Projects
/
mdb-ng
Archived
4
0
Fork 0

A first implementation of the load method.

This commit is contained in:
Øyvind Grønnesby 2005-05-26 20:19:45 +00:00
parent bd92d82219
commit 5cb46c61d8
1 changed files with 27 additions and 2 deletions

View File

@ -53,6 +53,7 @@ class PVVDB:
self.base = base # base database directory self.base = base # base database directory
self.locks = [] # list of activated locks self.locks = [] # list of activated locks
self.rcs = rcs.RCS() # an RCS interface function self.rcs = rcs.RCS() # an RCS interface function
self.format = self.__format(self.base)
def __del__(self): def __del__(self):
# clean up locks and such before being deleted. # clean up locks and such before being deleted.
@ -88,12 +89,36 @@ class PVVDB:
def unlock(self, username, pedantic=False): def unlock(self, username, pedantic=False):
# Unlock the record. # 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): def load(self, username, lock=False):
# Read the record from the database. Will do an automatic lock # Read the record from the database. Will do an automatic lock
# if `lock' is True. # 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): def save(self, username, comment="", lock=False):
# Write the record to the database. Will automatically unlock # Write the record to the database. Will automatically unlock