comparison roundup/hyperdb.py @ 3488:e4177cf4d30d

common initialization code and detectors interface... ...moved here from backend modules (patch from rfe [SF#413165])
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Tue, 24 Jan 2006 08:22:42 +0000
parents 1142dafe0d7f
children 0e5f15520e70
comparison
equal deleted inserted replaced
3487:a2ae11191968 3488:e4177cf4d30d
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
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 $
19 19
20 """Hyperdatabase implementation, especially field types. 20 """Hyperdatabase implementation, especially field types.
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
24 # standard python modules 24 # standard python modules
25 import sys, os, time, re, shutil 25 import sys, os, time, re, shutil, weakref
26 26
27 # roundup modules 27 # roundup modules
28 import date, password 28 import date, password
29 from support import ensureParentsExist 29 from support import ensureParentsExist, PrioList
30 30
31 # 31 #
32 # Types 32 # Types
33 # 33 #
34 class String: 34 class String:
439 439
440 'classname' must not collide with the name of an existing class, 440 'classname' must not collide with the name of an existing class,
441 or a ValueError is raised. The keyword arguments in 'properties' 441 or a ValueError is raised. The keyword arguments in 'properties'
442 must map names to property objects, or a TypeError is raised. 442 must map names to property objects, or a TypeError is raised.
443 """ 443 """
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])
445 463
446 def __repr__(self): 464 def __repr__(self):
447 '''Slightly more useful representation 465 '''Slightly more useful representation
448 ''' 466 '''
449 return '<hyperdb.Class "%s">'%self.classname 467 return '<hyperdb.Class "%s">'%self.classname
640 return props[0] 658 return props[0]
641 659
642 def orderprop (self): 660 def orderprop (self):
643 """Return the property name to use for sorting for the given node. 661 """Return the property name to use for sorting for the given node.
644 662
645 This method computes the property for sorting. 663 This method computes the property for sorting.
646 It tries the following in order: 664 It tries the following in order:
647 665
648 0. self._orderprop if set 666 0. self._orderprop if set
649 1. "order" property 667 1. "order" property
650 2. self.labelprop () 668 2. self.labelprop ()
731 is raised before any properties have been added. 749 is raised before any properties have been added.
732 """ 750 """
733 raise NotImplementedError 751 raise NotImplementedError
734 752
735 def index(self, nodeid): 753 def index(self, nodeid):
736 '''Add (or refresh) the node to search indexes 754 """Add (or refresh) the node to search indexes"""
737 ''' 755 raise NotImplementedError
738 raise NotImplementedError 756
739 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 #
740 def export_propnames(self): 781 def export_propnames(self):
741 '''List the property names for export from this Class.''' 782 """List the property names for export from this Class"""
742 propnames = self.getprops().keys() 783 propnames = self.getprops().keys()
743 propnames.sort() 784 propnames.sort()
744 return propnames 785 return propnames
745 786
746 787
827 ''' 868 '''
828 source = self.db.filename(self.classname, nodeid) 869 source = self.db.filename(self.classname, nodeid)
829 870
830 dest = self.exportFilename(dirname, nodeid) 871 dest = self.exportFilename(dirname, nodeid)
831 ensureParentsExist(dest) 872 ensureParentsExist(dest)
832 shutil.copyfile(source, dest) 873 shutil.copyfile(source, dest)
833 874
834 def import_files(self, dirname, nodeid): 875 def import_files(self, dirname, nodeid):
835 ''' Import the "content" property as a file 876 ''' Import the "content" property as a file
836 ''' 877 '''
837 source = self.exportFilename(dirname, nodeid) 878 source = self.exportFilename(dirname, nodeid)

Roundup Issue Tracker: http://roundup-tracker.org/