From 7a35acd993d13c5ab2c4076783e3a1956a4b5f6d Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 23 Jul 2001 07:14:41 +0000 Subject: [PATCH] Moved the database backends off into backends. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@48 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/__init__.py | 4 ++ roundup/roundupdb.py | 61 +++++++++++++++++++--------- roundup/templates/extended/dbinit.py | 18 ++++---- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/roundup/backends/__init__.py b/roundup/backends/__init__.py index e69de29..4bffc94 100644 --- a/roundup/backends/__init__.py +++ b/roundup/backends/__init__.py @@ -0,0 +1,4 @@ +import _bsddb; bsddb = _bsddb +import _anydbm; anydbm = _anydbm + +__all__ = ['bsddb', 'anydbm'] diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index 57023bc..25ebc63 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -1,4 +1,4 @@ -# $Id: roundupdb.py,v 1.2 2001-07-22 12:09:32 richard Exp $ +# $Id: roundupdb.py,v 1.3 2001-07-23 07:14:41 richard Exp $ import re, os, smtplib, socket @@ -27,6 +27,7 @@ class Database: return self.user.create(username=address, address=address, realname=realname) +# XXX: added the 'creator' faked attribute class Class(hyperdb.Class): # Overridden methods: def __init__(self, db, classname, **properties): @@ -70,6 +71,42 @@ class Class(hyperdb.Class): for react in self.reactors['retire']: react(self.db, self, nodeid, None) + def get(self, nodeid, propname): + """Attempts to get the "creation" or "activity" properties should + do the right thing + """ + if propname == 'creation': + journal = self.db.getjournal(self.classname, nodeid) + if journal: + return self.db.getjournal(self.classname, nodeid)[0][1] + else: + # on the strange chance that there's no journal + return date.Date() + if propname == 'activity': + journal = self.db.getjournal(self.classname, nodeid) + if journal: + return self.db.getjournal(self.classname, nodeid)[-1][1] + else: + # on the strange chance that there's no journal + return date.Date() + if propname == 'creator': + journal = self.db.getjournal(self.classname, nodeid) + if journal: + name = self.db.getjournal(self.classname, nodeid)[0][2] + else: + return None + return self.db.user.lookup(name) + return hyperdb.Class.get(self, nodeid, propname) + + def getprops(self): + """In addition to the actual properties on the node, these + methods provide the "creation" and "activity" properties.""" + d = hyperdb.Class.getprops(self).copy() + d['creation'] = hyperdb.Date() + d['activity'] = hyperdb.Date() + d['creator'] = hyperdb.Link("user") + return d + # New methods: def audit(self, event, detector): @@ -145,25 +182,6 @@ class IssueClass(Class): raise ValueError, '"creation", "activity" and "creator" are reserved' Class.__init__(self, db, classname, **properties) - def get(self, nodeid, propname): - if propname == 'creation': - return self.db.getjournal(self.classname, nodeid)[0][1] - if propname == 'activity': - return self.db.getjournal(self.classname, nodeid)[-1][1] - if propname == 'creator': - name = self.db.getjournal(self.classname, nodeid)[0][2] - return self.db.user.lookup(name) - return Class.get(self, nodeid, propname) - - def getprops(self): - """In addition to the actual properties on the node, these - methods provide the "creation" and "activity" properties.""" - d = Class.getprops(self).copy() - d['creation'] = hyperdb.Date() - d['activity'] = hyperdb.Date() - d['creator'] = hyperdb.Link("user") - return d - # New methods: def addmessage(self, nodeid, summary, text): @@ -227,6 +245,9 @@ class IssueClass(Class): # # $Log: not supported by cvs2svn $ +# Revision 1.2 2001/07/22 12:09:32 richard +# Final commit of Grande Splite +# # Revision 1.1 2001/07/22 11:58:35 richard # More Grande Splite # diff --git a/roundup/templates/extended/dbinit.py b/roundup/templates/extended/dbinit.py index 8a526e0..3684693 100644 --- a/roundup/templates/extended/dbinit.py +++ b/roundup/templates/extended/dbinit.py @@ -1,16 +1,15 @@ -# $Id: dbinit.py,v 1.2 2001-07-23 06:25:50 richard Exp $ +# $Id: dbinit.py,v 1.3 2001-07-23 07:14:41 richard Exp $ -import instance_config -from roundup import hyperdb, backends.bsddb, roundupdb, cgi_client, mailgw - -from roundup.roundupdb import Class, FileClass import os +import instance_config +from roundup import roundupdb, cgi_client, mailgw +from roundup.backends import bsddb +from roundup.roundupdb import Class, FileClass -class Database(roundupdb.Database, backends.bsddb.Database): +class Database(roundupdb.Database, bsddb.Database): ''' Creates a hybrid database from: - . the base Database class given in hyperdb (basic functionlity) - . the BSDDB implementation in hyperdb_bsddb + . the BSDDB implementation in backends.bsddb . the roundup extensions from roundupdb ''' pass @@ -172,6 +171,9 @@ def init(adminpw): # # $Log: not supported by cvs2svn $ +# Revision 1.2 2001/07/23 06:25:50 richard +# relfected the move to roundup/backends +# # Revision 1.1 2001/07/23 04:33:21 anthonybaxter # split __init__.py into 2. dbinit and instance_config. # -- 2.30.2