diff options
| -rw-r--r-- | object.py | 39 | ||||
| -rw-r--r-- | user.py | 4 |
2 files changed, 19 insertions, 24 deletions
@@ -14,10 +14,10 @@ from config import config class Object: - def _getPath(self): + def __get_path(self): return self.name[:2] + '/' + self.name[2:] - def _createDir(self): + def __create_dir(self): if (not os.path.exists(self.name[:2])): os.mkdir(self.name[:2]) @@ -27,7 +27,7 @@ class Object: ## # Save the object on the disk. def save(self): - self._createDir() + self.__createDir() header = "author " + self.data['author'] + "\n" header += "parent " + self.data['parent'] + "\n" @@ -47,28 +47,26 @@ class Object: def __init__(self, init): if isinstance(init, dict): - - if 'author' not in init : + if 'author' not in init: init['author'] = 'None' - if 'parent' not in init : + if 'parent' not in init: init['parent'] = 'None' - if 'content' not in init : + if 'content' not in init: init['content'] = 'None' self.data = init self.data['created'] = str(datetime.datetime.now()) self.name = hashlib.sha1(str(self.data)).hexdigest() - self.path = self._getPath() + self.path = self.__getPath() self.saved = False elif isinstance(init, str): - if (os.path.exists(str)): + if (os.path.exists(init)): file = open(self.path + '/object', 'r') contentStream = StringIO.StringIO(zlib.decompress(file.read())) data = {} for line in contentStream: - if (line == "#\n"): data['content'] = contentStream.read() break @@ -79,11 +77,10 @@ class Object: self.data = data file.close() - def appendTo(self, father): + def append_to(self, father): father.appendChild(self) - def appendChild(self, child) : - + def append_child(self, child): if not self.saved: self.save() @@ -92,7 +89,7 @@ class Object: file.close() @staticmethod - def getPermissionByHash(hash, user): + def get_permission_by_hash(hash, user): path = hash[:2] + '/' + hash[2:] try: file = open(path + '/permissions', 'r') @@ -106,18 +103,16 @@ class Object: return 0 - def getPermission(self, user) : - + def get_permission(self, user): file = open(self.path + '/permissions', 'r') - for line in file: name, sep, perm = line.rstrip('\n').partition(' ') if name == user: return perm - + return 0 - def setPermission(self, user, permission): + def set_permission(self, user, permission): if not self.saved: self.save() @@ -142,17 +137,17 @@ class ObjectHandler: self.root_directory = config.root + user + '/' self.root_object = hashlib.sha1(user).hexdigest() - if not os.path.exists(self.root_directory) : + if not os.path.exists(self.root_directory): logging.error("User %s root doesn't exist" % self.user) def get_object_directory(self, hash): directory = self.root_directory + hash[:2] + '/' + hash[2:] - if (os.path.exists(directory)) : + if (os.path.exists(directory)): return directory else : return None - def getObject(self, hash): + def get_object(self, hash): directory = self.get_object_directory(hash) if directory is None : logging.error("Object %s doesn't exist" % hash) @@ -22,10 +22,10 @@ class UserHandler: def unregister(self, name): shutil.rmtree(self.root + '/' + name) - def getUserList(self): + def get_user_list(self): return os.listdir(self.root) -class User : +class User: def __init__(self, name): self.name = name |
