summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e007793)
raw | patch | inline | side by side (parent: e007793)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 14 Jul 2002 06:06:34 +0000 (06:06 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 14 Jul 2002 06:06:34 +0000 (06:06 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@874 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/backends/back_anydbm.py | patch | blob | history | |
test/test_db.py | patch | blob | history |
index 195c8d06f5a35d5322c4b59fc62af89468bae7d9..6524c388c5765bd2a74bdba97d05fff61a47173e 100644 (file)
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-#$Id: back_anydbm.py,v 1.45 2002-07-14 04:03:14 richard Exp $
+#$Id: back_anydbm.py,v 1.46 2002-07-14 06:06:34 richard Exp $
'''
This module defines a backend that saves the hyperdatabase in a database
chosen by anydbm. It is guaranteed to always be available in python
print >>hyperdb.DEBUG, 'getclassdb', (self, classname, mode)
return self._opendb('nodes.%s'%classname, mode)
- def _opendb(self, name, mode):
- '''Low-level database opener that gets around anydbm/dbm
- eccentricities.
+ def determine_db_type(self, path):
+ ''' determine which DB wrote the class file
'''
- if __debug__:
- print >>hyperdb.DEBUG, '_opendb', (self, name, mode)
-
- # determine which DB wrote the class file
db_type = ''
- path = os.path.join(os.getcwd(), self.dir, name)
if os.path.exists(path):
db_type = whichdb.whichdb(path)
if not db_type:
# if the path ends in '.db', it's a dbm database, whether
# anydbm says it's dbhash or not!
db_type = 'dbm'
+ return db_type
+
+ def _opendb(self, name, mode):
+ '''Low-level database opener that gets around anydbm/dbm
+ eccentricities.
+ '''
+ if __debug__:
+ print >>hyperdb.DEBUG, '_opendb', (self, name, mode)
+
+ # figure the class db type
+ path = os.path.join(os.getcwd(), self.dir, name)
+ db_type = self.determine_db_type(path)
# new database? let anydbm pick the best dbm
if not db_type:
classes = self.getclasses()
- # TODO: factor this out to method - we're already doing it in
- # _opendb.
- db_type = ''
- path = os.path.join(os.getcwd(), self.dir, classes[0])
- if os.path.exists(path):
- db_type = whichdb.whichdb(path)
- if not db_type:
- raise hyperdb.DatabaseError, "Couldn't identify database type"
- elif os.path.exists(path+'.db'):
- db_type = 'dbm'
+ # figure the class db type
for classname in classes:
db_name = 'journals.%s'%classname
+ path = os.path.join(os.getcwd(), self.dir, classname)
+ db_type = self.determine_db_type(path)
db = self._opendb(db_name, 'w')
for key in db.keys():
if isinstance(prop, Multilink):
propvalues[key] = []
else:
- # TODO: None isn't right here, I think...
propvalues[key] = None
# done
if isinstance(prop, Multilink):
return []
else:
- # TODO: None isn't right here, I think...
return None
else:
return default
'propname' must be the name of a String property of this class or
None, or a TypeError is raised. The values of the key property on
- all existing nodes must be unique or a ValueError is raised.
+ all existing nodes must be unique or a ValueError is raised. If the
+ property doesn't exist, KeyError is raised.
"""
- # TODO: validate that the property is a String!
+ prop = self.getprops()[propname]
+ if not isinstance(prop, String):
+ raise TypeError, 'key properties must be String'
self.key = propname
def getkey(self):
#
#$Log: not supported by cvs2svn $
+#Revision 1.45 2002/07/14 04:03:14 richard
+#Implemented a switch to disable journalling for a Class. CGI session
+#database now uses it.
+#
#Revision 1.44 2002/07/14 02:05:53 richard
#. all storage-specific code (ie. backend) is now implemented by the backends
#
diff --git a/test/test_db.py b/test/test_db.py
index 94d657a768b77832c242abb491dde4b6d68e039a..1e851ae778ef1988651f4a7fc0069a11c74fec84 100644 (file)
--- a/test/test_db.py
+++ b/test/test_db.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_db.py,v 1.29 2002-07-14 04:03:15 richard Exp $
+# $Id: test_db.py,v 1.30 2002-07-14 06:06:34 richard Exp $
import unittest, os, shutil, time
ar(IndexError, self.db.issue.create, title='foo', status='1',
nosy=['10'])
+ #
+ # key property
+ #
+ # key must be a String
+ ar(TypeError, self.db.user.setkey, 'password')
+ # key must exist
+ ar(KeyError, self.db.user.setkey, 'fubar')
+
#
# class get
#
#
# $Log: not supported by cvs2svn $
+# Revision 1.29 2002/07/14 04:03:15 richard
+# Implemented a switch to disable journalling for a Class. CGI session
+# database now uses it.
+#
# Revision 1.28 2002/07/14 02:16:29 richard
# Fixes for the metakit backend (removed the cut-n-paste IssueClass, removed
# a special case for it in testing)