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.138 2004-03-18 01:58:45 richard Exp $
18+ #$Id: back_anydbm.py,v 1.139 2004-03-19 04:47:59 richard Exp $
1919'''This module defines a backend that saves the hyperdatabase in a
2020database chosen by anydbm. It is guaranteed to always be available in python
2121versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
3737from roundup import hyperdb , date , password , roundupdb , security
3838from blobfiles import FileStorage
3939from sessions_dbm import Sessions , OneTimeKeys
40- from roundup . indexer import Indexer
40+ from indexer_dbm import Indexer
4141from roundup .backends import locking
4242from roundup .hyperdb import String , Password , Date , Interval , Link , \
4343 Multilink , DatabaseError , Boolean , Number , Node
@@ -882,6 +882,7 @@ def create_inner(self, **propvalues):
882882 elif isinstance (prop , String ):
883883 if type (value ) != type ('' ) and type (value ) != type (u'' ):
884884 raise TypeError , 'new property "%s" not a string' % key
885+ self .db .indexer .add_text ((self .classname , newid , key ), value )
885886
886887 elif isinstance (prop , Password ):
887888 if not isinstance (value , password .Password ):
@@ -1143,6 +1144,15 @@ class or a KeyError is raised.
11431144 These operations trigger detectors and can be vetoed. Attempts
11441145 to modify the "creation" or "activity" properties cause a KeyError.
11451146 '''
1147+ self .fireAuditors ('set' , nodeid , propvalues )
1148+ oldvalues = copy .deepcopy (self .db .getnode (self .classname , nodeid ))
1149+ propvalues = self .set_inner (nodeid , ** propvalues )
1150+ self .fireReactors ('set' , nodeid , oldvalues )
1151+ return propvalues
1152+
1153+ def set_inner (self , nodeid , ** propvalues ):
1154+ ''' Called by set, in-between the audit and react calls.
1155+ '''
11461156 if not propvalues :
11471157 return propvalues
11481158
@@ -1155,11 +1165,6 @@ class or a KeyError is raised.
11551165 if self .db .journaltag is None :
11561166 raise DatabaseError , 'Database open read-only'
11571167
1158- self .fireAuditors ('set' , nodeid , propvalues )
1159- # Take a copy of the node dict so that the subsequent set
1160- # operation doesn't modify the oldvalues structure.
1161- oldvalues = copy .deepcopy (self .db .getnode (self .classname , nodeid ))
1162-
11631168 node = self .db .getnode (self .classname , nodeid )
11641169 if node .has_key (self .db .RETIRED_FLAG ):
11651170 raise IndexError
@@ -1290,6 +1295,8 @@ class or a KeyError is raised.
12901295 elif isinstance (prop , String ):
12911296 if value is not None and type (value ) != type ('' ) and type (value ) != type (u'' ):
12921297 raise TypeError , 'new property "%s" not a string' % propname
1298+ self .db .indexer .add_text ((self .classname , nodeid , propname ),
1299+ value )
12931300
12941301 elif isinstance (prop , Password ):
12951302 if not isinstance (value , password .Password ):
@@ -1331,9 +1338,7 @@ class or a KeyError is raised.
13311338 if self .do_journal :
13321339 self .db .addjournal (self .classname , nodeid , 'set' , journalvalues )
13331340
1334- self .fireReactors ('set' , nodeid , oldvalues )
1335-
1336- return propvalues
1341+ return propvalues
13371342
13381343 def retire (self , nodeid ):
13391344 '''Retire a node.
@@ -1946,20 +1951,18 @@ def addprop(self, **properties):
19461951 self .properties .update (properties )
19471952
19481953 def index (self , nodeid ):
1949- '''Add (or refresh) the node to search indexes
1950- '''
1954+ ''' Add (or refresh) the node to search indexes '''
19511955 # find all the String properties that have indexme
19521956 for prop , propclass in self .getprops ().items ():
1953- if isinstance (propclass , String ) and propclass .indexme :
1957+ if isinstance (propclass , hyperdb .String ) and propclass .indexme :
1958+ # index them under (classname, nodeid, property)
19541959 try :
19551960 value = str (self .get (nodeid , prop ))
19561961 except IndexError :
1957- # node no longer exists - entry should be removed
1958- self .db .indexer .purge_entry ((self .classname , nodeid , prop ))
1959- else :
1960- # and index them under (classname, nodeid, property)
1961- self .db .indexer .add_text ((self .classname , nodeid , prop ),
1962- value )
1962+ # node has been destroyed
1963+ continue
1964+ self .db .indexer .add_text ((self .classname , nodeid , prop ), value )
1965+
19631966
19641967 #
19651968 # Detector interface
@@ -2012,8 +2015,15 @@ def create(self, **propvalues):
20122015 content = propvalues ['content' ]
20132016 del propvalues ['content' ]
20142017
2018+ # make sure we have a MIME type
2019+ mime_type = propvalues .get ('type' , self .default_mime_type )
2020+
20152021 # do the database create
2016- newid = Class .create_inner (self , ** propvalues )
2022+ newid = self .create_inner (** propvalues )
2023+
2024+ # and index!
2025+ self .db .indexer .add_text ((self .classname , newid , 'content' ), content ,
2026+ mime_type )
20172027
20182028 # fire reactors
20192029 self .fireReactors ('create' , newid , None )
@@ -2059,6 +2069,35 @@ def get(self, nodeid, propname, default=_marker, cache=1):
20592069 else :
20602070 return Class .get (self , nodeid , propname )
20612071
2072+ def set (self , itemid , ** propvalues ):
2073+ ''' Snarf the "content" propvalue and update it in a file
2074+ '''
2075+ self .fireAuditors ('set' , itemid , propvalues )
2076+ oldvalues = copy .deepcopy (self .db .getnode (self .classname , itemid ))
2077+
2078+ # now remove the content property so it's not stored in the db
2079+ content = None
2080+ if propvalues .has_key ('content' ):
2081+ content = propvalues ['content' ]
2082+ del propvalues ['content' ]
2083+
2084+ # do the database create
2085+ propvalues = self .set_inner (itemid , ** propvalues )
2086+
2087+ # do content?
2088+ if content :
2089+ # store and index
2090+ self .db .storefile (self .classname , itemid , None , content )
2091+ mime_type = propvalues .get ('type' , self .get (itemid , 'type' ))
2092+ if not mime_type :
2093+ mime_type = self .default_mime_type
2094+ self .db .indexer .add_text ((self .classname , itemid , 'content' ),
2095+ content , mime_type )
2096+
2097+ # fire reactors
2098+ self .fireReactors ('set' , itemid , oldvalues )
2099+ return propvalues
2100+
20622101 def getprops (self , protected = 1 ):
20632102 ''' In addition to the actual properties on the node, these methods
20642103 provide the "content" property. If the "protected" flag is true,
@@ -2069,27 +2108,6 @@ def getprops(self, protected=1):
20692108 d ['content' ] = hyperdb .String ()
20702109 return d
20712110
2072- def index (self , nodeid ):
2073- ''' Index the node in the search index.
2074-
2075- We want to index the content in addition to the normal String
2076- property indexing.
2077- '''
2078- # perform normal indexing
2079- Class .index (self , nodeid )
2080-
2081- # get the content to index
2082- content = self .get (nodeid , 'content' )
2083-
2084- # figure the mime type
2085- if self .properties .has_key ('type' ):
2086- mime_type = self .get (nodeid , 'type' )
2087- else :
2088- mime_type = self .default_mime_type
2089-
2090- # and index!
2091- self .db .indexer .add_text ((self .classname , nodeid , 'content' ), content ,
2092- mime_type )
20932111
20942112# deviation from spec - was called ItemClass
20952113class IssueClass (Class , roundupdb .IssueClass ):
0 commit comments