aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2010-07-30 09:29:24 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2010-07-30 09:29:24 +0200
commit7945c0daad7d2e3b8380c18b7d080e54e0a948ed (patch)
treeebe1932b3d2aeb979570c977fc9947f8891336cf
downloadalias-7945c0daad7d2e3b8380c18b7d080e54e0a948ed.tar.gz
Project creation.
-rw-r--r--.gitignore1
-rw-r--r--__init__.py3
-rw-r--r--object.py28
-rw-r--r--permission.py45
-rw-r--r--users/thibaut/4786341468f1bb861b8ae2cd6dc0a2c582bf5da51
-rw-r--r--users/thibaut/71f57e14acfdc04b2fe6ed5e2b4dc4e04558dea91
-rw-r--r--users/thibaut/db.sqlbin0 -> 2048 bytes
-rw-r--r--users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a1481
-rw-r--r--version.py5
9 files changed, 85 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..faaaf79
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+
diff --git a/object.py b/object.py
new file mode 100644
index 0000000..a89b020
--- /dev/null
+++ b/object.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+#TODO : dissociate the db connexion and the objecthandler (probably pass a db connexion as init argument)
+import sqlite3
+from version import VERSION
+
+class ObjectHandler :
+
+ def __init__(self,root,dbhandler) :
+ self.rootDirectory = root
+ self.db = dbhandler
+ if isinstance(self.db,sqlite3.Connection) :
+ self.db.text_factory = str
+ self.sql = self.db.cursor()
+
+ def childList(self,hash) :
+ self.sql.execute("select son from structure where hash=?",(hash,))
+ l = []
+ for son in self.cursor :
+ l.append(son[0])
+ return l
+
+ def fileName(self,hash) :
+ return self.rootDirectory+'objects/'+hash[:2]+'/'+hash[2:]
+
+ def appendChild(self,father,son) :
+ self.sql.execute("insert into structure values (?,?)",(father,son))
+ self.db.commit()
+
diff --git a/permission.py b/permission.py
new file mode 100644
index 0000000..310cef2
--- /dev/null
+++ b/permission.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+#TODO : move the globals to a config file (use the config file parser module)
+PERM_LIST=['READ','MODIFY','APPEND'] #just add a string here to define a new permission
+PERMS = len(PERM_LIST)
+MAX = (1<<PERMS)-1
+
+class PermissionError(Exception) :
+ def __init__(self,error_string) :
+ self.error = error_string
+
+ def __str__(self) :
+ str(self.error)
+
+class Permission :
+
+ def __init__(self,init) :
+ if isinstance(init,int) :
+ if (init > MAX) or (init < 0) :
+ raise PermissionError('Permission int not in correct range')
+ result = []
+ for shift in range(PERMS-1,-1,-1) :
+ if init>>shift :
+ result.append(PERM_LIST[shift])
+ init = init-(1<<shift)
+ self.perm_list = result
+ elif isinstance(init,list) :
+ if (set(init) <= set(PERM_LIST)) :
+ self.perm_list = init
+ else :
+ raise PermissionError('Undefined permission')
+
+ def __str__(self) :
+ return str(self.perm_list)
+
+ def toInt(self) :
+ result = 0
+ for i,perm in enumerate(PERM_LIST) :
+ if perm in self.perm_list :
+ result += 1<<i
+ return result
+
+if __name__== '__main__' :
+ for i in range(MAX+1) :
+ print i, Permission(i), Permission(i).toInt()
+ \ No newline at end of file
diff --git a/users/thibaut/4786341468f1bb861b8ae2cd6dc0a2c582bf5da5 b/users/thibaut/4786341468f1bb861b8ae2cd6dc0a2c582bf5da5
new file mode 100644
index 0000000..89df1e2
--- /dev/null
+++ b/users/thibaut/4786341468f1bb861b8ae2cd6dc0a2c582bf5da5
@@ -0,0 +1 @@
+fils
diff --git a/users/thibaut/71f57e14acfdc04b2fe6ed5e2b4dc4e04558dea9 b/users/thibaut/71f57e14acfdc04b2fe6ed5e2b4dc4e04558dea9
new file mode 100644
index 0000000..ea7b6a8
--- /dev/null
+++ b/users/thibaut/71f57e14acfdc04b2fe6ed5e2b4dc4e04558dea9
@@ -0,0 +1 @@
+pere
diff --git a/users/thibaut/db.sql b/users/thibaut/db.sql
new file mode 100644
index 0000000..cca9035
--- /dev/null
+++ b/users/thibaut/db.sql
Binary files differ
diff --git a/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148 b/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148
new file mode 100644
index 0000000..4fe92a6
--- /dev/null
+++ b/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148
@@ -0,0 +1 @@
+fils2
diff --git a/version.py b/version.py
new file mode 100644
index 0000000..306cebb
--- /dev/null
+++ b/version.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+MAJOR=0
+MINOR=1
+TYPE='dev'
+VERSION = str(MAJOR)+'.'+str(MINOR)+TYPE #TODO: add the commit number ?