aboutsummaryrefslogtreecommitdiffstats
path: root/object.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2010-11-29 22:31:14 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2010-11-29 22:31:14 -0500
commit9b4433227dd6556206a32191403820e91f8e05c4 (patch)
tree33c2e60843337ca4e8e02febe2e3e0ce752afcff /object.py
parent217835b3adddedc9e8c501e8868d0440509ba1d5 (diff)
downloadalias-9b4433227dd6556206a32191403820e91f8e05c4.tar.gz
Some pep8ification
Diffstat (limited to 'object.py')
-rw-r--r--object.py39
1 files changed, 17 insertions, 22 deletions
diff --git a/object.py b/object.py
index 8faa317..6825a70 100644
--- a/object.py
+++ b/object.py
@@ -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)