Added functionality and (optimistic) test for check of .format files.
This commit is contained in:
parent
4d18c3c29a
commit
0c9e2826b8
|
@ -1,3 +1,14 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# import the interface
|
||||||
|
#
|
||||||
|
from db import connect, disconnect
|
||||||
|
|
||||||
|
#
|
||||||
|
# import the different submodules
|
||||||
|
#
|
||||||
|
import db, rcs
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
# itself while defining objects that the database will return.
|
# itself while defining objects that the database will return.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import rcs, re
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# The most generic exception that this library will raise.
|
# The most generic exception that this library will raise.
|
||||||
#
|
#
|
||||||
|
@ -53,6 +56,18 @@ class PVVDB:
|
||||||
# clean up locks and such before being deleted.
|
# clean up locks and such before being deleted.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __format(self, file_path):
|
||||||
|
# parses and verifies the .format files for a database.
|
||||||
|
fh = file(file_path)
|
||||||
|
fmt = {}
|
||||||
|
for line in fh:
|
||||||
|
if line[0] == "#":
|
||||||
|
continue
|
||||||
|
name, value = line.strip().split(":", 1)
|
||||||
|
value = value.split("#", 1)[0].strip()
|
||||||
|
fmt[name] = value
|
||||||
|
return fmt
|
||||||
|
|
||||||
def lock(self, username):
|
def lock(self, username):
|
||||||
# Lock the record.
|
# Lock the record.
|
||||||
pass
|
pass
|
||||||
|
@ -76,13 +91,19 @@ class PVVDB:
|
||||||
#
|
#
|
||||||
# Regular interface to the database.
|
# Regular interface to the database.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
pathmap = {}
|
||||||
|
|
||||||
def connect(path):
|
def connect(path):
|
||||||
# returns a PVVDB instance to that path. If asked for another
|
# returns a PVVDB instance to that path. If asked for another
|
||||||
# PVVDB instance with the same path as earlier, it will return
|
# PVVDB instance with the same path as earlier, it will return
|
||||||
# the same object.
|
# the same object.
|
||||||
pass
|
if not path in pathmap:
|
||||||
|
pathmap[path] = PVVDB(path)
|
||||||
|
return pathmap[path]
|
||||||
|
|
||||||
def disconnect(dbo):
|
def disconnect(dbo):
|
||||||
# do not do anything, really. PVVDB objects will clean up
|
# do not do anything, really. PVVDB objects will clean up
|
||||||
# automatically when deleted.
|
# automatically when deleted. is here for future database
|
||||||
|
# systems.
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -14,17 +14,33 @@ class mdbTest(TestCase):
|
||||||
|
|
||||||
class connectTest(mdbTest):
|
class connectTest(mdbTest):
|
||||||
|
|
||||||
def test_1(self):
|
def test_0(self):
|
||||||
db = self.mdb.connect("inputs/db-0/")
|
db = self.mdb.connect("inputs/db-0/")
|
||||||
self.failUnless(db.__class__ == self.mdb.db.PVVDB)
|
self.failUnless(db.__class__ == self.mdb.db.PVVDB)
|
||||||
|
|
||||||
|
|
||||||
class disconnectTest(mdbTest):
|
class disconnectTest(mdbTest):
|
||||||
|
|
||||||
def test_1(self):
|
def test_0(self):
|
||||||
db = self.mdb.connect("inputs/db-0/")
|
db = self.mdb.connect("inputs/db-0/")
|
||||||
self.mdb.disconnect(db)
|
self.mdb.disconnect(db)
|
||||||
|
|
||||||
|
|
||||||
|
class formatTest(mdbTest):
|
||||||
|
|
||||||
|
def test_0(self):
|
||||||
|
db = self.mdb.connect("inputs/db-0/")
|
||||||
|
format = db._PVVDB__format("inputs/format-legal-00")
|
||||||
|
self.failUnless(format['username'] == 'scalar' and
|
||||||
|
format['realname'] == 'scalar' and
|
||||||
|
format['uid'] == 'scalar' and
|
||||||
|
format['disk'] == 'list' and
|
||||||
|
format['bdb-uid'] == 'scalar' and
|
||||||
|
format['bdb-username'] == 'scalar' and
|
||||||
|
format['purged'] == 'scalar' and
|
||||||
|
format['membership'] == 'list')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Run the library tests.
|
# Run the library tests.
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#
|
||||||
|
# $Id$
|
||||||
|
#
|
||||||
|
username: scalar
|
||||||
|
realname: scalar
|
||||||
|
uid: scalar
|
||||||
|
disk: list # hvert element i lista er en 2-tuple adskilt med space
|
||||||
|
bdb-uid: scalar
|
||||||
|
bdb-username: scalar
|
||||||
|
purged: scalar
|
||||||
|
membership: list # hvert element i lista er en 2-tuple adskilt med space
|
Reference in New Issue