diff options
| author | guillaume <guillaume@localhost.localdomain> | 2010-08-10 16:27:37 -0400 |
|---|---|---|
| committer | guillaume <guillaume@localhost.localdomain> | 2010-08-10 16:27:37 -0400 |
| commit | 724c296e54714a949ce79c5056229e00fb7c15c2 (patch) | |
| tree | d505860e67513dcb76141ebecb86a50ac00ad70d | |
| parent | 9e8fd4662da1688cc0c8fec2e9194b1606f30295 (diff) | |
| download | alias-724c296e54714a949ce79c5056229e00fb7c15c2.tar.gz | |
First code commit, with very few things.
* Beginning of object class
* Beginning of permission class
| -rwxr-xr-x | .gitignore | 2 | ||||
| -rwxr-xr-x | __init__.py | 3 | ||||
| -rwxr-xr-x | object.py | 28 | ||||
| -rwxr-xr-x | permission.py | 45 | ||||
| -rwxr-xr-x | users/thibaut/4786341468f1bb861b8ae2cd6dc0a2c582bf5da5 | 1 | ||||
| -rwxr-xr-x | users/thibaut/71f57e14acfdc04b2fe6ed5e2b4dc4e04558dea9 | 1 | ||||
| -rwxr-xr-x | users/thibaut/db.sql | bin | 0 -> 2048 bytes | |||
| -rwxr-xr-x | users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148 | 1 | ||||
| -rwxr-xr-x | version.py | 5 |
9 files changed, 86 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..454d936 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.directory diff --git a/__init__.py b/__init__.py new file mode 100755 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 100755 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 100755 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 100755 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 100755 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 Binary files differnew file mode 100755 index 0000000..cca9035 --- /dev/null +++ b/users/thibaut/db.sql diff --git a/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148 b/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148 new file mode 100755 index 0000000..4fe92a6 --- /dev/null +++ b/users/thibaut/ed10ca5a70af5dfbd943667ec2b9ee857ee2a148 @@ -0,0 +1 @@ +fils2 diff --git a/version.py b/version.py new file mode 100755 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 ? |
