aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2010-10-26 02:29:43 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2010-10-26 02:29:43 +0200
commit9a44bc91a7f2aad0f14e486f77ed88bb1b2980c1 (patch)
treed35c5228a4fe91c064bd6978bd6991dc7f3a4556
parentc6dc4fa3ca6841854641205c8ceeab40a66c7c8b (diff)
downloadalias-9a44bc91a7f2aad0f14e486f77ed88bb1b2980c1.tar.gz
Fix a bug in Object.setPermission (newlines were added when changing the permissions)
-rw-r--r--object.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/object.py b/object.py
index bb2a9c6..86996bc 100644
--- a/object.py
+++ b/object.py
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
import StringIO
import hashlib
+import sys
import os
import os.path
import zlib
import datetime
import fileinput
-import permission
+from permission import *
class Object :
@@ -92,6 +93,7 @@ class Object :
file.close()
def getPermission( self, user ) :
+
file = open( self.path + '/permissions', 'r' )
for line in file :
@@ -101,7 +103,7 @@ class Object :
return 0
- def setPermission(self, user, perm ) :
+ def setPermission(self, user, permission ) :
if not self.saved :
self.save()
@@ -109,22 +111,25 @@ class Object :
for line in fileinput.input( self.path + "/permissions", inplace=1 ) :
name, sep, perm = line.rstrip('\n').partition(' ')
if name == user :
- print name + sep + perm
+ sys.stdout.write( name + ' ' + str( permission ) + '\n' )
sentinel = True
else :
- print line
+ sys.stdout.write( line )
if not sentinel :
file = open( self.path + '/permissions', 'a' )
- file.write( user + ' ' + str( perm ) )
+ file.write( user + ' ' + str( permission ) + '\n' )
file.close()
if __name__== '__main__' :
x = Object({'parent' : 'toto', 'author' : 'Zaran'})
- x.setPermission("test", permission.READ)
-
+ x.setPermission("test", READ )
+ x.setPermission( "toto", READ | MODIFY )
+ x.setPermission( "toto", READ | MODIFY | APPEND )
+ x.setPermission( "toto2", READ | MODIFY | APPEND )
+ print x.getPermission("toto")
child = Object({'parent' : x.name, 'author' : 'Zaran'})
child.save()