Skip to content

Commit 8c32292

Browse files
author
Alexander Smishlajev
committed
common initialization code and detectors interface
moved to hyperdb.py (patch from rfe [SF#413165])
1 parent 9dab55a commit 8c32292

File tree

3 files changed

+6
-161
lines changed

3 files changed

+6
-161
lines changed

roundup/backends/back_anydbm.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.193 2006-01-23 05:24:33 richard Exp $
18+
#$Id: back_anydbm.py,v 1.194 2006-01-24 08:26:09 a1s Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -735,32 +735,6 @@ def close(self):
735735
class Class(hyperdb.Class):
736736
'''The handle to a particular class of nodes in a hyperdatabase.'''
737737

738-
def __init__(self, db, classname, **properties):
739-
'''Create a new class with a given name and property specification.
740-
741-
'classname' must not collide with the name of an existing class,
742-
or a ValueError is raised. The keyword arguments in 'properties'
743-
must map names to property objects, or a TypeError is raised.
744-
'''
745-
for name in 'creation activity creator actor'.split():
746-
if properties.has_key(name):
747-
raise ValueError, '"creation", "activity", "creator" and '\
748-
'"actor" are reserved'
749-
750-
self.classname = classname
751-
self.properties = properties
752-
self.db = weakref.proxy(db) # use a weak ref to avoid circularity
753-
self.key = ''
754-
755-
# should we journal changes (default yes)
756-
self.do_journal = 1
757-
758-
# do the db-related init stuff
759-
db.addclass(self)
760-
761-
self.auditors = {'create': [], 'set': [], 'retire': [], 'restore': []}
762-
self.reactors = {'create': [], 'set': [], 'retire': [], 'restore': []}
763-
764738
def enableJournalling(self):
765739
'''Turn journalling on for this class
766740
'''
@@ -1881,36 +1855,6 @@ def index(self, nodeid):
18811855
continue
18821856
self.db.indexer.add_text((self.classname, nodeid, prop), value)
18831857

1884-
1885-
#
1886-
# Detector interface
1887-
#
1888-
def audit(self, event, detector):
1889-
'''Register a detector
1890-
'''
1891-
l = self.auditors[event]
1892-
if detector not in l:
1893-
self.auditors[event].append(detector)
1894-
1895-
def fireAuditors(self, action, nodeid, newvalues):
1896-
'''Fire all registered auditors.
1897-
'''
1898-
for audit in self.auditors[action]:
1899-
audit(self.db, self, nodeid, newvalues)
1900-
1901-
def react(self, event, detector):
1902-
'''Register a detector
1903-
'''
1904-
l = self.reactors[event]
1905-
if detector not in l:
1906-
self.reactors[event].append(detector)
1907-
1908-
def fireReactors(self, action, nodeid, oldvalues):
1909-
'''Fire all registered reactors.
1910-
'''
1911-
for react in self.reactors[action]:
1912-
react(self.db, self, nodeid, oldvalues)
1913-
19141858
#
19151859
# import / export support
19161860
#

roundup/backends/back_metakit.py

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.100 2006-01-23 05:24:33 richard Exp $
1+
# $Id: back_metakit.py,v 1.101 2006-01-24 08:27:05 a1s Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -399,27 +399,18 @@ class Class(hyperdb.Class):
399399

400400
privateprops = None
401401
def __init__(self, db, classname, **properties):
402-
if (properties.has_key('creation') or properties.has_key('activity')
403-
or properties.has_key('creator') or properties.has_key('actor')):
404-
raise ValueError, '"creation", "activity" and "creator" are '\
405-
'reserved'
406402
if hasattr(db, classname):
407403
raise ValueError, "Class %s already exists"%classname
408-
409-
self.db = db
410-
self.classname = classname
404+
hyperdb.Class.__init__ (self, db, classname, **properties)
405+
self.db = db # why isn't this a weakref as for other backends??
411406
self.key = None
412-
self.ruprops = properties
407+
self.ruprops = self.properties
413408
self.privateprops = { 'id' : hyperdb.String(),
414409
'activity' : hyperdb.Date(),
415410
'actor' : hyperdb.Link('user'),
416411
'creation' : hyperdb.Date(),
417412
'creator' : hyperdb.Link('user') }
418413

419-
# event -> list of callables
420-
self.auditors = {'create': [], 'set': [], 'retire': [], 'restore': []}
421-
self.reactors = {'create': [], 'set': [], 'retire': [], 'restore': []}
422-
423414
view = self.__getview()
424415
self.maxid = 1
425416
if view:
@@ -429,13 +420,8 @@ def __init__(self, db, classname, **properties):
429420
self.rbactions = []
430421

431422
# people reach inside!!
432-
self.properties = self.ruprops
433-
self.db.addclass(self)
434423
self.idcache = {}
435424

436-
# default is to journal changes
437-
self.do_journal = 1
438-
439425
def setid(self, maxid):
440426
self.maxid = maxid + 1
441427

@@ -449,35 +435,6 @@ def disableJournalling(self):
449435
'''
450436
self.do_journal = 0
451437

452-
#
453-
# Detector/reactor interface
454-
#
455-
def audit(self, event, detector):
456-
'''Register a detector
457-
'''
458-
l = self.auditors[event]
459-
if detector not in l:
460-
self.auditors[event].append(detector)
461-
462-
def fireAuditors(self, action, nodeid, newvalues):
463-
'''Fire all registered auditors.
464-
'''
465-
for audit in self.auditors[action]:
466-
audit(self.db, self, nodeid, newvalues)
467-
468-
def react(self, event, detector):
469-
'''Register a reactor
470-
'''
471-
l = self.reactors[event]
472-
if detector not in l:
473-
self.reactors[event].append(detector)
474-
475-
def fireReactors(self, action, nodeid, oldvalues):
476-
'''Fire all registered reactors.
477-
'''
478-
for react in self.reactors[action]:
479-
react(self.db, self, nodeid, oldvalues)
480-
481438
# --- the hyperdb.Class methods
482439
def create(self, **propvalues):
483440
''' Create a new node of this class and return its id.

roundup/backends/rdbms_common.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.162 2006-01-20 02:42:35 richard Exp $
1+
# $Id: rdbms_common.py,v 1.163 2006-01-24 08:27:54 a1s Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1230,32 +1230,6 @@ class Class(hyperdb.Class):
12301230
concrete backend Class.
12311231
'''
12321232

1233-
def __init__(self, db, classname, **properties):
1234-
'''Create a new class with a given name and property specification.
1235-
1236-
'classname' must not collide with the name of an existing class,
1237-
or a ValueError is raised. The keyword arguments in 'properties'
1238-
must map names to property objects, or a TypeError is raised.
1239-
'''
1240-
for name in 'creation activity creator actor'.split():
1241-
if properties.has_key(name):
1242-
raise ValueError, '"creation", "activity", "creator" and '\
1243-
'"actor" are reserved'
1244-
1245-
self.classname = classname
1246-
self.properties = properties
1247-
self.db = weakref.proxy(db) # use a weak ref to avoid circularity
1248-
self.key = ''
1249-
1250-
# should we journal changes (default yes)
1251-
self.do_journal = 1
1252-
1253-
# do the db-related init stuff
1254-
db.addclass(self)
1255-
1256-
self.auditors = {'create': [], 'set': [], 'retire': [], 'restore': []}
1257-
self.reactors = {'create': [], 'set': [], 'retire': [], 'restore': []}
1258-
12591233
def schema(self):
12601234
''' A dumpable version of the schema that we can store in the
12611235
database
@@ -2319,36 +2293,6 @@ def index(self, nodeid):
23192293
self.db.indexer.add_text((self.classname, nodeid, prop),
23202294
str(self.get(nodeid, prop)))
23212295

2322-
2323-
#
2324-
# Detector interface
2325-
#
2326-
def audit(self, event, detector):
2327-
'''Register a detector
2328-
'''
2329-
l = self.auditors[event]
2330-
if detector not in l:
2331-
self.auditors[event].append(detector)
2332-
2333-
def fireAuditors(self, action, nodeid, newvalues):
2334-
'''Fire all registered auditors.
2335-
'''
2336-
for audit in self.auditors[action]:
2337-
audit(self.db, self, nodeid, newvalues)
2338-
2339-
def react(self, event, detector):
2340-
'''Register a detector
2341-
'''
2342-
l = self.reactors[event]
2343-
if detector not in l:
2344-
self.reactors[event].append(detector)
2345-
2346-
def fireReactors(self, action, nodeid, oldvalues):
2347-
'''Fire all registered reactors.
2348-
'''
2349-
for react in self.reactors[action]:
2350-
react(self.db, self, nodeid, oldvalues)
2351-
23522296
#
23532297
# import / export support
23542298
#

0 commit comments

Comments
 (0)