Code

braino
[roundup.git] / roundup / hyperdb.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
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"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 # $Id: hyperdb.py,v 1.74 2002-07-10 00:24:10 richard Exp $
20 __doc__ = """
21 Hyperdatabase implementation, especially field types.
22 """
24 # standard python modules
25 import sys, re, string, weakref, os, time
27 # roundup modules
28 import date, password
30 # configure up the DEBUG and TRACE captures
31 class Sink:
32     def write(self, content):
33         pass
34 DEBUG = os.environ.get('HYPERDBDEBUG', '')
35 if DEBUG and __debug__:
36     if DEBUG == 'stdout':
37         DEBUG = sys.stdout
38     else:
39         DEBUG = open(DEBUG, 'a')
40 else:
41     DEBUG = Sink()
42 TRACE = os.environ.get('HYPERDBTRACE', '')
43 if TRACE and __debug__:
44     if TRACE == 'stdout':
45         TRACE = sys.stdout
46     else:
47         TRACE = open(TRACE, 'w')
48 else:
49     TRACE = Sink()
50 def traceMark():
51     print >>TRACE, '**MARK', time.ctime()
52 del Sink
54 #
55 # Types
56 #
57 class String:
58     """An object designating a String property."""
59     def __init__(self, indexme='no'):
60         self.indexme = indexme == 'yes'
61     def __repr__(self):
62         ' more useful for dumps '
63         return '<%s>'%self.__class__
65 class Password:
66     """An object designating a Password property."""
67     def __repr__(self):
68         ' more useful for dumps '
69         return '<%s>'%self.__class__
71 class Date:
72     """An object designating a Date property."""
73     def __repr__(self):
74         ' more useful for dumps '
75         return '<%s>'%self.__class__
77 class Interval:
78     """An object designating an Interval property."""
79     def __repr__(self):
80         ' more useful for dumps '
81         return '<%s>'%self.__class__
83 class Link:
84     """An object designating a Link property that links to a
85        node in a specified class."""
86     def __init__(self, classname, do_journal='no'):
87         ''' Default is to not journal link and unlink events
88         '''
89         self.classname = classname
90         self.do_journal = do_journal == 'yes'
91     def __repr__(self):
92         ' more useful for dumps '
93         return '<%s to "%s">'%(self.__class__, self.classname)
95 class Multilink:
96     """An object designating a Multilink property that links
97        to nodes in a specified class.
99        "classname" indicates the class to link to
101        "do_journal" indicates whether the linked-to nodes should have
102                     'link' and 'unlink' events placed in their journal
103     """
104     def __init__(self, classname, do_journal='no'):
105         ''' Default is to not journal link and unlink events
106         '''
107         self.classname = classname
108         self.do_journal = do_journal == 'yes'
109     def __repr__(self):
110         ' more useful for dumps '
111         return '<%s to "%s">'%(self.__class__, self.classname)
113 class DatabaseError(ValueError):
114     '''Error to be raised when there is some problem in the database code
115     '''
116     pass
120 # the base Database class
122 class Database:
123     '''A database for storing records containing flexible data types.
125 This class defines a hyperdatabase storage layer, which the Classes use to
126 store their data.
129 Transactions
130 ------------
131 The Database should support transactions through the commit() and
132 rollback() methods. All other Database methods should be transaction-aware,
133 using data from the current transaction before looking up the database.
135 An implementation must provide an override for the get() method so that the
136 in-database value is returned in preference to the in-transaction value.
137 This is necessary to determine if any values have changed during a
138 transaction.
140 '''
142     # flag to set on retired entries
143     RETIRED_FLAG = '__hyperdb_retired'
145     # XXX deviates from spec: storagelocator is obtained from the config
146     def __init__(self, config, journaltag=None):
147         """Open a hyperdatabase given a specifier to some storage.
149         The 'storagelocator' is obtained from config.DATABASE.
150         The meaning of 'storagelocator' depends on the particular
151         implementation of the hyperdatabase.  It could be a file name,
152         a directory path, a socket descriptor for a connection to a
153         database over the network, etc.
155         The 'journaltag' is a token that will be attached to the journal
156         entries for any edits done on the database.  If 'journaltag' is
157         None, the database is opened in read-only mode: the Class.create(),
158         Class.set(), and Class.retire() methods are disabled.
159         """
160         raise NotImplementedError
162     def post_init(self):
163         """Called once the schema initialisation has finished."""
164         raise NotImplementedError
166     def __getattr__(self, classname):
167         """A convenient way of calling self.getclass(classname)."""
168         raise NotImplementedError
170     def addclass(self, cl):
171         '''Add a Class to the hyperdatabase.
172         '''
173         raise NotImplementedError
175     def getclasses(self):
176         """Return a list of the names of all existing classes."""
177         raise NotImplementedError
179     def getclass(self, classname):
180         """Get the Class object representing a particular class.
182         If 'classname' is not a valid class name, a KeyError is raised.
183         """
184         raise NotImplementedError
186     def clear(self):
187         '''Delete all database contents.
188         '''
189         raise NotImplementedError
191     def getclassdb(self, classname, mode='r'):
192         '''Obtain a connection to the class db that will be used for
193            multiple actions.
194         '''
195         raise NotImplementedError
197     def addnode(self, classname, nodeid, node):
198         '''Add the specified node to its class's db.
199         '''
200         raise NotImplementedError
202     def serialise(self, classname, node):
203         '''Copy the node contents, converting non-marshallable data into
204            marshallable data.
205         '''
206         if __debug__:
207             print >>DEBUG, 'serialise', classname, node
208         properties = self.getclass(classname).getprops()
209         d = {}
210         for k, v in node.items():
211             # if the property doesn't exist, or is the "retired" flag then
212             # it won't be in the properties dict
213             if not properties.has_key(k):
214                 d[k] = v
215                 continue
217             # get the property spec
218             prop = properties[k]
220             if isinstance(prop, Password):
221                 d[k] = str(v)
222             elif isinstance(prop, Date) and v is not None:
223                 d[k] = v.get_tuple()
224             elif isinstance(prop, Interval) and v is not None:
225                 d[k] = v.get_tuple()
226             else:
227                 d[k] = v
228         return d
230     def setnode(self, classname, nodeid, node):
231         '''Change the specified node.
232         '''
233         raise NotImplementedError
235     def unserialise(self, classname, node):
236         '''Decode the marshalled node data
237         '''
238         if __debug__:
239             print >>DEBUG, 'unserialise', classname, node
240         properties = self.getclass(classname).getprops()
241         d = {}
242         for k, v in node.items():
243             # if the property doesn't exist, or is the "retired" flag then
244             # it won't be in the properties dict
245             if not properties.has_key(k):
246                 d[k] = v
247                 continue
249             # get the property spec
250             prop = properties[k]
252             if isinstance(prop, Date) and v is not None:
253                 d[k] = date.Date(v)
254             elif isinstance(prop, Interval) and v is not None:
255                 d[k] = date.Interval(v)
256             elif isinstance(prop, Password):
257                 p = password.Password()
258                 p.unpack(v)
259                 d[k] = p
260             else:
261                 d[k] = v
262         return d
264     def getnode(self, classname, nodeid, db=None, cache=1):
265         '''Get a node from the database.
266         '''
267         raise NotImplementedError
269     def hasnode(self, classname, nodeid, db=None):
270         '''Determine if the database has a given node.
271         '''
272         raise NotImplementedError
274     def countnodes(self, classname, db=None):
275         '''Count the number of nodes that exist for a particular Class.
276         '''
277         raise NotImplementedError
279     def getnodeids(self, classname, db=None):
280         '''Retrieve all the ids of the nodes for a particular Class.
281         '''
282         raise NotImplementedError
284     def storefile(self, classname, nodeid, property, content):
285         '''Store the content of the file in the database.
286         
287            The property may be None, in which case the filename does not
288            indicate which property is being saved.
289         '''
290         raise NotImplementedError
292     def getfile(self, classname, nodeid, property):
293         '''Store the content of the file in the database.
294         '''
295         raise NotImplementedError
297     def addjournal(self, classname, nodeid, action, params):
298         ''' Journal the Action
299         'action' may be:
301             'create' or 'set' -- 'params' is a dictionary of property values
302             'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
303             'retire' -- 'params' is None
304         '''
305         raise NotImplementedError
307     def getjournal(self, classname, nodeid):
308         ''' get the journal for id
309         '''
310         raise NotImplementedError
312     def pack(self, pack_before):
313         ''' pack the database
314         '''
315         raise NotImplementedError
317     def commit(self):
318         ''' Commit the current transactions.
320         Save all data changed since the database was opened or since the
321         last commit() or rollback().
322         '''
323         raise NotImplementedError
325     def rollback(self):
326         ''' Reverse all actions from the current transaction.
328         Undo all the changes made since the database was opened or the last
329         commit() or rollback() was performed.
330         '''
331         raise NotImplementedError
333 _marker = []
335 # The base Class class
337 class Class:
338     """The handle to a particular class of nodes in a hyperdatabase."""
340     def __init__(self, db, classname, **properties):
341         """Create a new class with a given name and property specification.
343         'classname' must not collide with the name of an existing class,
344         or a ValueError is raised.  The keyword arguments in 'properties'
345         must map names to property objects, or a TypeError is raised.
346         """
347         self.classname = classname
348         self.properties = properties
349         self.db = weakref.proxy(db)       # use a weak ref to avoid circularity
350         self.key = ''
352         # do the db-related init stuff
353         db.addclass(self)
355     def __repr__(self):
356         '''Slightly more useful representation
357         '''
358         return '<hypderdb.Class "%s">'%self.classname
360     # Editing nodes:
362     def create(self, **propvalues):
363         """Create a new node of this class and return its id.
365         The keyword arguments in 'propvalues' map property names to values.
367         The values of arguments must be acceptable for the types of their
368         corresponding properties or a TypeError is raised.
369         
370         If this class has a key property, it must be present and its value
371         must not collide with other key strings or a ValueError is raised.
372         
373         Any other properties on this class that are missing from the
374         'propvalues' dictionary are set to None.
375         
376         If an id in a link or multilink property does not refer to a valid
377         node, an IndexError is raised.
378         """
379         if propvalues.has_key('id'):
380             raise KeyError, '"id" is reserved'
382         if self.db.journaltag is None:
383             raise DatabaseError, 'Database open read-only'
385         # new node's id
386         newid = self.db.newid(self.classname)
388         # validate propvalues
389         num_re = re.compile('^\d+$')
390         for key, value in propvalues.items():
391             if key == self.key:
392                 try:
393                     self.lookup(value)
394                 except KeyError:
395                     pass
396                 else:
397                     raise ValueError, 'node with key "%s" exists'%value
399             # try to handle this property
400             try:
401                 prop = self.properties[key]
402             except KeyError:
403                 raise KeyError, '"%s" has no property "%s"'%(self.classname,
404                     key)
406             if isinstance(prop, Link):
407                 if type(value) != type(''):
408                     raise ValueError, 'link value must be String'
409                 link_class = self.properties[key].classname
410                 # if it isn't a number, it's a key
411                 if not num_re.match(value):
412                     try:
413                         value = self.db.classes[link_class].lookup(value)
414                     except (TypeError, KeyError):
415                         raise IndexError, 'new property "%s": %s not a %s'%(
416                             key, value, link_class)
417                 elif not self.db.hasnode(link_class, value):
418                     raise IndexError, '%s has no node %s'%(link_class, value)
420                 # save off the value
421                 propvalues[key] = value
423                 # register the link with the newly linked node
424                 if self.properties[key].do_journal:
425                     self.db.addjournal(link_class, value, 'link',
426                         (self.classname, newid, key))
428             elif isinstance(prop, Multilink):
429                 if type(value) != type([]):
430                     raise TypeError, 'new property "%s" not a list of ids'%key
432                 # clean up and validate the list of links
433                 link_class = self.properties[key].classname
434                 l = []
435                 for entry in value:
436                     if type(entry) != type(''):
437                         raise ValueError, '"%s" link value (%s) must be String' % (key, value)
438                     # if it isn't a number, it's a key
439                     if not num_re.match(entry):
440                         try:
441                             entry = self.db.classes[link_class].lookup(entry)
442                         except (TypeError, KeyError):
443                             raise IndexError, 'new property "%s": %s not a %s'%(
444                                 key, entry, self.properties[key].classname)
445                     l.append(entry)
446                 value = l
447                 propvalues[key] = value
449                 # handle additions
450                 for id in value:
451                     if not self.db.hasnode(link_class, id):
452                         raise IndexError, '%s has no node %s'%(link_class, id)
453                     # register the link with the newly linked node
454                     if self.properties[key].do_journal:
455                         self.db.addjournal(link_class, id, 'link',
456                             (self.classname, newid, key))
458             elif isinstance(prop, String):
459                 if type(value) != type(''):
460                     raise TypeError, 'new property "%s" not a string'%key
462             elif isinstance(prop, Password):
463                 if not isinstance(value, password.Password):
464                     raise TypeError, 'new property "%s" not a Password'%key
466             elif isinstance(prop, Date):
467                 if value is not None and not isinstance(value, date.Date):
468                     raise TypeError, 'new property "%s" not a Date'%key
470             elif isinstance(prop, Interval):
471                 if value is not None and not isinstance(value, date.Interval):
472                     raise TypeError, 'new property "%s" not an Interval'%key
474         # make sure there's data where there needs to be
475         for key, prop in self.properties.items():
476             if propvalues.has_key(key):
477                 continue
478             if key == self.key:
479                 raise ValueError, 'key property "%s" is required'%key
480             if isinstance(prop, Multilink):
481                 propvalues[key] = []
482             else:
483                 # TODO: None isn't right here, I think...
484                 propvalues[key] = None
486         # done
487         self.db.addnode(self.classname, newid, propvalues)
488         self.db.addjournal(self.classname, newid, 'create', propvalues)
489         return newid
491     def get(self, nodeid, propname, default=_marker, cache=1):
492         """Get the value of a property on an existing node of this class.
494         'nodeid' must be the id of an existing node of this class or an
495         IndexError is raised.  'propname' must be the name of a property
496         of this class or a KeyError is raised.
498         'cache' indicates whether the transaction cache should be queried
499         for the node. If the node has been modified and you need to
500         determine what its values prior to modification are, you need to
501         set cache=0.
502         """
503         if propname == 'id':
504             return nodeid
506         # get the property (raises KeyErorr if invalid)
507         prop = self.properties[propname]
509         # get the node's dict
510         d = self.db.getnode(self.classname, nodeid, cache=cache)
512         if not d.has_key(propname):
513             if default is _marker:
514                 if isinstance(prop, Multilink):
515                     return []
516                 else:
517                     # TODO: None isn't right here, I think...
518                     return None
519             else:
520                 return default
522         return d[propname]
524     # XXX not in spec
525     def getnode(self, nodeid, cache=1):
526         ''' Return a convenience wrapper for the node.
528         'nodeid' must be the id of an existing node of this class or an
529         IndexError is raised.
531         'cache' indicates whether the transaction cache should be queried
532         for the node. If the node has been modified and you need to
533         determine what its values prior to modification are, you need to
534         set cache=0.
535         '''
536         return Node(self, nodeid, cache=cache)
538     def set(self, nodeid, **propvalues):
539         """Modify a property on an existing node of this class.
540         
541         'nodeid' must be the id of an existing node of this class or an
542         IndexError is raised.
544         Each key in 'propvalues' must be the name of a property of this
545         class or a KeyError is raised.
547         All values in 'propvalues' must be acceptable types for their
548         corresponding properties or a TypeError is raised.
550         If the value of the key property is set, it must not collide with
551         other key strings or a ValueError is raised.
553         If the value of a Link or Multilink property contains an invalid
554         node id, a ValueError is raised.
555         """
556         if not propvalues:
557             return
559         if propvalues.has_key('id'):
560             raise KeyError, '"id" is reserved'
562         if self.db.journaltag is None:
563             raise DatabaseError, 'Database open read-only'
565         node = self.db.getnode(self.classname, nodeid)
566         if node.has_key(self.db.RETIRED_FLAG):
567             raise IndexError
568         num_re = re.compile('^\d+$')
569         for key, value in propvalues.items():
570             # check to make sure we're not duplicating an existing key
571             if key == self.key and node[key] != value:
572                 try:
573                     self.lookup(value)
574                 except KeyError:
575                     pass
576                 else:
577                     raise ValueError, 'node with key "%s" exists'%value
579             # this will raise the KeyError if the property isn't valid
580             # ... we don't use getprops() here because we only care about
581             # the writeable properties.
582             prop = self.properties[key]
584             # if the value's the same as the existing value, no sense in
585             # doing anything
586             if node.has_key(key) and value == node[key]:
587                 del propvalues[key]
588                 continue
590             # do stuff based on the prop type
591             if isinstance(prop, Link):
592                 link_class = self.properties[key].classname
593                 # if it isn't a number, it's a key
594                 if type(value) != type(''):
595                     raise ValueError, 'link value must be String'
596                 if not num_re.match(value):
597                     try:
598                         value = self.db.classes[link_class].lookup(value)
599                     except (TypeError, KeyError):
600                         raise IndexError, 'new property "%s": %s not a %s'%(
601                             key, value, self.properties[key].classname)
603                 if not self.db.hasnode(link_class, value):
604                     raise IndexError, '%s has no node %s'%(link_class, value)
606                 if self.properties[key].do_journal:
607                     # register the unlink with the old linked node
608                     if node[key] is not None:
609                         self.db.addjournal(link_class, node[key], 'unlink',
610                             (self.classname, nodeid, key))
612                     # register the link with the newly linked node
613                     if value is not None:
614                         self.db.addjournal(link_class, value, 'link',
615                             (self.classname, nodeid, key))
617             elif isinstance(prop, Multilink):
618                 if type(value) != type([]):
619                     raise TypeError, 'new property "%s" not a list of ids'%key
620                 link_class = self.properties[key].classname
621                 l = []
622                 for entry in value:
623                     # if it isn't a number, it's a key
624                     if type(entry) != type(''):
625                         raise ValueError, 'new property "%s" link value ' \
626                             'must be a string'%key
627                     if not num_re.match(entry):
628                         try:
629                             entry = self.db.classes[link_class].lookup(entry)
630                         except (TypeError, KeyError):
631                             raise IndexError, 'new property "%s": %s not a %s'%(
632                                 key, entry, self.properties[key].classname)
633                     l.append(entry)
634                 value = l
635                 propvalues[key] = value
637                 # handle removals
638                 if node.has_key(key):
639                     l = node[key]
640                 else:
641                     l = []
642                 for id in l[:]:
643                     if id in value:
644                         continue
645                     # register the unlink with the old linked node
646                     if self.properties[key].do_journal:
647                         self.db.addjournal(link_class, id, 'unlink',
648                             (self.classname, nodeid, key))
649                     l.remove(id)
651                 # handle additions
652                 for id in value:
653                     if not self.db.hasnode(link_class, id):
654                         raise IndexError, '%s has no node %s'%(
655                             link_class, id)
656                     if id in l:
657                         continue
658                     # register the link with the newly linked node
659                     if self.properties[key].do_journal:
660                         self.db.addjournal(link_class, id, 'link',
661                             (self.classname, nodeid, key))
662                     l.append(id)
664             elif isinstance(prop, String):
665                 if value is not None and type(value) != type(''):
666                     raise TypeError, 'new property "%s" not a string'%key
668             elif isinstance(prop, Password):
669                 if not isinstance(value, password.Password):
670                     raise TypeError, 'new property "%s" not a Password'% key
671                 propvalues[key] = value
673             elif value is not None and isinstance(prop, Date):
674                 if not isinstance(value, date.Date):
675                     raise TypeError, 'new property "%s" not a Date'% key
676                 propvalues[key] = value
678             elif value is not None and isinstance(prop, Interval):
679                 if not isinstance(value, date.Interval):
680                     raise TypeError, 'new property "%s" not an Interval'% key
681                 propvalues[key] = value
683             node[key] = value
685         # nothing to do?
686         if not propvalues:
687             return
689         # do the set, and journal it
690         self.db.setnode(self.classname, nodeid, node)
691         self.db.addjournal(self.classname, nodeid, 'set', propvalues)
693     def retire(self, nodeid):
694         """Retire a node.
695         
696         The properties on the node remain available from the get() method,
697         and the node's id is never reused.
698         
699         Retired nodes are not returned by the find(), list(), or lookup()
700         methods, and other nodes may reuse the values of their key properties.
701         """
702         if self.db.journaltag is None:
703             raise DatabaseError, 'Database open read-only'
704         node = self.db.getnode(self.classname, nodeid)
705         node[self.db.RETIRED_FLAG] = 1
706         self.db.setnode(self.classname, nodeid, node)
707         self.db.addjournal(self.classname, nodeid, 'retired', None)
709     def history(self, nodeid):
710         """Retrieve the journal of edits on a particular node.
712         'nodeid' must be the id of an existing node of this class or an
713         IndexError is raised.
715         The returned list contains tuples of the form
717             (date, tag, action, params)
719         'date' is a Timestamp object specifying the time of the change and
720         'tag' is the journaltag specified when the database was opened.
721         """
722         return self.db.getjournal(self.classname, nodeid)
724     # Locating nodes:
725     def hasnode(self, nodeid):
726         '''Determine if the given nodeid actually exists
727         '''
728         return self.db.hasnode(self.classname, nodeid)
730     def setkey(self, propname):
731         """Select a String property of this class to be the key property.
733         'propname' must be the name of a String property of this class or
734         None, or a TypeError is raised.  The values of the key property on
735         all existing nodes must be unique or a ValueError is raised.
736         """
737         # TODO: validate that the property is a String!
738         self.key = propname
740     def getkey(self):
741         """Return the name of the key property for this class or None."""
742         return self.key
744     def labelprop(self, default_to_id=0):
745         ''' Return the property name for a label for the given node.
747         This method attempts to generate a consistent label for the node.
748         It tries the following in order:
749             1. key property
750             2. "name" property
751             3. "title" property
752             4. first property from the sorted property name list
753         '''
754         k = self.getkey()
755         if  k:
756             return k
757         props = self.getprops()
758         if props.has_key('name'):
759             return 'name'
760         elif props.has_key('title'):
761             return 'title'
762         if default_to_id:
763             return 'id'
764         props = props.keys()
765         props.sort()
766         return props[0]
768     # TODO: set up a separate index db file for this? profile?
769     def lookup(self, keyvalue):
770         """Locate a particular node by its key property and return its id.
772         If this class has no key property, a TypeError is raised.  If the
773         'keyvalue' matches one of the values for the key property among
774         the nodes in this class, the matching node's id is returned;
775         otherwise a KeyError is raised.
776         """
777         cldb = self.db.getclassdb(self.classname)
778         try:
779             for nodeid in self.db.getnodeids(self.classname, cldb):
780                 node = self.db.getnode(self.classname, nodeid, cldb)
781                 if node.has_key(self.db.RETIRED_FLAG):
782                     continue
783                 if node[self.key] == keyvalue:
784                     cldb.close()
785                     return nodeid
786         finally:
787             cldb.close()
788         raise KeyError, keyvalue
790     # XXX: change from spec - allows multiple props to match
791     def find(self, **propspec):
792         """Get the ids of nodes in this class which link to the given nodes.
794         'propspec' consists of keyword args propname={nodeid:1,}   
795           'propname' must be the name of a property in this class, or a
796             KeyError is raised.  That property must be a Link or Multilink
797             property, or a TypeError is raised.
799         Any node in this class whose 'propname' property links to any of the
800         nodeids will be returned. Used by the full text indexing, which knows
801         that "foo" occurs in msg1, msg3 and file7, so we have hits on these issues:
802             db.issue.find(messages={'1':1,'3':1}, files={'7':1})
803         """
804         propspec = propspec.items()
805         for propname, nodeids in propspec:
806             # check the prop is OK
807             prop = self.properties[propname]
808             if not isinstance(prop, Link) and not isinstance(prop, Multilink):
809                 raise TypeError, "'%s' not a Link/Multilink property"%propname
810             #XXX edit is expensive and of questionable use
811             #for nodeid in nodeids:
812             #    if not self.db.hasnode(prop.classname, nodeid):
813             #        raise ValueError, '%s has no node %s'%(prop.classname, nodeid)
815         # ok, now do the find
816         cldb = self.db.getclassdb(self.classname)
817         l = []
818         try:
819             for id in self.db.getnodeids(self.classname, db=cldb):
820                 node = self.db.getnode(self.classname, id, db=cldb)
821                 if node.has_key(self.db.RETIRED_FLAG):
822                     continue
823                 for propname, nodeids in propspec:
824                     # can't test if the node doesn't have this property
825                     if not node.has_key(propname):
826                         continue
827                     if type(nodeids) is type(''):
828                         nodeids = {nodeids:1}
829                     prop = self.properties[propname]
830                     value = node[propname]
831                     if isinstance(prop, Link) and nodeids.has_key(value):
832                         l.append(id)
833                         break
834                     elif isinstance(prop, Multilink):
835                         hit = 0
836                         for v in value:
837                             if nodeids.has_key(v):
838                                 l.append(id)
839                                 hit = 1
840                                 break
841                         if hit:
842                             break
843         finally:
844             cldb.close()
845         return l
847     def stringFind(self, **requirements):
848         """Locate a particular node by matching a set of its String
849         properties in a caseless search.
851         If the property is not a String property, a TypeError is raised.
852         
853         The return is a list of the id of all nodes that match.
854         """
855         for propname in requirements.keys():
856             prop = self.properties[propname]
857             if isinstance(not prop, String):
858                 raise TypeError, "'%s' not a String property"%propname
859             requirements[propname] = requirements[propname].lower()
860         l = []
861         cldb = self.db.getclassdb(self.classname)
862         try:
863             for nodeid in self.db.getnodeids(self.classname, cldb):
864                 node = self.db.getnode(self.classname, nodeid, cldb)
865                 if node.has_key(self.db.RETIRED_FLAG):
866                     continue
867                 for key, value in requirements.items():
868                     if node[key] and node[key].lower() != value:
869                         break
870                 else:
871                     l.append(nodeid)
872         finally:
873             cldb.close()
874         return l
876     def list(self):
877         """Return a list of the ids of the active nodes in this class."""
878         l = []
879         cn = self.classname
880         cldb = self.db.getclassdb(cn)
881         try:
882             for nodeid in self.db.getnodeids(cn, cldb):
883                 node = self.db.getnode(cn, nodeid, cldb)
884                 if node.has_key(self.db.RETIRED_FLAG):
885                     continue
886                 l.append(nodeid)
887         finally:
888             cldb.close()
889         l.sort()
890         return l
892     # XXX not in spec
893     def filter(self, search_matches, filterspec, sort, group, 
894             num_re = re.compile('^\d+$')):
895         ''' Return a list of the ids of the active nodes in this class that
896             match the 'filter' spec, sorted by the group spec and then the
897             sort spec
898         '''
899         cn = self.classname
901         # optimise filterspec
902         l = []
903         props = self.getprops()
904         for k, v in filterspec.items():
905             propclass = props[k]
906             if isinstance(propclass, Link):
907                 if type(v) is not type([]):
908                     v = [v]
909                 # replace key values with node ids
910                 u = []
911                 link_class =  self.db.classes[propclass.classname]
912                 for entry in v:
913                     if entry == '-1': entry = None
914                     elif not num_re.match(entry):
915                         try:
916                             entry = link_class.lookup(entry)
917                         except (TypeError,KeyError):
918                             raise ValueError, 'property "%s": %s not a %s'%(
919                                 k, entry, self.properties[k].classname)
920                     u.append(entry)
922                 l.append((0, k, u))
923             elif isinstance(propclass, Multilink):
924                 if type(v) is not type([]):
925                     v = [v]
926                 # replace key values with node ids
927                 u = []
928                 link_class =  self.db.classes[propclass.classname]
929                 for entry in v:
930                     if not num_re.match(entry):
931                         try:
932                             entry = link_class.lookup(entry)
933                         except (TypeError,KeyError):
934                             raise ValueError, 'new property "%s": %s not a %s'%(
935                                 k, entry, self.properties[k].classname)
936                     u.append(entry)
937                 l.append((1, k, u))
938             elif isinstance(propclass, String):
939                 # simple glob searching
940                 v = re.sub(r'([\|\{\}\\\.\+\[\]\(\)])', r'\\\1', v)
941                 v = v.replace('?', '.')
942                 v = v.replace('*', '.*?')
943                 l.append((2, k, re.compile(v, re.I)))
944             else:
945                 l.append((6, k, v))
946         filterspec = l
948         # now, find all the nodes that are active and pass filtering
949         l = []
950         cldb = self.db.getclassdb(cn)
951         try:
952             for nodeid in self.db.getnodeids(cn, cldb):
953                 node = self.db.getnode(cn, nodeid, cldb)
954                 if node.has_key(self.db.RETIRED_FLAG):
955                     continue
956                 # apply filter
957                 for t, k, v in filterspec:
958                     # this node doesn't have this property, so reject it
959                     if not node.has_key(k): break
961                     if t == 0 and node[k] not in v:
962                         # link - if this node'd property doesn't appear in the
963                         # filterspec's nodeid list, skip it
964                         break
965                     elif t == 1:
966                         # multilink - if any of the nodeids required by the
967                         # filterspec aren't in this node's property, then skip
968                         # it
969                         for value in v:
970                             if value not in node[k]:
971                                 break
972                         else:
973                             continue
974                         break
975                     elif t == 2 and (node[k] is None or not v.search(node[k])):
976                         # RE search
977                         break
978                     elif t == 6 and node[k] != v:
979                         # straight value comparison for the other types
980                         break
981                 else:
982                     l.append((nodeid, node))
983         finally:
984             cldb.close()
985         l.sort()
987         # filter based on full text search
988         if search_matches is not None:
989             k = []
990             l_debug = []
991             for v in l:
992                 l_debug.append(v[0])
993                 if search_matches.has_key(v[0]):
994                     k.append(v)
995             l = k
997         # optimise sort
998         m = []
999         for entry in sort:
1000             if entry[0] != '-':
1001                 m.append(('+', entry))
1002             else:
1003                 m.append((entry[0], entry[1:]))
1004         sort = m
1006         # optimise group
1007         m = []
1008         for entry in group:
1009             if entry[0] != '-':
1010                 m.append(('+', entry))
1011             else:
1012                 m.append((entry[0], entry[1:]))
1013         group = m
1014         # now, sort the result
1015         def sortfun(a, b, sort=sort, group=group, properties=self.getprops(),
1016                 db = self.db, cl=self):
1017             a_id, an = a
1018             b_id, bn = b
1019             # sort by group and then sort
1020             for list in group, sort:
1021                 for dir, prop in list:
1022                     # sorting is class-specific
1023                     propclass = properties[prop]
1025                     # handle the properties that might be "faked"
1026                     # also, handle possible missing properties
1027                     try:
1028                         if not an.has_key(prop):
1029                             an[prop] = cl.get(a_id, prop)
1030                         av = an[prop]
1031                     except KeyError:
1032                         # the node doesn't have a value for this property
1033                         if isinstance(propclass, Multilink): av = []
1034                         else: av = ''
1035                     try:
1036                         if not bn.has_key(prop):
1037                             bn[prop] = cl.get(b_id, prop)
1038                         bv = bn[prop]
1039                     except KeyError:
1040                         # the node doesn't have a value for this property
1041                         if isinstance(propclass, Multilink): bv = []
1042                         else: bv = ''
1044                     # String and Date values are sorted in the natural way
1045                     if isinstance(propclass, String):
1046                         # clean up the strings
1047                         if av and av[0] in string.uppercase:
1048                             av = an[prop] = av.lower()
1049                         if bv and bv[0] in string.uppercase:
1050                             bv = bn[prop] = bv.lower()
1051                     if (isinstance(propclass, String) or
1052                             isinstance(propclass, Date)):
1053                         # it might be a string that's really an integer
1054                         try:
1055                             av = int(av)
1056                             bv = int(bv)
1057                         except:
1058                             pass
1059                         if dir == '+':
1060                             r = cmp(av, bv)
1061                             if r != 0: return r
1062                         elif dir == '-':
1063                             r = cmp(bv, av)
1064                             if r != 0: return r
1066                     # Link properties are sorted according to the value of
1067                     # the "order" property on the linked nodes if it is
1068                     # present; or otherwise on the key string of the linked
1069                     # nodes; or finally on  the node ids.
1070                     elif isinstance(propclass, Link):
1071                         link = db.classes[propclass.classname]
1072                         if av is None and bv is not None: return -1
1073                         if av is not None and bv is None: return 1
1074                         if av is None and bv is None: continue
1075                         if link.getprops().has_key('order'):
1076                             if dir == '+':
1077                                 r = cmp(link.get(av, 'order'),
1078                                     link.get(bv, 'order'))
1079                                 if r != 0: return r
1080                             elif dir == '-':
1081                                 r = cmp(link.get(bv, 'order'),
1082                                     link.get(av, 'order'))
1083                                 if r != 0: return r
1084                         elif link.getkey():
1085                             key = link.getkey()
1086                             if dir == '+':
1087                                 r = cmp(link.get(av, key), link.get(bv, key))
1088                                 if r != 0: return r
1089                             elif dir == '-':
1090                                 r = cmp(link.get(bv, key), link.get(av, key))
1091                                 if r != 0: return r
1092                         else:
1093                             if dir == '+':
1094                                 r = cmp(av, bv)
1095                                 if r != 0: return r
1096                             elif dir == '-':
1097                                 r = cmp(bv, av)
1098                                 if r != 0: return r
1100                     # Multilink properties are sorted according to how many
1101                     # links are present.
1102                     elif isinstance(propclass, Multilink):
1103                         if dir == '+':
1104                             r = cmp(len(av), len(bv))
1105                             if r != 0: return r
1106                         elif dir == '-':
1107                             r = cmp(len(bv), len(av))
1108                             if r != 0: return r
1109                 # end for dir, prop in list:
1110             # end for list in sort, group:
1111             # if all else fails, compare the ids
1112             return cmp(a[0], b[0])
1114         l.sort(sortfun)
1115         return [i[0] for i in l]
1117     def count(self):
1118         """Get the number of nodes in this class.
1120         If the returned integer is 'numnodes', the ids of all the nodes
1121         in this class run from 1 to numnodes, and numnodes+1 will be the
1122         id of the next node to be created in this class.
1123         """
1124         return self.db.countnodes(self.classname)
1126     # Manipulating properties:
1128     def getprops(self, protected=1):
1129         """Return a dictionary mapping property names to property objects.
1130            If the "protected" flag is true, we include protected properties -
1131            those which may not be modified."""
1132         d = self.properties.copy()
1133         if protected:
1134             d['id'] = String()
1135         return d
1137     def addprop(self, **properties):
1138         """Add properties to this class.
1140         The keyword arguments in 'properties' must map names to property
1141         objects, or a TypeError is raised.  None of the keys in 'properties'
1142         may collide with the names of existing properties, or a ValueError
1143         is raised before any properties have been added.
1144         """
1145         for key in properties.keys():
1146             if self.properties.has_key(key):
1147                 raise ValueError, key
1148         self.properties.update(properties)
1150     def index(self, nodeid):
1151         '''Add (or refresh) the node to search indexes
1152         '''
1153         # find all the String properties that have indexme
1154         for prop, propclass in self.getprops().items():
1155             if isinstance(propclass, String) and propclass.indexme:
1156                 # and index them under (classname, nodeid, property)
1157                 self.db.indexer.add_text((self.classname, nodeid, prop),
1158                     str(self.get(nodeid, prop)))
1160 # XXX not in spec
1161 class Node:
1162     ''' A convenience wrapper for the given node
1163     '''
1164     def __init__(self, cl, nodeid, cache=1):
1165         self.__dict__['cl'] = cl
1166         self.__dict__['nodeid'] = nodeid
1167         self.__dict__['cache'] = cache
1168     def keys(self, protected=1):
1169         return self.cl.getprops(protected=protected).keys()
1170     def values(self, protected=1):
1171         l = []
1172         for name in self.cl.getprops(protected=protected).keys():
1173             l.append(self.cl.get(self.nodeid, name, cache=self.cache))
1174         return l
1175     def items(self, protected=1):
1176         l = []
1177         for name in self.cl.getprops(protected=protected).keys():
1178             l.append((name, self.cl.get(self.nodeid, name, cache=self.cache)))
1179         return l
1180     def has_key(self, name):
1181         return self.cl.getprops().has_key(name)
1182     def __getattr__(self, name):
1183         if self.__dict__.has_key(name):
1184             return self.__dict__[name]
1185         try:
1186             return self.cl.get(self.nodeid, name, cache=self.cache)
1187         except KeyError, value:
1188             # we trap this but re-raise it as AttributeError - all other
1189             # exceptions should pass through untrapped
1190             pass
1191         # nope, no such attribute
1192         raise AttributeError, str(value)
1193     def __getitem__(self, name):
1194         return self.cl.get(self.nodeid, name, cache=self.cache)
1195     def __setattr__(self, name, value):
1196         try:
1197             return self.cl.set(self.nodeid, **{name: value})
1198         except KeyError, value:
1199             raise AttributeError, str(value)
1200     def __setitem__(self, name, value):
1201         self.cl.set(self.nodeid, **{name: value})
1202     def history(self):
1203         return self.cl.history(self.nodeid)
1204     def retire(self):
1205         return self.cl.retire(self.nodeid)
1208 def Choice(name, db, *options):
1209     '''Quick helper to create a simple class with choices
1210     '''
1211     cl = Class(db, name, name=String(), order=String())
1212     for i in range(len(options)):
1213         cl.create(name=options[i], order=i)
1214     return hyperdb.Link(name)
1217 # $Log: not supported by cvs2svn $
1218 # Revision 1.73  2002/07/10 00:19:48  richard
1219 # Added explicit closing of backend database handles.
1221 # Revision 1.72  2002/07/09 21:53:38  gmcm
1222 # Optimize Class.find so that the propspec can contain a set of ids to match.
1223 # This is used by indexer.search so it can do just one find for all the index matches.
1224 # This was already confusing code, but for common terms (lots of index matches),
1225 # it is enormously faster.
1227 # Revision 1.71  2002/07/09 03:02:52  richard
1228 # More indexer work:
1229 # - all String properties may now be indexed too. Currently there's a bit of
1230 #   "issue" specific code in the actual searching which needs to be
1231 #   addressed. In a nutshell:
1232 #   + pass 'indexme="yes"' as a String() property initialisation arg, eg:
1233 #         file = FileClass(db, "file", name=String(), type=String(),
1234 #             comment=String(indexme="yes"))
1235 #   + the comment will then be indexed and be searchable, with the results
1236 #     related back to the issue that the file is linked to
1237 # - as a result of this work, the FileClass has a default MIME type that may
1238 #   be overridden in a subclass, or by the use of a "type" property as is
1239 #   done in the default templates.
1240 # - the regeneration of the indexes (if necessary) is done once the schema is
1241 #   set up in the dbinit.
1243 # Revision 1.70  2002/06/27 12:06:20  gmcm
1244 # Improve an error message.
1246 # Revision 1.69  2002/06/17 23:15:29  richard
1247 # Can debug to stdout now
1249 # Revision 1.68  2002/06/11 06:52:03  richard
1250 #  . #564271 ] find() and new properties
1252 # Revision 1.67  2002/06/11 05:02:37  richard
1253 #  . #565979 ] code error in hyperdb.Class.find
1255 # Revision 1.66  2002/05/25 07:16:24  rochecompaan
1256 # Merged search_indexing-branch with HEAD
1258 # Revision 1.65  2002/05/22 04:12:05  richard
1259 #  . applied patch #558876 ] cgi client customization
1260 #    ... with significant additions and modifications ;)
1261 #    - extended handling of ML assignedto to all places it's handled
1262 #    - added more NotFound info
1264 # Revision 1.64  2002/05/15 06:21:21  richard
1265 #  . node caching now works, and gives a small boost in performance
1267 # As a part of this, I cleaned up the DEBUG output and implemented TRACE
1268 # output (HYPERDBTRACE='file to trace to') with checkpoints at the start of
1269 # CGI requests. Run roundup with python -O to skip all the DEBUG/TRACE stuff
1270 # (using if __debug__ which is compiled out with -O)
1272 # Revision 1.63  2002/04/15 23:25:15  richard
1273 # . node ids are now generated from a lockable store - no more race conditions
1275 # We're using the portalocker code by Jonathan Feinberg that was contributed
1276 # to the ASPN Python cookbook. This gives us locking across Unix and Windows.
1278 # Revision 1.62  2002/04/03 07:05:50  richard
1279 # d'oh! killed retirement of nodes :(
1280 # all better now...
1282 # Revision 1.61  2002/04/03 06:11:51  richard
1283 # Fix for old databases that contain properties that don't exist any more.
1285 # Revision 1.60  2002/04/03 05:54:31  richard
1286 # Fixed serialisation problem by moving the serialisation step out of the
1287 # hyperdb.Class (get, set) into the hyperdb.Database.
1289 # Also fixed htmltemplate after the showid changes I made yesterday.
1291 # Unit tests for all of the above written.
1293 # Revision 1.59.2.2  2002/04/20 13:23:33  rochecompaan
1294 # We now have a separate search page for nodes.  Search links for
1295 # different classes can be customized in instance_config similar to
1296 # index links.
1298 # Revision 1.59.2.1  2002/04/19 19:54:42  rochecompaan
1299 # cgi_client.py
1300 #     removed search link for the time being
1301 #     moved rendering of matches to htmltemplate
1302 # hyperdb.py
1303 #     filtering of nodes on full text search incorporated in filter method
1304 # roundupdb.py
1305 #     added paramater to call of filter method
1306 # roundup_indexer.py
1307 #     added search method to RoundupIndexer class
1309 # Revision 1.59  2002/03/12 22:52:26  richard
1310 # more pychecker warnings removed
1312 # Revision 1.58  2002/02/27 03:23:16  richard
1313 # Ran it through pychecker, made fixes
1315 # Revision 1.57  2002/02/20 05:23:24  richard
1316 # Didn't accomodate new values for new properties
1318 # Revision 1.56  2002/02/20 05:05:28  richard
1319 #  . Added simple editing for classes that don't define a templated interface.
1320 #    - access using the admin "class list" interface
1321 #    - limited to admin-only
1322 #    - requires the csv module from object-craft (url given if it's missing)
1324 # Revision 1.55  2002/02/15 07:27:12  richard
1325 # Oops, precedences around the way w0rng.
1327 # Revision 1.54  2002/02/15 07:08:44  richard
1328 #  . Alternate email addresses are now available for users. See the MIGRATION
1329 #    file for info on how to activate the feature.
1331 # Revision 1.53  2002/01/22 07:21:13  richard
1332 # . fixed back_bsddb so it passed the journal tests
1334 # ... it didn't seem happy using the back_anydbm _open method, which is odd.
1335 # Yet another occurrance of whichdb not being able to recognise older bsddb
1336 # databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the
1337 # process.
1339 # Revision 1.52  2002/01/21 16:33:19  rochecompaan
1340 # You can now use the roundup-admin tool to pack the database
1342 # Revision 1.51  2002/01/21 03:01:29  richard
1343 # brief docco on the do_journal argument
1345 # Revision 1.50  2002/01/19 13:16:04  rochecompaan
1346 # Journal entries for link and multilink properties can now be switched on
1347 # or off.
1349 # Revision 1.49  2002/01/16 07:02:57  richard
1350 #  . lots of date/interval related changes:
1351 #    - more relaxed date format for input
1353 # Revision 1.48  2002/01/14 06:32:34  richard
1354 #  . #502951 ] adding new properties to old database
1356 # Revision 1.47  2002/01/14 02:20:15  richard
1357 #  . changed all config accesses so they access either the instance or the
1358 #    config attriubute on the db. This means that all config is obtained from
1359 #    instance_config instead of the mish-mash of classes. This will make
1360 #    switching to a ConfigParser setup easier too, I hope.
1362 # At a minimum, this makes migration a _little_ easier (a lot easier in the
1363 # 0.5.0 switch, I hope!)
1365 # Revision 1.46  2002/01/07 10:42:23  richard
1366 # oops
1368 # Revision 1.45  2002/01/02 04:18:17  richard
1369 # hyperdb docstrings
1371 # Revision 1.44  2002/01/02 02:31:38  richard
1372 # Sorry for the huge checkin message - I was only intending to implement #496356
1373 # but I found a number of places where things had been broken by transactions:
1374 #  . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
1375 #    for _all_ roundup-generated smtp messages to be sent to.
1376 #  . the transaction cache had broken the roundupdb.Class set() reactors
1377 #  . newly-created author users in the mailgw weren't being committed to the db
1379 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
1380 # on when I found that stuff :):
1381 #  . #496356 ] Use threading in messages
1382 #  . detectors were being registered multiple times
1383 #  . added tests for mailgw
1384 #  . much better attaching of erroneous messages in the mail gateway
1386 # Revision 1.43  2001/12/20 06:13:24  rochecompaan
1387 # Bugs fixed:
1388 #   . Exception handling in hyperdb for strings-that-look-like numbers got
1389 #     lost somewhere
1390 #   . Internet Explorer submits full path for filename - we now strip away
1391 #     the path
1392 # Features added:
1393 #   . Link and multilink properties are now displayed sorted in the cgi
1394 #     interface
1396 # Revision 1.42  2001/12/16 10:53:37  richard
1397 # take a copy of the node dict so that the subsequent set
1398 # operation doesn't modify the oldvalues structure
1400 # Revision 1.41  2001/12/15 23:47:47  richard
1401 # Cleaned up some bare except statements
1403 # Revision 1.40  2001/12/14 23:42:57  richard
1404 # yuck, a gdbm instance tests false :(
1405 # I've left the debugging code in - it should be removed one day if we're ever
1406 # _really_ anal about performace :)
1408 # Revision 1.39  2001/12/02 05:06:16  richard
1409 # . We now use weakrefs in the Classes to keep the database reference, so
1410 #   the close() method on the database is no longer needed.
1411 #   I bumped the minimum python requirement up to 2.1 accordingly.
1412 # . #487480 ] roundup-server
1413 # . #487476 ] INSTALL.txt
1415 # I also cleaned up the change message / post-edit stuff in the cgi client.
1416 # There's now a clearly marked "TODO: append the change note" where I believe
1417 # the change note should be added there. The "changes" list will obviously
1418 # have to be modified to be a dict of the changes, or somesuch.
1420 # More testing needed.
1422 # Revision 1.38  2001/12/01 07:17:50  richard
1423 # . We now have basic transaction support! Information is only written to
1424 #   the database when the commit() method is called. Only the anydbm
1425 #   backend is modified in this way - neither of the bsddb backends have been.
1426 #   The mail, admin and cgi interfaces all use commit (except the admin tool
1427 #   doesn't have a commit command, so interactive users can't commit...)
1428 # . Fixed login/registration forwarding the user to the right page (or not,
1429 #   on a failure)
1431 # Revision 1.37  2001/11/28 21:55:35  richard
1432 #  . login_action and newuser_action return values were being ignored
1433 #  . Woohoo! Found that bloody re-login bug that was killing the mail
1434 #    gateway.
1435 #  (also a minor cleanup in hyperdb)
1437 # Revision 1.36  2001/11/27 03:16:09  richard
1438 # Another place that wasn't handling missing properties.
1440 # Revision 1.35  2001/11/22 15:46:42  jhermann
1441 # Added module docstrings to all modules.
1443 # Revision 1.34  2001/11/21 04:04:43  richard
1444 # *sigh* more missing value handling
1446 # Revision 1.33  2001/11/21 03:40:54  richard
1447 # more new property handling
1449 # Revision 1.32  2001/11/21 03:11:28  richard
1450 # Better handling of new properties.
1452 # Revision 1.31  2001/11/12 22:01:06  richard
1453 # Fixed issues with nosy reaction and author copies.
1455 # Revision 1.30  2001/11/09 10:11:08  richard
1456 #  . roundup-admin now handles all hyperdb exceptions
1458 # Revision 1.29  2001/10/27 00:17:41  richard
1459 # Made Class.stringFind() do caseless matching.
1461 # Revision 1.28  2001/10/21 04:44:50  richard
1462 # bug #473124: UI inconsistency with Link fields.
1463 #    This also prompted me to fix a fairly long-standing usability issue -
1464 #    that of being able to turn off certain filters.
1466 # Revision 1.27  2001/10/20 23:44:27  richard
1467 # Hyperdatabase sorts strings-that-look-like-numbers as numbers now.
1469 # Revision 1.26  2001/10/16 03:48:01  richard
1470 # admin tool now complains if a "find" is attempted with a non-link property.
1472 # Revision 1.25  2001/10/11 00:17:51  richard
1473 # Reverted a change in hyperdb so the default value for missing property
1474 # values in a create() is None and not '' (the empty string.) This obviously
1475 # breaks CSV import/export - the string 'None' will be created in an
1476 # export/import operation.
1478 # Revision 1.24  2001/10/10 03:54:57  richard
1479 # Added database importing and exporting through CSV files.
1480 # Uses the csv module from object-craft for exporting if it's available.
1481 # Requires the csv module for importing.
1483 # Revision 1.23  2001/10/09 23:58:10  richard
1484 # Moved the data stringification up into the hyperdb.Class class' get, set
1485 # and create methods. This means that the data is also stringified for the
1486 # journal call, and removes duplication of code from the backends. The
1487 # backend code now only sees strings.
1489 # Revision 1.22  2001/10/09 07:25:59  richard
1490 # Added the Password property type. See "pydoc roundup.password" for
1491 # implementation details. Have updated some of the documentation too.
1493 # Revision 1.21  2001/10/05 02:23:24  richard
1494 #  . roundup-admin create now prompts for property info if none is supplied
1495 #    on the command-line.
1496 #  . hyperdb Class getprops() method may now return only the mutable
1497 #    properties.
1498 #  . Login now uses cookies, which makes it a whole lot more flexible. We can
1499 #    now support anonymous user access (read-only, unless there's an
1500 #    "anonymous" user, in which case write access is permitted). Login
1501 #    handling has been moved into cgi_client.Client.main()
1502 #  . The "extended" schema is now the default in roundup init.
1503 #  . The schemas have had their page headings modified to cope with the new
1504 #    login handling. Existing installations should copy the interfaces.py
1505 #    file from the roundup lib directory to their instance home.
1506 #  . Incorrectly had a Bizar Software copyright on the cgitb.py module from
1507 #    Ping - has been removed.
1508 #  . Fixed a whole bunch of places in the CGI interface where we should have
1509 #    been returning Not Found instead of throwing an exception.
1510 #  . Fixed a deviation from the spec: trying to modify the 'id' property of
1511 #    an item now throws an exception.
1513 # Revision 1.20  2001/10/04 02:12:42  richard
1514 # Added nicer command-line item adding: passing no arguments will enter an
1515 # interactive more which asks for each property in turn. While I was at it, I
1516 # fixed an implementation problem WRT the spec - I wasn't raising a
1517 # ValueError if the key property was missing from a create(). Also added a
1518 # protected=boolean argument to getprops() so we can list only the mutable
1519 # properties (defaults to yes, which lists the immutables).
1521 # Revision 1.19  2001/08/29 04:47:18  richard
1522 # Fixed CGI client change messages so they actually include the properties
1523 # changed (again).
1525 # Revision 1.18  2001/08/16 07:34:59  richard
1526 # better CGI text searching - but hidden filter fields are disappearing...
1528 # Revision 1.17  2001/08/16 06:59:58  richard
1529 # all searches use re now - and they're all case insensitive
1531 # Revision 1.16  2001/08/15 23:43:18  richard
1532 # Fixed some isFooTypes that I missed.
1533 # Refactored some code in the CGI code.
1535 # Revision 1.15  2001/08/12 06:32:36  richard
1536 # using isinstance(blah, Foo) now instead of isFooType
1538 # Revision 1.14  2001/08/07 00:24:42  richard
1539 # stupid typo
1541 # Revision 1.13  2001/08/07 00:15:51  richard
1542 # Added the copyright/license notice to (nearly) all files at request of
1543 # Bizar Software.
1545 # Revision 1.12  2001/08/02 06:38:17  richard
1546 # Roundupdb now appends "mailing list" information to its messages which
1547 # include the e-mail address and web interface address. Templates may
1548 # override this in their db classes to include specific information (support
1549 # instructions, etc).
1551 # Revision 1.11  2001/08/01 04:24:21  richard
1552 # mailgw was assuming certain properties existed on the issues being created.
1554 # Revision 1.10  2001/07/30 02:38:31  richard
1555 # get() now has a default arg - for migration only.
1557 # Revision 1.9  2001/07/29 09:28:23  richard
1558 # Fixed sorting by clicking on column headings.
1560 # Revision 1.8  2001/07/29 08:27:40  richard
1561 # Fixed handling of passed-in values in form elements (ie. during a
1562 # drill-down)
1564 # Revision 1.7  2001/07/29 07:01:39  richard
1565 # Added vim command to all source so that we don't get no steenkin' tabs :)
1567 # Revision 1.6  2001/07/29 05:36:14  richard
1568 # Cleanup of the link label generation.
1570 # Revision 1.5  2001/07/29 04:05:37  richard
1571 # Added the fabricated property "id".
1573 # Revision 1.4  2001/07/27 06:25:35  richard
1574 # Fixed some of the exceptions so they're the right type.
1575 # Removed the str()-ification of node ids so we don't mask oopsy errors any
1576 # more.
1578 # Revision 1.3  2001/07/27 05:17:14  richard
1579 # just some comments
1581 # Revision 1.2  2001/07/22 12:09:32  richard
1582 # Final commit of Grande Splite
1584 # Revision 1.1  2001/07/22 11:58:35  richard
1585 # More Grande Splite
1588 # vim: set filetype=python ts=4 sw=4 et si