diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2010-10-26 02:40:04 +0200 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2010-10-26 02:40:04 +0200 |
| commit | edde6c6fe4ea8953a80b5e7b60d49e14e8ee7938 (patch) | |
| tree | a9c22838e9880291559f93e88fb18578e1f7a822 | |
| parent | 9a44bc91a7f2aad0f14e486f77ed88bb1b2980c1 (diff) | |
| download | alias-edde6c6fe4ea8953a80b5e7b60d49e14e8ee7938.tar.gz | |
Add static method to get method by hash
| -rw-r--r-- | object.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -92,6 +92,21 @@ class Object : file.write( child.name + "\n") file.close() + @staticmethod + def getPermissionByHash( hash, user ) : + path = hash[:2] + '/' + hash[2:] + try: + file = open( path + '/permissions', 'r' ) + except IOError : + print 'cannot open', path + else : + for line in file : + name, sep, perm = line.rstrip('\n').partition(' ') + if name == user : + return perm + + return 0 + def getPermission( self, user ) : file = open( self.path + '/permissions', 'r' ) @@ -102,7 +117,7 @@ class Object : return perm return 0 - + def setPermission(self, user, permission ) : if not self.saved : self.save() @@ -130,6 +145,7 @@ if __name__== '__main__' : x.setPermission( "toto", READ | MODIFY | APPEND ) x.setPermission( "toto2", READ | MODIFY | APPEND ) print x.getPermission("toto") + print Object.getPermissionByHash(x.name, "toto") child = Object({'parent' : x.name, 'author' : 'Zaran'}) child.save() |
