From 5cb46c61d864a418777ea155fa9646b46e71c657 Mon Sep 17 00:00:00 2001 From: oyving Date: Thu, 26 May 2005 20:19:45 +0000 Subject: [PATCH] A first implementation of the load method. --- lib/mdb/db.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/mdb/db.py b/lib/mdb/db.py index d675e6a..5d00327 100644 --- a/lib/mdb/db.py +++ b/lib/mdb/db.py @@ -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