Skip to content

Commit 9dab55a

Browse files
author
Alexander Smishlajev
committed
common initialization code and detectors interface...
...moved here from backend modules (patch from rfe [SF#413165])
1 parent 0ae8f6e commit 9dab55a

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

roundup/hyperdb.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.113 2006-01-20 02:40:56 richard Exp $
18+
# $Id: hyperdb.py,v 1.114 2006-01-24 08:22:42 a1s Exp $
1919

2020
"""Hyperdatabase implementation, especially field types.
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

2424
# standard python modules
25-
import sys, os, time, re, shutil
25+
import sys, os, time, re, shutil, weakref
2626

2727
# roundup modules
2828
import date, password
29-
from support import ensureParentsExist
29+
from support import ensureParentsExist, PrioList
3030

3131
#
3232
# Types
@@ -441,7 +441,25 @@ def __init__(self, db, classname, **properties):
441441
or a ValueError is raised. The keyword arguments in 'properties'
442442
must map names to property objects, or a TypeError is raised.
443443
"""
444-
raise NotImplementedError
444+
for name in 'creation activity creator actor'.split():
445+
if properties.has_key(name):
446+
raise ValueError, '"creation", "activity", "creator" and '\
447+
'"actor" are reserved'
448+
449+
self.classname = classname
450+
self.properties = properties
451+
self.db = weakref.proxy(db) # use a weak ref to avoid circularity
452+
self.key = ''
453+
454+
# should we journal changes (default yes)
455+
self.do_journal = 1
456+
457+
# do the db-related init stuff
458+
db.addclass(self)
459+
460+
actions = "create set retire restore".split ()
461+
self.auditors = dict ([(a, PrioList ()) for a in actions])
462+
self.reactors = dict ([(a, PrioList ()) for a in actions])
445463

446464
def __repr__(self):
447465
'''Slightly more useful representation
@@ -642,7 +660,7 @@ def labelprop(self, default_to_id=0):
642660
def orderprop (self):
643661
"""Return the property name to use for sorting for the given node.
644662
645-
This method computes the property for sorting.
663+
This method computes the property for sorting.
646664
It tries the following in order:
647665
648666
0. self._orderprop if set
@@ -733,12 +751,35 @@ def addprop(self, **properties):
733751
raise NotImplementedError
734752

735753
def index(self, nodeid):
736-
'''Add (or refresh) the node to search indexes
737-
'''
754+
"""Add (or refresh) the node to search indexes"""
738755
raise NotImplementedError
739756

757+
#
758+
# Detector interface
759+
#
760+
def audit(self, event, detector, priority = 100):
761+
"""Register an auditor detector"""
762+
self.auditors[event].append((priority, detector))
763+
764+
def fireAuditors(self, event, nodeid, newvalues):
765+
"""Fire all registered auditors"""
766+
for prio, audit in self.auditors[event]:
767+
audit(self.db, self, nodeid, newvalues)
768+
769+
def react(self, event, detector, priority = 100):
770+
"""Register a reactor detector"""
771+
self.reactors[event].append((priority, detector))
772+
773+
def fireReactors(self, event, nodeid, oldvalues):
774+
"""Fire all registered reactors"""
775+
for prio, react in self.reactors[event]:
776+
react(self.db, self, nodeid, oldvalues)
777+
778+
#
779+
# import / export support
780+
#
740781
def export_propnames(self):
741-
'''List the property names for export from this Class.'''
782+
"""List the property names for export from this Class"""
742783
propnames = self.getprops().keys()
743784
propnames.sort()
744785
return propnames
@@ -829,7 +870,7 @@ def export_files(self, dirname, nodeid):
829870

830871
dest = self.exportFilename(dirname, nodeid)
831872
ensureParentsExist(dest)
832-
shutil.copyfile(source, dest)
873+
shutil.copyfile(source, dest)
833874

834875
def import_files(self, dirname, nodeid):
835876
''' Import the "content" property as a file

0 commit comments

Comments
 (0)