A first implementation of the load method.
This commit is contained in:
parent
bd92d82219
commit
5cb46c61d8
|
@ -53,6 +53,7 @@ class PVVDB:
|
|||
self.base = base # base database directory
|
||||
self.locks = [] # list of activated locks
|
||||
self.rcs = rcs.RCS() # an RCS interface function
|
||||
self.format = self.__format(self.base)
|
||||
|
||||
def __del__(self):
|
||||
# clean up locks and such before being deleted.
|
||||
|
@ -88,12 +89,36 @@ class PVVDB:
|
|||
|
||||
def unlock(self, username, pedantic=False):
|
||||
# Unlock the record.
|
||||
pass
|
||||
if not username in self.locks and pedantic:
|
||||
raise PVVDBError, "%s not locked." % `username`
|
||||
self.rcs.unlock(self.__filename(username))
|
||||
self.locks.remove(username)
|
||||
|
||||
def load(self, username, lock=False):
|
||||
# Read the record from the database. Will do an automatic lock
|
||||
# if `lock' is True.
|
||||
pass
|
||||
if lock:
|
||||
self.lock(username)
|
||||
userfile = file(self.__filename(username))
|
||||
member = {}
|
||||
for line in userfile:
|
||||
key, value = line.strip().split(": ", 1)
|
||||
if not key in self.format:
|
||||
raise PVVDBError, "%s not a legal attribute." % `key`
|
||||
v = None
|
||||
# handle the list datatype
|
||||
if self.format[key] == 'list':
|
||||
v = []
|
||||
# XXX: needs to respect escaping of field separators
|
||||
for e in value.split(", "):
|
||||
v.append(e)
|
||||
elif self.format[key] == 'scalar':
|
||||
v = value
|
||||
else:
|
||||
# we should not be here
|
||||
raise PVVDBError, "%s not legal datatype." % `self.format[key]`
|
||||
member[key] = value
|
||||
return PVVMember(member, username)
|
||||
|
||||
def save(self, username, comment="", lock=False):
|
||||
# Write the record to the database. Will automatically unlock
|
||||
|
|
Reference in New Issue