8bfc257bf5b4d9ba45da835e8e576b3ffe320c9d
1 # $Id: back_gadfly.py,v 1.9 2002-09-03 05:46:21 richard Exp $
2 __doc__ = '''
3 About Gadfly
4 ============
6 Gadfly is a collection of python modules that provides relational
7 database functionality entirely implemented in Python. It supports a
8 subset of the intergalactic standard RDBMS Structured Query Language
9 SQL.
12 Basic Structure
13 ===============
15 We map roundup classes to relational tables. Automatically detect schema
16 changes and modify the gadfly table schemas appropriately. Multilinks
17 (which represent a many-to-many relationship) are handled through
18 intermediate tables.
20 Journals are stored adjunct to the per-class tables.
22 Table names and columns have "_" prepended so the names can't
23 clash with restricted names (like "order"). Retirement is determined by the
24 __retired__ column being true.
26 All columns are defined as VARCHAR, since it really doesn't matter what
27 type they're defined as. We stuff all kinds of data in there ;) [as long as
28 it's marshallable, gadfly doesn't care]
31 Additional Instance Requirements
32 ================================
34 The instance configuration must specify where the database is. It does this
35 with GADFLY_DATABASE, which is used as the arguments to the gadfly.gadfly()
36 method:
38 Using an on-disk database directly (not a good idea):
39 GADFLY_DATABASE = (database name, directory)
41 Using a network database (much better idea):
42 GADFLY_DATABASE = (policy, password, address, port)
44 Because multiple accesses directly to a gadfly database aren't handled, but
45 multiple network accesses are, it's strongly advised that the latter setup be
46 used.
48 '''
50 # standard python modules
51 import sys, os, time, re, errno, weakref, copy
53 # roundup modules
54 from roundup import hyperdb, date, password, roundupdb, security
55 from roundup.hyperdb import String, Password, Date, Interval, Link, \
56 Multilink, DatabaseError, Boolean, Number
58 # the all-important gadfly :)
59 import gadfly
60 import gadfly.client
61 import gadfly.database
63 # support
64 from blobfiles import FileStorage
65 from roundup.indexer import Indexer
66 from sessions import Sessions
68 class Database(FileStorage, hyperdb.Database, roundupdb.Database):
69 # flag to set on retired entries
70 RETIRED_FLAG = '__hyperdb_retired'
72 def __init__(self, config, journaltag=None):
73 ''' Open the database and load the schema from it.
74 '''
75 self.config, self.journaltag = config, journaltag
76 self.dir = config.DATABASE
77 self.classes = {}
78 self.indexer = Indexer(self.dir)
79 self.sessions = Sessions(self.config)
80 self.security = security.Security(self)
82 # additional transaction support for external files and the like
83 self.transactions = []
85 db = config.GADFLY_DATABASE
86 if len(db) == 2:
87 # ensure files are group readable and writable
88 os.umask(0002)
89 try:
90 self.conn = gadfly.gadfly(*db)
91 except IOError, error:
92 if error.errno != errno.ENOENT:
93 raise
94 self.database_schema = {}
95 self.conn = gadfly.gadfly()
96 self.conn.startup(*db)
97 cursor = self.conn.cursor()
98 cursor.execute('create table schema (schema varchar)')
99 cursor.execute('create table ids (name varchar, num integer)')
100 else:
101 cursor = self.conn.cursor()
102 cursor.execute('select schema from schema')
103 self.database_schema = cursor.fetchone()[0]
104 else:
105 self.conn = gadfly.client.gfclient(*db)
106 cursor = self.conn.cursor()
107 cursor.execute('select schema from schema')
108 self.database_schema = cursor.fetchone()[0]
110 def __repr__(self):
111 return '<radfly 0x%x>'%id(self)
113 def post_init(self):
114 ''' Called once the schema initialisation has finished.
116 We should now confirm that the schema defined by our "classes"
117 attribute actually matches the schema in the database.
118 '''
119 # now detect changes in the schema
120 for classname, spec in self.classes.items():
121 if self.database_schema.has_key(classname):
122 dbspec = self.database_schema[classname]
123 self.update_class(spec, dbspec)
124 self.database_schema[classname] = spec.schema()
125 else:
126 self.create_class(spec)
127 self.database_schema[classname] = spec.schema()
129 for classname in self.database_schema.keys():
130 if not self.classes.has_key(classname):
131 self.drop_class(classname)
133 # update the database version of the schema
134 cursor = self.conn.cursor()
135 cursor.execute('delete from schema')
136 cursor.execute('insert into schema values (?)', (self.database_schema,))
138 # reindex the db if necessary
139 if self.indexer.should_reindex():
140 self.reindex()
142 # commit
143 self.conn.commit()
145 def reindex(self):
146 for klass in self.classes.values():
147 for nodeid in klass.list():
148 klass.index(nodeid)
149 self.indexer.save_index()
151 def determine_columns(self, spec):
152 ''' Figure the column names and multilink properties from the spec
153 '''
154 cols = []
155 mls = []
156 # add the multilinks separately
157 for col, prop in spec.properties.items():
158 if isinstance(prop, Multilink):
159 mls.append(col)
160 else:
161 cols.append('_'+col)
162 cols.sort()
163 return cols, mls
165 def update_class(self, spec, dbspec):
166 ''' Determine the differences between the current spec and the
167 database version of the spec, and update where necessary
169 NOTE that this doesn't work for adding/deleting properties!
170 ... until gadfly grows an ALTER TABLE command, it's not going to!
171 '''
172 spec_schema = spec.schema()
173 if spec_schema == dbspec:
174 return
175 if __debug__:
176 print >>hyperdb.DEBUG, 'update_class FIRING'
178 # key property changed?
179 if dbspec[0] != spec_schema[0]:
180 if __debug__:
181 print >>hyperdb.DEBUG, 'update_class setting keyprop', `spec[0]`
182 # XXX turn on indexing for the key property
184 # dict 'em up
185 spec_propnames,spec_props = [],{}
186 for propname,prop in spec_schema[1]:
187 spec_propnames.append(propname)
188 spec_props[propname] = prop
189 dbspec_propnames,dbspec_props = [],{}
190 for propname,prop in dbspec[1]:
191 dbspec_propnames.append(propname)
192 dbspec_props[propname] = prop
194 # we're going to need one of these
195 cursor = self.conn.cursor()
197 # now compare
198 for propname in spec_propnames:
199 prop = spec_props[propname]
200 if __debug__:
201 print >>hyperdb.DEBUG, 'update_class ...', `prop`
202 if dbspec_props.has_key(propname) and prop==dbspec_props[propname]:
203 continue
204 if __debug__:
205 print >>hyperdb.DEBUG, 'update_class', `prop`
207 if not dbspec_props.has_key(propname):
208 # add the property
209 if isinstance(prop, Multilink):
210 sql = 'create table %s_%s (linkid varchar, nodeid '\
211 'varchar)'%(spec.classname, prop)
212 if __debug__:
213 print >>hyperdb.DEBUG, 'update_class', (self, sql)
214 cursor.execute(sql)
215 else:
216 # XXX gadfly doesn't have an ALTER TABLE command
217 raise NotImplementedError
218 sql = 'alter table _%s add column (_%s varchar)'%(
219 spec.classname, propname)
220 if __debug__:
221 print >>hyperdb.DEBUG, 'update_class', (self, sql)
222 cursor.execute(sql)
223 else:
224 # modify the property
225 if __debug__:
226 print >>hyperdb.DEBUG, 'update_class NOOP'
227 pass # NOOP in gadfly
229 # and the other way - only worry about deletions here
230 for propname in dbspec_propnames:
231 prop = dbspec_props[propname]
232 if spec_props.has_key(propname):
233 continue
234 if __debug__:
235 print >>hyperdb.DEBUG, 'update_class', `prop`
237 # delete the property
238 if isinstance(prop, Multilink):
239 sql = 'drop table %s_%s'%(spec.classname, prop)
240 if __debug__:
241 print >>hyperdb.DEBUG, 'update_class', (self, sql)
242 cursor.execute(sql)
243 else:
244 # XXX gadfly doesn't have an ALTER TABLE command
245 raise NotImplementedError
246 sql = 'alter table _%s delete column _%s'%(spec.classname,
247 propname)
248 if __debug__:
249 print >>hyperdb.DEBUG, 'update_class', (self, sql)
250 cursor.execute(sql)
252 def create_class(self, spec):
253 ''' Create a database table according to the given spec.
254 '''
255 cols, mls = self.determine_columns(spec)
257 # add on our special columns
258 cols.append('id')
259 cols.append('__retired__')
261 cursor = self.conn.cursor()
263 # create the base table
264 cols = ','.join(['%s varchar'%x for x in cols])
265 sql = 'create table _%s (%s)'%(spec.classname, cols)
266 if __debug__:
267 print >>hyperdb.DEBUG, 'create_class', (self, sql)
268 cursor.execute(sql)
270 # journal table
271 cols = ','.join(['%s varchar'%x
272 for x in 'nodeid date tag action params'.split()])
273 sql = 'create table %s__journal (%s)'%(spec.classname, cols)
274 if __debug__:
275 print >>hyperdb.DEBUG, 'create_class', (self, sql)
276 cursor.execute(sql)
278 # now create the multilink tables
279 for ml in mls:
280 sql = 'create table %s_%s (linkid varchar, nodeid varchar)'%(
281 spec.classname, ml)
282 if __debug__:
283 print >>hyperdb.DEBUG, 'create_class', (self, sql)
284 cursor.execute(sql)
286 # ID counter
287 sql = 'insert into ids (name, num) values (?,?)'
288 vals = (spec.classname, 1)
289 if __debug__:
290 print >>hyperdb.DEBUG, 'create_class', (self, sql, vals)
291 cursor.execute(sql, vals)
293 def drop_class(self, spec):
294 ''' Drop the given table from the database.
296 Drop the journal and multilink tables too.
297 '''
298 # figure the multilinks
299 mls = []
300 for col, prop in spec.properties.items():
301 if isinstance(prop, Multilink):
302 mls.append(col)
303 cursor = self.conn.cursor()
305 sql = 'drop table _%s'%spec.classname
306 if __debug__:
307 print >>hyperdb.DEBUG, 'drop_class', (self, sql)
308 cursor.execute(sql)
310 sql = 'drop table %s__journal'%spec.classname
311 if __debug__:
312 print >>hyperdb.DEBUG, 'drop_class', (self, sql)
313 cursor.execute(sql)
315 for ml in mls:
316 sql = 'drop table %s_%s'%(spec.classname, ml)
317 if __debug__:
318 print >>hyperdb.DEBUG, 'drop_class', (self, sql)
319 cursor.execute(sql)
321 #
322 # Classes
323 #
324 def __getattr__(self, classname):
325 ''' A convenient way of calling self.getclass(classname).
326 '''
327 if self.classes.has_key(classname):
328 if __debug__:
329 print >>hyperdb.DEBUG, '__getattr__', (self, classname)
330 return self.classes[classname]
331 raise AttributeError, classname
333 def addclass(self, cl):
334 ''' Add a Class to the hyperdatabase.
335 '''
336 if __debug__:
337 print >>hyperdb.DEBUG, 'addclass', (self, cl)
338 cn = cl.classname
339 if self.classes.has_key(cn):
340 raise ValueError, cn
341 self.classes[cn] = cl
343 def getclasses(self):
344 ''' Return a list of the names of all existing classes.
345 '''
346 if __debug__:
347 print >>hyperdb.DEBUG, 'getclasses', (self,)
348 l = self.classes.keys()
349 l.sort()
350 return l
352 def getclass(self, classname):
353 '''Get the Class object representing a particular class.
355 If 'classname' is not a valid class name, a KeyError is raised.
356 '''
357 if __debug__:
358 print >>hyperdb.DEBUG, 'getclass', (self, classname)
359 return self.classes[classname]
361 def clear(self):
362 ''' Delete all database contents.
364 Note: I don't commit here, which is different behaviour to the
365 "nuke from orbit" behaviour in the *dbms.
366 '''
367 if __debug__:
368 print >>hyperdb.DEBUG, 'clear', (self,)
369 cursor = self.conn.cursor()
370 for cn in self.classes.keys():
371 sql = 'delete from _%s'%cn
372 if __debug__:
373 print >>hyperdb.DEBUG, 'clear', (self, sql)
374 cursor.execute(sql)
376 #
377 # Node IDs
378 #
379 def newid(self, classname):
380 ''' Generate a new id for the given class
381 '''
382 # get the next ID
383 cursor = self.conn.cursor()
384 sql = 'select num from ids where name=?'
385 if __debug__:
386 print >>hyperdb.DEBUG, 'newid', (self, sql, classname)
387 cursor.execute(sql, (classname, ))
388 newid = cursor.fetchone()[0]
390 # update the counter
391 sql = 'update ids set num=? where name=?'
392 vals = (newid+1, classname)
393 if __debug__:
394 print >>hyperdb.DEBUG, 'newid', (self, sql, vals)
395 cursor.execute(sql, vals)
397 # return as string
398 return str(newid)
400 def setid(self, classname, setid):
401 ''' Set the id counter: used during import of database
402 '''
403 cursor = self.conn.cursor()
404 sql = 'update ids set num=? where name=?'
405 vals = (setid, spec.classname)
406 if __debug__:
407 print >>hyperdb.DEBUG, 'setid', (self, sql, vals)
408 cursor.execute(sql, vals)
410 #
411 # Nodes
412 #
414 def addnode(self, classname, nodeid, node):
415 ''' Add the specified node to its class's db.
416 '''
417 if __debug__:
418 print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node)
419 # gadfly requires values for all non-multilink columns
420 cl = self.classes[classname]
421 cols, mls = self.determine_columns(cl)
423 # default the non-multilink columns
424 for col, prop in cl.properties.items():
425 if not isinstance(col, Multilink):
426 if not node.has_key(col):
427 node[col] = None
429 node = self.serialise(classname, node)
431 # make sure the ordering is correct for column name -> column value
432 vals = tuple([node[col[1:]] for col in cols]) + (nodeid, 0)
433 s = ','.join(['?' for x in cols]) + ',?,?'
434 cols = ','.join(cols) + ',id,__retired__'
436 # perform the inserts
437 cursor = self.conn.cursor()
438 sql = 'insert into _%s (%s) values (%s)'%(classname, cols, s)
439 if __debug__:
440 print >>hyperdb.DEBUG, 'addnode', (self, sql, vals)
441 cursor.execute(sql, vals)
443 # insert the multilink rows
444 for col in mls:
445 t = '%s_%s'%(classname, col)
446 for entry in node[col]:
447 sql = 'insert into %s (linkid, nodeid) values (?,?)'%t
448 vals = (entry, nodeid)
449 if __debug__:
450 print >>hyperdb.DEBUG, 'addnode', (self, sql, vals)
451 cursor.execute(sql, vals)
453 # make sure we do the commit-time extra stuff for this node
454 self.transactions.append((self.doSaveNode, (classname, nodeid, node)))
456 def setnode(self, classname, nodeid, node, multilink_changes):
457 ''' Change the specified node.
458 '''
459 if __debug__:
460 print >>hyperdb.DEBUG, 'setnode', (self, classname, nodeid, node)
461 node = self.serialise(classname, node)
463 cl = self.classes[classname]
464 cols = []
465 mls = []
466 # add the multilinks separately
467 for col in node.keys():
468 prop = cl.properties[col]
469 if isinstance(prop, Multilink):
470 mls.append(col)
471 else:
472 cols.append('_'+col)
473 cols.sort()
475 # make sure the ordering is correct for column name -> column value
476 vals = tuple([node[col[1:]] for col in cols])
477 s = ','.join(['%s=?'%x for x in cols])
478 cols = ','.join(cols)
480 # perform the update
481 cursor = self.conn.cursor()
482 sql = 'update _%s set %s'%(classname, s)
483 if __debug__:
484 print >>hyperdb.DEBUG, 'setnode', (self, sql, vals)
485 cursor.execute(sql, vals)
487 # now the fun bit, updating the multilinks ;)
488 for col, (add, remove) in multilink_changes.items():
489 tn = '%s_%s'%(classname, col)
490 if add:
491 sql = 'insert into %s (nodeid, linkid) values (?,?)'%tn
492 vals = [(nodeid, addid) for addid in add]
493 if __debug__:
494 print >>hyperdb.DEBUG, 'setnode (add)', (self, sql, vals)
495 cursor.execute(sql, vals)
496 if remove:
497 sql = 'delete from %s where nodeid=? and linkid=?'%tn
498 vals = [(nodeid, removeid) for removeid in remove]
499 if __debug__:
500 print >>hyperdb.DEBUG, 'setnode (rem)', (self, sql, vals)
501 cursor.execute(sql, vals)
503 # make sure we do the commit-time extra stuff for this node
504 self.transactions.append((self.doSaveNode, (classname, nodeid, node)))
506 def getnode(self, classname, nodeid):
507 ''' Get a node from the database.
508 '''
509 if __debug__:
510 print >>hyperdb.DEBUG, 'getnode', (self, classname, nodeid)
511 # figure the columns we're fetching
512 cl = self.classes[classname]
513 cols, mls = self.determine_columns(cl)
514 scols = ','.join(cols)
516 # perform the basic property fetch
517 cursor = self.conn.cursor()
518 sql = 'select %s from _%s where id=?'%(scols, classname)
519 if __debug__:
520 print >>hyperdb.DEBUG, 'getnode', (self, sql, nodeid)
521 cursor.execute(sql, (nodeid,))
522 try:
523 values = cursor.fetchone()
524 except gadfly.database.error, message:
525 if message == 'no more results':
526 raise IndexError, 'no such %s node %s'%(classname, nodeid)
527 raise
529 # make up the node
530 node = {}
531 for col in range(len(cols)):
532 node[cols[col][1:]] = values[col]
534 # now the multilinks
535 for col in mls:
536 # get the link ids
537 sql = 'select linkid from %s_%s where nodeid=?'%(classname, col)
538 if __debug__:
539 print >>hyperdb.DEBUG, 'getnode', (self, sql, nodeid)
540 cursor.execute(sql, (nodeid,))
541 # extract the first column from the result
542 node[col] = [x[0] for x in cursor.fetchall()]
544 return self.unserialise(classname, node)
546 def destroynode(self, classname, nodeid):
547 '''Remove a node from the database. Called exclusively by the
548 destroy() method on Class.
549 '''
550 if __debug__:
551 print >>hyperdb.DEBUG, 'destroynode', (self, classname, nodeid)
553 # make sure the node exists
554 if not self.hasnode(classname, nodeid):
555 raise IndexError, '%s has no node %s'%(classname, nodeid)
557 # see if there's any obvious commit actions that we should get rid of
558 for entry in self.transactions[:]:
559 if entry[1][:2] == (classname, nodeid):
560 self.transactions.remove(entry)
562 # now do the SQL
563 cursor = self.conn.cursor()
564 sql = 'delete from _%s where id=?'%(classname)
565 if __debug__:
566 print >>hyperdb.DEBUG, 'destroynode', (self, sql, nodeid)
567 cursor.execute(sql, (nodeid,))
569 def serialise(self, classname, node):
570 '''Copy the node contents, converting non-marshallable data into
571 marshallable data.
572 '''
573 if __debug__:
574 print >>hyperdb.DEBUG, 'serialise', classname, node
575 properties = self.getclass(classname).getprops()
576 d = {}
577 for k, v in node.items():
578 # if the property doesn't exist, or is the "retired" flag then
579 # it won't be in the properties dict
580 if not properties.has_key(k):
581 d[k] = v
582 continue
584 # get the property spec
585 prop = properties[k]
587 if isinstance(prop, Password):
588 d[k] = str(v)
589 elif isinstance(prop, Date) and v is not None:
590 d[k] = v.serialise()
591 elif isinstance(prop, Interval) and v is not None:
592 d[k] = v.serialise()
593 else:
594 d[k] = v
595 return d
597 def unserialise(self, classname, node):
598 '''Decode the marshalled node data
599 '''
600 if __debug__:
601 print >>hyperdb.DEBUG, 'unserialise', classname, node
602 properties = self.getclass(classname).getprops()
603 d = {}
604 for k, v in node.items():
605 # if the property doesn't exist, or is the "retired" flag then
606 # it won't be in the properties dict
607 if not properties.has_key(k):
608 d[k] = v
609 continue
611 # get the property spec
612 prop = properties[k]
614 if isinstance(prop, Date) and v is not None:
615 d[k] = date.Date(v)
616 elif isinstance(prop, Interval) and v is not None:
617 d[k] = date.Interval(v)
618 elif isinstance(prop, Password):
619 p = password.Password()
620 p.unpack(v)
621 d[k] = p
622 else:
623 d[k] = v
624 return d
626 def hasnode(self, classname, nodeid):
627 ''' Determine if the database has a given node.
628 '''
629 cursor = self.conn.cursor()
630 sql = 'select count(*) from _%s where id=?'%classname
631 if __debug__:
632 print >>hyperdb.DEBUG, 'hasnode', (self, sql, nodeid)
633 cursor.execute(sql, (nodeid,))
634 return cursor.fetchone()[0]
636 def countnodes(self, classname):
637 ''' Count the number of nodes that exist for a particular Class.
638 '''
639 cursor = self.conn.cursor()
640 sql = 'select count(*) from _%s'%classname
641 if __debug__:
642 print >>hyperdb.DEBUG, 'countnodes', (self, sql)
643 cursor.execute(sql)
644 return cursor.fetchone()[0]
646 def getnodeids(self, classname, retired=0):
647 ''' Retrieve all the ids of the nodes for a particular Class.
649 Set retired=None to get all nodes. Otherwise it'll get all the
650 retired or non-retired nodes, depending on the flag.
651 '''
652 cursor = self.conn.cursor()
653 # flip the sense of the flag if we don't want all of them
654 if retired is not None:
655 retired = not retired
656 sql = 'select id from _%s where __retired__ <> ?'%classname
657 if __debug__:
658 print >>hyperdb.DEBUG, 'getnodeids', (self, sql, retired)
659 cursor.execute(sql, (retired,))
660 return [x[0] for x in cursor.fetchall()]
662 def addjournal(self, classname, nodeid, action, params):
663 ''' Journal the Action
664 'action' may be:
666 'create' or 'set' -- 'params' is a dictionary of property values
667 'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
668 'retire' -- 'params' is None
669 '''
670 if isinstance(params, type({})):
671 if params.has_key('creator'):
672 journaltag = self.user.get(params['creator'], 'username')
673 del params['creator']
674 else:
675 journaltag = self.journaltag
676 if params.has_key('created'):
677 journaldate = params['created'].serialise()
678 del params['created']
679 else:
680 journaldate = date.Date().serialise()
681 if params.has_key('activity'):
682 del params['activity']
684 # serialise the parameters now
685 if action in ('set', 'create'):
686 params = self.serialise(classname, params)
687 else:
688 journaltag = self.journaltag
689 journaldate = date.Date().serialise()
691 # create the journal entry
692 cols = ','.join('nodeid date tag action params'.split())
693 entry = (nodeid, journaldate, journaltag, action, params)
695 if __debug__:
696 print >>hyperdb.DEBUG, 'doSaveJournal', entry
698 # do the insert
699 cursor = self.conn.cursor()
700 sql = 'insert into %s__journal (%s) values (?,?,?,?,?)'%(classname,
701 cols)
702 if __debug__:
703 print >>hyperdb.DEBUG, 'addjournal', (self, sql, entry)
704 cursor.execute(sql, entry)
706 def getjournal(self, classname, nodeid):
707 ''' get the journal for id
708 '''
709 # make sure the node exists
710 if not self.hasnode(classname, nodeid):
711 raise IndexError, '%s has no node %s'%(classname, nodeid)
713 # now get the journal entries
714 cols = ','.join('nodeid date tag action params'.split())
715 cursor = self.conn.cursor()
716 sql = 'select %s from %s__journal where nodeid=?'%(cols, classname)
717 if __debug__:
718 print >>hyperdb.DEBUG, 'getjournal', (self, sql, nodeid)
719 cursor.execute(sql, (nodeid,))
720 res = []
721 for nodeid, date_stamp, user, action, params in cursor.fetchall():
722 res.append((nodeid, date.Date(date_stamp), user, action, params))
723 return res
725 def pack(self, pack_before):
726 ''' Delete all journal entries except "create" before 'pack_before'.
727 '''
728 # get a 'yyyymmddhhmmss' version of the date
729 date_stamp = pack_before.serialise()
731 # do the delete
732 cursor = self.conn.cursor()
733 for classname in self.classes.keys():
734 sql = "delete from %s__journal where date<? and "\
735 "action<>'create'"%classname
736 if __debug__:
737 print >>hyperdb.DEBUG, 'pack', (self, sql, date_stamp)
738 cursor.execute(sql, (date_stamp,))
740 def commit(self):
741 ''' Commit the current transactions.
743 Save all data changed since the database was opened or since the
744 last commit() or rollback().
745 '''
746 if __debug__:
747 print >>hyperdb.DEBUG, 'commit', (self,)
749 # commit gadfly
750 self.conn.commit()
752 # now, do all the other transaction stuff
753 reindex = {}
754 for method, args in self.transactions:
755 reindex[method(*args)] = 1
757 # reindex the nodes that request it
758 for classname, nodeid in filter(None, reindex.keys()):
759 print >>hyperdb.DEBUG, 'commit.reindex', (classname, nodeid)
760 self.getclass(classname).index(nodeid)
762 # save the indexer state
763 self.indexer.save_index()
765 # clear out the transactions
766 self.transactions = []
768 def rollback(self):
769 ''' Reverse all actions from the current transaction.
771 Undo all the changes made since the database was opened or the last
772 commit() or rollback() was performed.
773 '''
774 if __debug__:
775 print >>hyperdb.DEBUG, 'rollback', (self,)
777 # roll back gadfly
778 self.conn.rollback()
780 # roll back "other" transaction stuff
781 for method, args in self.transactions:
782 # delete temporary files
783 if method == self.doStoreFile:
784 self.rollbackStoreFile(*args)
785 self.transactions = []
787 def doSaveNode(self, classname, nodeid, node):
788 ''' dummy that just generates a reindex event
789 '''
790 # return the classname, nodeid so we reindex this content
791 return (classname, nodeid)
793 #
794 # The base Class class
795 #
796 class Class(hyperdb.Class):
797 ''' The handle to a particular class of nodes in a hyperdatabase.
799 All methods except __repr__ and getnode must be implemented by a
800 concrete backend Class.
801 '''
803 def __init__(self, db, classname, **properties):
804 '''Create a new class with a given name and property specification.
806 'classname' must not collide with the name of an existing class,
807 or a ValueError is raised. The keyword arguments in 'properties'
808 must map names to property objects, or a TypeError is raised.
809 '''
810 if (properties.has_key('creation') or properties.has_key('activity')
811 or properties.has_key('creator')):
812 raise ValueError, '"creation", "activity" and "creator" are '\
813 'reserved'
815 self.classname = classname
816 self.properties = properties
817 self.db = weakref.proxy(db) # use a weak ref to avoid circularity
818 self.key = ''
820 # should we journal changes (default yes)
821 self.do_journal = 1
823 # do the db-related init stuff
824 db.addclass(self)
826 self.auditors = {'create': [], 'set': [], 'retire': []}
827 self.reactors = {'create': [], 'set': [], 'retire': []}
829 def schema(self):
830 ''' A dumpable version of the schema that we can store in the
831 database
832 '''
833 return (self.key, [(x, repr(y)) for x,y in self.properties.items()])
835 def enableJournalling(self):
836 '''Turn journalling on for this class
837 '''
838 self.do_journal = 1
840 def disableJournalling(self):
841 '''Turn journalling off for this class
842 '''
843 self.do_journal = 0
845 # Editing nodes:
846 def create(self, **propvalues):
847 ''' Create a new node of this class and return its id.
849 The keyword arguments in 'propvalues' map property names to values.
851 The values of arguments must be acceptable for the types of their
852 corresponding properties or a TypeError is raised.
854 If this class has a key property, it must be present and its value
855 must not collide with other key strings or a ValueError is raised.
857 Any other properties on this class that are missing from the
858 'propvalues' dictionary are set to None.
860 If an id in a link or multilink property does not refer to a valid
861 node, an IndexError is raised.
862 '''
863 if propvalues.has_key('id'):
864 raise KeyError, '"id" is reserved'
866 if self.db.journaltag is None:
867 raise DatabaseError, 'Database open read-only'
869 if propvalues.has_key('creation') or propvalues.has_key('activity'):
870 raise KeyError, '"creation" and "activity" are reserved'
872 self.fireAuditors('create', None, propvalues)
874 # new node's id
875 newid = self.db.newid(self.classname)
877 # validate propvalues
878 num_re = re.compile('^\d+$')
879 for key, value in propvalues.items():
880 if key == self.key:
881 try:
882 self.lookup(value)
883 except KeyError:
884 pass
885 else:
886 raise ValueError, 'node with key "%s" exists'%value
888 # try to handle this property
889 try:
890 prop = self.properties[key]
891 except KeyError:
892 raise KeyError, '"%s" has no property "%s"'%(self.classname,
893 key)
895 if value is not None and isinstance(prop, Link):
896 if type(value) != type(''):
897 raise ValueError, 'link value must be String'
898 link_class = self.properties[key].classname
899 # if it isn't a number, it's a key
900 if not num_re.match(value):
901 try:
902 value = self.db.classes[link_class].lookup(value)
903 except (TypeError, KeyError):
904 raise IndexError, 'new property "%s": %s not a %s'%(
905 key, value, link_class)
906 elif not self.db.getclass(link_class).hasnode(value):
907 raise IndexError, '%s has no node %s'%(link_class, value)
909 # save off the value
910 propvalues[key] = value
912 # register the link with the newly linked node
913 if self.do_journal and self.properties[key].do_journal:
914 self.db.addjournal(link_class, value, 'link',
915 (self.classname, newid, key))
917 elif isinstance(prop, Multilink):
918 if type(value) != type([]):
919 raise TypeError, 'new property "%s" not a list of ids'%key
921 # clean up and validate the list of links
922 link_class = self.properties[key].classname
923 l = []
924 for entry in value:
925 if type(entry) != type(''):
926 raise ValueError, '"%s" link value (%s) must be '\
927 'String'%(key, value)
928 # if it isn't a number, it's a key
929 if not num_re.match(entry):
930 try:
931 entry = self.db.classes[link_class].lookup(entry)
932 except (TypeError, KeyError):
933 raise IndexError, 'new property "%s": %s not a %s'%(
934 key, entry, self.properties[key].classname)
935 l.append(entry)
936 value = l
937 propvalues[key] = value
939 # handle additions
940 for nodeid in value:
941 if not self.db.getclass(link_class).hasnode(nodeid):
942 raise IndexError, '%s has no node %s'%(link_class,
943 nodeid)
944 # register the link with the newly linked node
945 if self.do_journal and self.properties[key].do_journal:
946 self.db.addjournal(link_class, nodeid, 'link',
947 (self.classname, newid, key))
949 elif isinstance(prop, String):
950 if type(value) != type(''):
951 raise TypeError, 'new property "%s" not a string'%key
953 elif isinstance(prop, Password):
954 if not isinstance(value, password.Password):
955 raise TypeError, 'new property "%s" not a Password'%key
957 elif isinstance(prop, Date):
958 if value is not None and not isinstance(value, date.Date):
959 raise TypeError, 'new property "%s" not a Date'%key
961 elif isinstance(prop, Interval):
962 if value is not None and not isinstance(value, date.Interval):
963 raise TypeError, 'new property "%s" not an Interval'%key
965 elif value is not None and isinstance(prop, Number):
966 try:
967 float(value)
968 except ValueError:
969 raise TypeError, 'new property "%s" not numeric'%key
971 elif value is not None and isinstance(prop, Boolean):
972 try:
973 int(value)
974 except ValueError:
975 raise TypeError, 'new property "%s" not boolean'%key
977 # make sure there's data where there needs to be
978 for key, prop in self.properties.items():
979 if propvalues.has_key(key):
980 continue
981 if key == self.key:
982 raise ValueError, 'key property "%s" is required'%key
983 if isinstance(prop, Multilink):
984 propvalues[key] = []
985 else:
986 propvalues[key] = None
988 # done
989 self.db.addnode(self.classname, newid, propvalues)
990 if self.do_journal:
991 self.db.addjournal(self.classname, newid, 'create', propvalues)
993 self.fireReactors('create', newid, None)
995 return newid
997 _marker = []
998 def get(self, nodeid, propname, default=_marker, cache=1):
999 '''Get the value of a property on an existing node of this class.
1001 'nodeid' must be the id of an existing node of this class or an
1002 IndexError is raised. 'propname' must be the name of a property
1003 of this class or a KeyError is raised.
1005 'cache' indicates whether the transaction cache should be queried
1006 for the node. If the node has been modified and you need to
1007 determine what its values prior to modification are, you need to
1008 set cache=0.
1009 '''
1010 if propname == 'id':
1011 return nodeid
1013 if propname == 'creation':
1014 if not self.do_journal:
1015 raise ValueError, 'Journalling is disabled for this class'
1016 journal = self.db.getjournal(self.classname, nodeid)
1017 if journal:
1018 return self.db.getjournal(self.classname, nodeid)[0][1]
1019 else:
1020 # on the strange chance that there's no journal
1021 return date.Date()
1022 if propname == 'activity':
1023 if not self.do_journal:
1024 raise ValueError, 'Journalling is disabled for this class'
1025 journal = self.db.getjournal(self.classname, nodeid)
1026 if journal:
1027 return self.db.getjournal(self.classname, nodeid)[-1][1]
1028 else:
1029 # on the strange chance that there's no journal
1030 return date.Date()
1031 if propname == 'creator':
1032 if not self.do_journal:
1033 raise ValueError, 'Journalling is disabled for this class'
1034 journal = self.db.getjournal(self.classname, nodeid)
1035 if journal:
1036 name = self.db.getjournal(self.classname, nodeid)[0][2]
1037 else:
1038 return None
1039 try:
1040 return self.db.user.lookup(name)
1041 except KeyError:
1042 # the journaltag user doesn't exist any more
1044 # get the property (raises KeyErorr if invalid)
1045 prop = self.properties[propname]
1047 # get the node's dict
1048 d = self.db.getnode(self.classname, nodeid) #, cache=cache)
1050 if not d.has_key(propname):
1051 if default is self._marker:
1052 if isinstance(prop, Multilink):
1053 return []
1054 else:
1055 return None
1056 else:
1057 return default
1059 # don't pass our list to other code
1060 if isinstance(prop, Multilink):
1061 return d[propname][:]
1063 return d[propname]
1065 def getnode(self, nodeid, cache=1):
1066 ''' Return a convenience wrapper for the node.
1068 'nodeid' must be the id of an existing node of this class or an
1069 IndexError is raised.
1071 'cache' indicates whether the transaction cache should be queried
1072 for the node. If the node has been modified and you need to
1073 determine what its values prior to modification are, you need to
1074 set cache=0.
1075 '''
1076 return Node(self, nodeid, cache=cache)
1078 def set(self, nodeid, **propvalues):
1079 '''Modify a property on an existing node of this class.
1081 'nodeid' must be the id of an existing node of this class or an
1082 IndexError is raised.
1084 Each key in 'propvalues' must be the name of a property of this
1085 class or a KeyError is raised.
1087 All values in 'propvalues' must be acceptable types for their
1088 corresponding properties or a TypeError is raised.
1090 If the value of the key property is set, it must not collide with
1091 other key strings or a ValueError is raised.
1093 If the value of a Link or Multilink property contains an invalid
1094 node id, a ValueError is raised.
1095 '''
1096 if not propvalues:
1097 return propvalues
1099 if propvalues.has_key('creation') or propvalues.has_key('activity'):
1100 raise KeyError, '"creation" and "activity" are reserved'
1102 if propvalues.has_key('id'):
1103 raise KeyError, '"id" is reserved'
1105 if self.db.journaltag is None:
1106 raise DatabaseError, 'Database open read-only'
1108 self.fireAuditors('set', nodeid, propvalues)
1109 # Take a copy of the node dict so that the subsequent set
1110 # operation doesn't modify the oldvalues structure.
1111 # XXX used to try the cache here first
1112 oldvalues = copy.deepcopy(self.db.getnode(self.classname, nodeid))
1114 node = self.db.getnode(self.classname, nodeid)
1115 if self.is_retired(nodeid):
1116 raise IndexError
1117 num_re = re.compile('^\d+$')
1119 # if the journal value is to be different, store it in here
1120 journalvalues = {}
1122 # remember the add/remove stuff for multilinks, making it easier
1123 # for the Database layer to do its stuff
1124 multilink_changes = {}
1126 for propname, value in propvalues.items():
1127 # check to make sure we're not duplicating an existing key
1128 if propname == self.key and node[propname] != value:
1129 try:
1130 self.lookup(value)
1131 except KeyError:
1132 pass
1133 else:
1134 raise ValueError, 'node with key "%s" exists'%value
1136 # this will raise the KeyError if the property isn't valid
1137 # ... we don't use getprops() here because we only care about
1138 # the writeable properties.
1139 prop = self.properties[propname]
1141 # if the value's the same as the existing value, no sense in
1142 # doing anything
1143 if node.has_key(propname) and value == node[propname]:
1144 del propvalues[propname]
1145 continue
1147 # do stuff based on the prop type
1148 if isinstance(prop, Link):
1149 link_class = prop.classname
1150 # if it isn't a number, it's a key
1151 if value is not None and not isinstance(value, type('')):
1152 raise ValueError, 'property "%s" link value be a string'%(
1153 propname)
1154 if isinstance(value, type('')) and not num_re.match(value):
1155 try:
1156 value = self.db.classes[link_class].lookup(value)
1157 except (TypeError, KeyError):
1158 raise IndexError, 'new property "%s": %s not a %s'%(
1159 propname, value, prop.classname)
1161 if (value is not None and
1162 not self.db.getclass(link_class).hasnode(value)):
1163 raise IndexError, '%s has no node %s'%(link_class, value)
1165 if self.do_journal and prop.do_journal:
1166 # register the unlink with the old linked node
1167 if node[propname] is not None:
1168 self.db.addjournal(link_class, node[propname], 'unlink',
1169 (self.classname, nodeid, propname))
1171 # register the link with the newly linked node
1172 if value is not None:
1173 self.db.addjournal(link_class, value, 'link',
1174 (self.classname, nodeid, propname))
1176 elif isinstance(prop, Multilink):
1177 if type(value) != type([]):
1178 raise TypeError, 'new property "%s" not a list of'\
1179 ' ids'%propname
1180 link_class = self.properties[propname].classname
1181 l = []
1182 for entry in value:
1183 # if it isn't a number, it's a key
1184 if type(entry) != type(''):
1185 raise ValueError, 'new property "%s" link value ' \
1186 'must be a string'%propname
1187 if not num_re.match(entry):
1188 try:
1189 entry = self.db.classes[link_class].lookup(entry)
1190 except (TypeError, KeyError):
1191 raise IndexError, 'new property "%s": %s not a %s'%(
1192 propname, entry,
1193 self.properties[propname].classname)
1194 l.append(entry)
1195 value = l
1196 propvalues[propname] = value
1198 # figure the journal entry for this property
1199 add = []
1200 remove = []
1202 # handle removals
1203 if node.has_key(propname):
1204 l = node[propname]
1205 else:
1206 l = []
1207 for id in l[:]:
1208 if id in value:
1209 continue
1210 # register the unlink with the old linked node
1211 if self.do_journal and self.properties[propname].do_journal:
1212 self.db.addjournal(link_class, id, 'unlink',
1213 (self.classname, nodeid, propname))
1214 l.remove(id)
1215 remove.append(id)
1217 # handle additions
1218 for id in value:
1219 if not self.db.getclass(link_class).hasnode(id):
1220 raise IndexError, '%s has no node %s'%(link_class, id)
1221 if id in l:
1222 continue
1223 # register the link with the newly linked node
1224 if self.do_journal and self.properties[propname].do_journal:
1225 self.db.addjournal(link_class, id, 'link',
1226 (self.classname, nodeid, propname))
1227 l.append(id)
1228 add.append(id)
1230 # figure the journal entry
1231 l = []
1232 if add:
1233 l.append(('+', add))
1234 if remove:
1235 l.append(('-', remove))
1236 multilink_changes[propname] = (add, remove)
1237 if l:
1238 journalvalues[propname] = tuple(l)
1240 elif isinstance(prop, String):
1241 if value is not None and type(value) != type(''):
1242 raise TypeError, 'new property "%s" not a string'%propname
1244 elif isinstance(prop, Password):
1245 if not isinstance(value, password.Password):
1246 raise TypeError, 'new property "%s" not a Password'%propname
1247 propvalues[propname] = value
1249 elif value is not None and isinstance(prop, Date):
1250 if not isinstance(value, date.Date):
1251 raise TypeError, 'new property "%s" not a Date'% propname
1252 propvalues[propname] = value
1254 elif value is not None and isinstance(prop, Interval):
1255 if not isinstance(value, date.Interval):
1256 raise TypeError, 'new property "%s" not an '\
1257 'Interval'%propname
1258 propvalues[propname] = value
1260 elif value is not None and isinstance(prop, Number):
1261 try:
1262 float(value)
1263 except ValueError:
1264 raise TypeError, 'new property "%s" not numeric'%propname
1266 elif value is not None and isinstance(prop, Boolean):
1267 try:
1268 int(value)
1269 except ValueError:
1270 raise TypeError, 'new property "%s" not boolean'%propname
1272 node[propname] = value
1274 # nothing to do?
1275 if not propvalues:
1276 return propvalues
1278 # do the set, and journal it
1279 self.db.setnode(self.classname, nodeid, node, multilink_changes)
1281 if self.do_journal:
1282 propvalues.update(journalvalues)
1283 self.db.addjournal(self.classname, nodeid, 'set', propvalues)
1285 self.fireReactors('set', nodeid, oldvalues)
1287 return propvalues
1289 def retire(self, nodeid):
1290 '''Retire a node.
1292 The properties on the node remain available from the get() method,
1293 and the node's id is never reused.
1295 Retired nodes are not returned by the find(), list(), or lookup()
1296 methods, and other nodes may reuse the values of their key properties.
1297 '''
1298 if self.db.journaltag is None:
1299 raise DatabaseError, 'Database open read-only'
1301 cursor = self.db.conn.cursor()
1302 sql = 'update _%s set __retired__=1 where id=?'%self.classname
1303 if __debug__:
1304 print >>hyperdb.DEBUG, 'retire', (self, sql, nodeid)
1305 cursor.execute(sql, (nodeid,))
1307 def is_retired(self, nodeid):
1308 '''Return true if the node is rerired
1309 '''
1310 cursor = self.db.conn.cursor()
1311 sql = 'select __retired__ from _%s where id=?'%self.classname
1312 if __debug__:
1313 print >>hyperdb.DEBUG, 'is_retired', (self, sql, nodeid)
1314 cursor.execute(sql, (nodeid,))
1315 return cursor.fetchone()[0]
1317 def destroy(self, nodeid):
1318 '''Destroy a node.
1320 WARNING: this method should never be used except in extremely rare
1321 situations where there could never be links to the node being
1322 deleted
1323 WARNING: use retire() instead
1324 WARNING: the properties of this node will not be available ever again
1325 WARNING: really, use retire() instead
1327 Well, I think that's enough warnings. This method exists mostly to
1328 support the session storage of the cgi interface.
1330 The node is completely removed from the hyperdb, including all journal
1331 entries. It will no longer be available, and will generally break code
1332 if there are any references to the node.
1333 '''
1334 if self.db.journaltag is None:
1335 raise DatabaseError, 'Database open read-only'
1336 self.db.destroynode(self.classname, nodeid)
1338 def history(self, nodeid):
1339 '''Retrieve the journal of edits on a particular node.
1341 'nodeid' must be the id of an existing node of this class or an
1342 IndexError is raised.
1344 The returned list contains tuples of the form
1346 (date, tag, action, params)
1348 'date' is a Timestamp object specifying the time of the change and
1349 'tag' is the journaltag specified when the database was opened.
1350 '''
1351 if not self.do_journal:
1352 raise ValueError, 'Journalling is disabled for this class'
1353 return self.db.getjournal(self.classname, nodeid)
1355 # Locating nodes:
1356 def hasnode(self, nodeid):
1357 '''Determine if the given nodeid actually exists
1358 '''
1359 return self.db.hasnode(self.classname, nodeid)
1361 def setkey(self, propname):
1362 '''Select a String property of this class to be the key property.
1364 'propname' must be the name of a String property of this class or
1365 None, or a TypeError is raised. The values of the key property on
1366 all existing nodes must be unique or a ValueError is raised.
1367 '''
1368 # XXX create an index on the key prop column
1369 prop = self.getprops()[propname]
1370 if not isinstance(prop, String):
1371 raise TypeError, 'key properties must be String'
1372 self.key = propname
1374 def getkey(self):
1375 '''Return the name of the key property for this class or None.'''
1376 return self.key
1378 def labelprop(self, default_to_id=0):
1379 ''' Return the property name for a label for the given node.
1381 This method attempts to generate a consistent label for the node.
1382 It tries the following in order:
1383 1. key property
1384 2. "name" property
1385 3. "title" property
1386 4. first property from the sorted property name list
1387 '''
1388 k = self.getkey()
1389 if k:
1390 return k
1391 props = self.getprops()
1392 if props.has_key('name'):
1393 return 'name'
1394 elif props.has_key('title'):
1395 return 'title'
1396 if default_to_id:
1397 return 'id'
1398 props = props.keys()
1399 props.sort()
1400 return props[0]
1402 def lookup(self, keyvalue):
1403 '''Locate a particular node by its key property and return its id.
1405 If this class has no key property, a TypeError is raised. If the
1406 'keyvalue' matches one of the values for the key property among
1407 the nodes in this class, the matching node's id is returned;
1408 otherwise a KeyError is raised.
1409 '''
1410 if not self.key:
1411 raise TypeError, 'No key property set'
1413 cursor = self.db.conn.cursor()
1414 sql = 'select id from _%s where _%s=?'%(self.classname, self.key)
1415 if __debug__:
1416 print >>hyperdb.DEBUG, 'lookup', (self, sql, keyvalue)
1417 cursor.execute(sql, (keyvalue,))
1419 # see if there was a result
1420 l = cursor.fetchall()
1421 if not l:
1422 raise KeyError, keyvalue
1424 # return the id
1425 return l[0][0]
1427 def find(self, **propspec):
1428 '''Get the ids of nodes in this class which link to the given nodes.
1430 'propspec' consists of keyword args propname={nodeid:1,}
1431 'propname' must be the name of a property in this class, or a
1432 KeyError is raised. That property must be a Link or Multilink
1433 property, or a TypeError is raised.
1435 Any node in this class whose 'propname' property links to any of the
1436 nodeids will be returned. Used by the full text indexing, which knows
1437 that "foo" occurs in msg1, msg3 and file7, so we have hits on these
1438 issues:
1440 db.issue.find(messages={'1':1,'3':1}, files={'7':1})
1441 '''
1442 if __debug__:
1443 print >>hyperdb.DEBUG, 'find', (self, propspec)
1444 if not propspec:
1445 return []
1446 queries = []
1447 tables = []
1448 allvalues = ()
1449 for prop, values in propspec.items():
1450 allvalues += tuple(values.keys())
1451 tables.append('select nodeid from %s_%s where linkid in (%s)'%(
1452 self.classname, prop, ','.join(['?' for x in values.keys()])))
1453 sql = '\nintersect\n'.join(tables)
1454 if __debug__:
1455 print >>hyperdb.DEBUG, 'find', (self, sql, allvalues)
1456 cursor = self.db.conn.cursor()
1457 cursor.execute(sql, allvalues)
1458 try:
1459 l = [x[0] for x in cursor.fetchall()]
1460 except gadfly.database.error, message:
1461 if message == 'no more results':
1462 l = []
1463 raise
1464 if __debug__:
1465 print >>hyperdb.DEBUG, 'find ... ', l
1466 return l
1468 def list(self):
1469 ''' Return a list of the ids of the active nodes in this class.
1470 '''
1471 return self.db.getnodeids(self.classname, retired=0)
1473 def filter(self, search_matches, filterspec, sort, group):
1474 ''' Return a list of the ids of the active nodes in this class that
1475 match the 'filter' spec, sorted by the group spec and then the
1476 sort spec
1478 "filterspec" is {propname: value(s)}
1479 "sort" and "group" are (dir, prop) where dir is '+', '-' or None
1480 and prop is a prop name or None
1481 "search_matches" is {nodeid: marker}
1482 '''
1483 cn = self.classname
1485 # figure the WHERE clause from the filterspec
1486 props = self.getprops()
1487 frum = ['_'+cn]
1488 where = []
1489 args = []
1490 for k, v in filterspec.items():
1491 propclass = props[k]
1492 if isinstance(propclass, Multilink):
1493 tn = '%s_%s'%(cn, k)
1494 frum.append(tn)
1495 if isinstance(v, type([])):
1496 s = ','.join(['?' for x in v])
1497 where.append('id=%s.nodeid and %s.linkid in (%s)'%(tn,tn,s))
1498 args = args + v
1499 else:
1500 where.append('id=%s.nodeid and %s.linkid = ?'%(tn, tn))
1501 args.append(v)
1502 else:
1503 if isinstance(v, type([])):
1504 s = ','.join(['?' for x in v])
1505 where.append('_%s in (%s)'%(k, s))
1506 args = args + v
1507 else:
1508 where.append('_%s=?'%k)
1509 args.append(v)
1511 # add results of full text search
1512 if search_matches is not None:
1513 v = search_matches.keys()
1514 s = ','.join(['?' for x in v])
1515 where.append('id in (%s)'%s)
1516 args = args + v
1518 # figure the order by clause
1519 orderby = []
1520 ordercols = []
1521 if sort is not None:
1522 if sort[0] != '-':
1523 orderby.append('_'+sort[1])
1524 ordercols.append(sort[1])
1525 else:
1526 orderby.append('_'+sort[1]+' desc')
1527 ordercols.append(sort[1])
1529 # figure the group by clause
1530 groupby = []
1531 groupcols = []
1532 if group is not None:
1533 if group[0] != '-':
1534 groupby.append('_'+group[1])
1535 groupcols.append(group[1])
1536 else:
1537 groupby.append('_'+group[1]+' desc')
1538 groupcols.append(group[1])
1540 # construct the SQL
1541 frum = ','.join(frum)
1542 where = ' and '.join(where)
1543 cols = ['id']
1544 if orderby:
1545 cols = cols + ordercols
1546 order = ' order by %s'%(','.join(orderby))
1547 else:
1548 order = ''
1549 if groupby:
1550 cols = cols + groupcols
1551 group = ' group by %s'%(','.join(groupby))
1552 else:
1553 group = ''
1554 cols = ','.join(cols)
1555 sql = 'select %s from %s where %s%s%s'%(cols, frum, where, order,
1556 group)
1557 args = tuple(args)
1558 if __debug__:
1559 print >>hyperdb.DEBUG, 'find', (self, sql, args)
1560 cursor = self.db.conn.cursor()
1561 cursor.execute(sql, args)
1563 def count(self):
1564 '''Get the number of nodes in this class.
1566 If the returned integer is 'numnodes', the ids of all the nodes
1567 in this class run from 1 to numnodes, and numnodes+1 will be the
1568 id of the next node to be created in this class.
1569 '''
1570 return self.db.countnodes(self.classname)
1572 # Manipulating properties:
1573 def getprops(self, protected=1):
1574 '''Return a dictionary mapping property names to property objects.
1575 If the "protected" flag is true, we include protected properties -
1576 those which may not be modified.
1577 '''
1578 d = self.properties.copy()
1579 if protected:
1580 d['id'] = String()
1581 d['creation'] = hyperdb.Date()
1582 d['activity'] = hyperdb.Date()
1583 d['creator'] = hyperdb.Link("user")
1584 return d
1586 def addprop(self, **properties):
1587 '''Add properties to this class.
1589 The keyword arguments in 'properties' must map names to property
1590 objects, or a TypeError is raised. None of the keys in 'properties'
1591 may collide with the names of existing properties, or a ValueError
1592 is raised before any properties have been added.
1593 '''
1594 for key in properties.keys():
1595 if self.properties.has_key(key):
1596 raise ValueError, key
1597 self.properties.update(properties)
1599 def index(self, nodeid):
1600 '''Add (or refresh) the node to search indexes
1601 '''
1602 # find all the String properties that have indexme
1603 for prop, propclass in self.getprops().items():
1604 if isinstance(propclass, String) and propclass.indexme:
1605 try:
1606 value = str(self.get(nodeid, prop))
1607 except IndexError:
1608 # node no longer exists - entry should be removed
1609 self.db.indexer.purge_entry((self.classname, nodeid, prop))
1610 else:
1611 # and index them under (classname, nodeid, property)
1612 self.db.indexer.add_text((self.classname, nodeid, prop),
1613 value)
1616 #
1617 # Detector interface
1618 #
1619 def audit(self, event, detector):
1620 '''Register a detector
1621 '''
1622 l = self.auditors[event]
1623 if detector not in l:
1624 self.auditors[event].append(detector)
1626 def fireAuditors(self, action, nodeid, newvalues):
1627 '''Fire all registered auditors.
1628 '''
1629 for audit in self.auditors[action]:
1630 audit(self.db, self, nodeid, newvalues)
1632 def react(self, event, detector):
1633 '''Register a detector
1634 '''
1635 l = self.reactors[event]
1636 if detector not in l:
1637 self.reactors[event].append(detector)
1639 def fireReactors(self, action, nodeid, oldvalues):
1640 '''Fire all registered reactors.
1641 '''
1642 for react in self.reactors[action]:
1643 react(self.db, self, nodeid, oldvalues)
1645 class FileClass(Class):
1646 '''This class defines a large chunk of data. To support this, it has a
1647 mandatory String property "content" which is typically saved off
1648 externally to the hyperdb.
1650 The default MIME type of this data is defined by the
1651 "default_mime_type" class attribute, which may be overridden by each
1652 node if the class defines a "type" String property.
1653 '''
1654 default_mime_type = 'text/plain'
1656 def create(self, **propvalues):
1657 ''' snaffle the file propvalue and store in a file
1658 '''
1659 content = propvalues['content']
1660 del propvalues['content']
1661 newid = Class.create(self, **propvalues)
1662 self.db.storefile(self.classname, newid, None, content)
1663 return newid
1665 def import_list(self, propnames, proplist):
1666 ''' Trap the "content" property...
1667 '''
1668 # dupe this list so we don't affect others
1669 propnames = propnames[:]
1671 # extract the "content" property from the proplist
1672 i = propnames.index('content')
1673 content = proplist[i]
1674 del propnames[i]
1675 del proplist[i]
1677 # do the normal import
1678 newid = Class.import_list(self, propnames, proplist)
1680 # save off the "content" file
1681 self.db.storefile(self.classname, newid, None, content)
1682 return newid
1684 _marker = []
1685 def get(self, nodeid, propname, default=_marker, cache=1):
1686 ''' trap the content propname and get it from the file
1687 '''
1689 poss_msg = 'Possibly a access right configuration problem.'
1690 if propname == 'content':
1691 try:
1692 return self.db.getfile(self.classname, nodeid, None)
1693 except IOError, (strerror):
1694 # BUG: by catching this we donot see an error in the log.
1695 return 'ERROR reading file: %s%s\n%s\n%s'%(
1696 self.classname, nodeid, poss_msg, strerror)
1697 if default is not self._marker:
1698 return Class.get(self, nodeid, propname, default, cache=cache)
1699 else:
1700 return Class.get(self, nodeid, propname, cache=cache)
1702 def getprops(self, protected=1):
1703 ''' In addition to the actual properties on the node, these methods
1704 provide the "content" property. If the "protected" flag is true,
1705 we include protected properties - those which may not be
1706 modified.
1707 '''
1708 d = Class.getprops(self, protected=protected).copy()
1709 if protected:
1710 d['content'] = hyperdb.String()
1711 return d
1713 def index(self, nodeid):
1714 ''' Index the node in the search index.
1716 We want to index the content in addition to the normal String
1717 property indexing.
1718 '''
1719 # perform normal indexing
1720 Class.index(self, nodeid)
1722 # get the content to index
1723 content = self.get(nodeid, 'content')
1725 # figure the mime type
1726 if self.properties.has_key('type'):
1727 mime_type = self.get(nodeid, 'type')
1728 else:
1729 mime_type = self.default_mime_type
1731 # and index!
1732 self.db.indexer.add_text((self.classname, nodeid, 'content'), content,
1733 mime_type)
1735 # XXX deviation from spec - was called ItemClass
1736 class IssueClass(Class, roundupdb.IssueClass):
1737 # Overridden methods:
1738 def __init__(self, db, classname, **properties):
1739 '''The newly-created class automatically includes the "messages",
1740 "files", "nosy", and "superseder" properties. If the 'properties'
1741 dictionary attempts to specify any of these properties or a
1742 "creation" or "activity" property, a ValueError is raised.
1743 '''
1744 if not properties.has_key('title'):
1745 properties['title'] = hyperdb.String(indexme='yes')
1746 if not properties.has_key('messages'):
1747 properties['messages'] = hyperdb.Multilink("msg")
1748 if not properties.has_key('files'):
1749 properties['files'] = hyperdb.Multilink("file")
1750 if not properties.has_key('nosy'):
1751 # note: journalling is turned off as it really just wastes
1752 # space. this behaviour may be overridden in an instance
1753 properties['nosy'] = hyperdb.Multilink("user", do_journal="no")
1754 if not properties.has_key('superseder'):
1755 properties['superseder'] = hyperdb.Multilink(classname)
1756 Class.__init__(self, db, classname, **properties)
1758 #
1759 # $Log: not supported by cvs2svn $
1760 # Revision 1.8 2002/09/03 02:53:53 richard
1761 # Fixed nasty bug that was preventing changes to multilinks going through.
1762 #
1763 # Revision 1.7 2002/09/01 04:32:30 richard
1764 # . Lots of cleanup in the classic html (stylesheet, search page, index page, ...)
1765 # . Reinstated searching, but not query saving yet
1766 # . Filtering only allows sorting and grouping by one property - all backends
1767 # now implement this behaviour.
1768 # . Nosy list journalling turned off by default, everything else is on.
1769 # . Added some convenience methods (reverse, propchanged, [item] accesses, ...)
1770 # . Did I mention the stylesheet is much cleaner now? :)
1771 #
1772 # Revision 1.6 2002/08/30 08:35:16 richard
1773 # very basic filter support
1774 #
1775 # Revision 1.5 2002/08/23 05:33:32 richard
1776 # implemented multilink changes (and a unit test)
1777 #
1778 # Revision 1.4 2002/08/23 05:00:38 richard
1779 # fixed read-only gadfly retire()
1780 #
1781 # Revision 1.3 2002/08/23 04:58:00 richard
1782 # ahhh, I understand now
1783 #
1784 # Revision 1.2 2002/08/23 04:48:10 richard
1785 # That's gadfly done, mostly. Things left:
1786 # - Class.filter (I'm a wuss ;)
1787 # - schema changes adding new non-multilink properties are not implemented.
1788 # gadfly doesn't have an ALTER TABLE command, making that quite difficult :)
1789 #
1790 # I had to mangle two unit tests to get this all working:
1791 # - gadfly also can't handle two handles open on the one database, so
1792 # testIDGeneration doesn't try that.
1793 # - testNewProperty is disabled as per the second comment above.
1794 #
1795 # I noticed test_pack was incorrect, and the *dbm tests fail there now.
1796 # Looking into it...
1797 #
1798 # Revision 1.1 2002/08/22 07:56:51 richard
1799 # Whee! It's not finished yet, but I can create a new instance and play with
1800 # it a little bit :)
1801 #
1802 # Revision 1.80 2002/08/16 04:28:13 richard
1803 # added is_retired query to Class
1804 #
1805 # Revision 1.79 2002/07/29 23:30:14 richard
1806 # documentation reorg post-new-security
1807 #
1808 # Revision 1.78 2002/07/21 03:26:37 richard
1809 # Gordon, does this help?
1810 #
1811 # Revision 1.77 2002/07/18 11:27:47 richard
1812 # ws
1813 #
1814 # Revision 1.76 2002/07/18 11:17:30 gmcm
1815 # Add Number and Boolean types to hyperdb.
1816 # Add conversion cases to web, mail & admin interfaces.
1817 # Add storage/serialization cases to back_anydbm & back_metakit.
1818 #
1819 # Revision 1.75 2002/07/14 02:05:53 richard
1820 # . all storage-specific code (ie. backend) is now implemented by the backends
1821 #
1822 # Revision 1.74 2002/07/10 00:24:10 richard
1823 # braino
1824 #
1825 # Revision 1.73 2002/07/10 00:19:48 richard
1826 # Added explicit closing of backend database handles.
1827 #
1828 # Revision 1.72 2002/07/09 21:53:38 gmcm
1829 # Optimize Class.find so that the propspec can contain a set of ids to match.
1830 # This is used by indexer.search so it can do just one find for all the index matches.
1831 # This was already confusing code, but for common terms (lots of index matches),
1832 # it is enormously faster.
1833 #
1834 # Revision 1.71 2002/07/09 03:02:52 richard
1835 # More indexer work:
1836 # - all String properties may now be indexed too. Currently there's a bit of
1837 # "issue" specific code in the actual searching which needs to be
1838 # addressed. In a nutshell:
1839 # + pass 'indexme="yes"' as a String() property initialisation arg, eg:
1840 # file = FileClass(db, "file", name=String(), type=String(),
1841 # comment=String(indexme="yes"))
1842 # + the comment will then be indexed and be searchable, with the results
1843 # related back to the issue that the file is linked to
1844 # - as a result of this work, the FileClass has a default MIME type that may
1845 # be overridden in a subclass, or by the use of a "type" property as is
1846 # done in the default templates.
1847 # - the regeneration of the indexes (if necessary) is done once the schema is
1848 # set up in the dbinit.
1849 #
1850 # Revision 1.70 2002/06/27 12:06:20 gmcm
1851 # Improve an error message.
1852 #
1853 # Revision 1.69 2002/06/17 23:15:29 richard
1854 # Can debug to stdout now
1855 #
1856 # Revision 1.68 2002/06/11 06:52:03 richard
1857 # . #564271 ] find() and new properties
1858 #
1859 # Revision 1.67 2002/06/11 05:02:37 richard
1860 # . #565979 ] code error in hyperdb.Class.find
1861 #
1862 # Revision 1.66 2002/05/25 07:16:24 rochecompaan
1863 # Merged search_indexing-branch with HEAD
1864 #
1865 # Revision 1.65 2002/05/22 04:12:05 richard
1866 # . applied patch #558876 ] cgi client customization
1867 # ... with significant additions and modifications ;)
1868 # - extended handling of ML assignedto to all places it's handled
1869 # - added more NotFound info
1870 #
1871 # Revision 1.64 2002/05/15 06:21:21 richard
1872 # . node caching now works, and gives a small boost in performance
1873 #
1874 # As a part of this, I cleaned up the DEBUG output and implemented TRACE
1875 # output (HYPERDBTRACE='file to trace to') with checkpoints at the start of
1876 # CGI requests. Run roundup with python -O to skip all the DEBUG/TRACE stuff
1877 # (using if __debug__ which is compiled out with -O)
1878 #
1879 # Revision 1.63 2002/04/15 23:25:15 richard
1880 # . node ids are now generated from a lockable store - no more race conditions
1881 #
1882 # We're using the portalocker code by Jonathan Feinberg that was contributed
1883 # to the ASPN Python cookbook. This gives us locking across Unix and Windows.
1884 #
1885 # Revision 1.62 2002/04/03 07:05:50 richard
1886 # d'oh! killed retirement of nodes :(
1887 # all better now...
1888 #
1889 # Revision 1.61 2002/04/03 06:11:51 richard
1890 # Fix for old databases that contain properties that don't exist any more.
1891 #
1892 # Revision 1.60 2002/04/03 05:54:31 richard
1893 # Fixed serialisation problem by moving the serialisation step out of the
1894 # hyperdb.Class (get, set) into the hyperdb.Database.
1895 #
1896 # Also fixed htmltemplate after the showid changes I made yesterday.
1897 #
1898 # Unit tests for all of the above written.
1899 #
1900 # Revision 1.59.2.2 2002/04/20 13:23:33 rochecompaan
1901 # We now have a separate search page for nodes. Search links for
1902 # different classes can be customized in instance_config similar to
1903 # index links.
1904 #
1905 # Revision 1.59.2.1 2002/04/19 19:54:42 rochecompaan
1906 # cgi_client.py
1907 # removed search link for the time being
1908 # moved rendering of matches to htmltemplate
1909 # hyperdb.py
1910 # filtering of nodes on full text search incorporated in filter method
1911 # roundupdb.py
1912 # added paramater to call of filter method
1913 # roundup_indexer.py
1914 # added search method to RoundupIndexer class
1915 #
1916 # Revision 1.59 2002/03/12 22:52:26 richard
1917 # more pychecker warnings removed
1918 #
1919 # Revision 1.58 2002/02/27 03:23:16 richard
1920 # Ran it through pychecker, made fixes
1921 #
1922 # Revision 1.57 2002/02/20 05:23:24 richard
1923 # Didn't accomodate new values for new properties
1924 #
1925 # Revision 1.56 2002/02/20 05:05:28 richard
1926 # . Added simple editing for classes that don't define a templated interface.
1927 # - access using the admin "class list" interface
1928 # - limited to admin-only
1929 # - requires the csv module from object-craft (url given if it's missing)
1930 #
1931 # Revision 1.55 2002/02/15 07:27:12 richard
1932 # Oops, precedences around the way w0rng.
1933 #
1934 # Revision 1.54 2002/02/15 07:08:44 richard
1935 # . Alternate email addresses are now available for users. See the MIGRATION
1936 # file for info on how to activate the feature.
1937 #
1938 # Revision 1.53 2002/01/22 07:21:13 richard
1939 # . fixed back_bsddb so it passed the journal tests
1940 #
1941 # ... it didn't seem happy using the back_anydbm _open method, which is odd.
1942 # Yet another occurrance of whichdb not being able to recognise older bsddb
1943 # databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the
1944 # process.
1945 #
1946 # Revision 1.52 2002/01/21 16:33:19 rochecompaan
1947 # You can now use the roundup-admin tool to pack the database
1948 #
1949 # Revision 1.51 2002/01/21 03:01:29 richard
1950 # brief docco on the do_journal argument
1951 #
1952 # Revision 1.50 2002/01/19 13:16:04 rochecompaan
1953 # Journal entries for link and multilink properties can now be switched on
1954 # or off.
1955 #
1956 # Revision 1.49 2002/01/16 07:02:57 richard
1957 # . lots of date/interval related changes:
1958 # - more relaxed date format for input
1959 #
1960 # Revision 1.48 2002/01/14 06:32:34 richard
1961 # . #502951 ] adding new properties to old database
1962 #
1963 # Revision 1.47 2002/01/14 02:20:15 richard
1964 # . changed all config accesses so they access either the instance or the
1965 # config attriubute on the db. This means that all config is obtained from
1966 # instance_config instead of the mish-mash of classes. This will make
1967 # switching to a ConfigParser setup easier too, I hope.
1968 #
1969 # At a minimum, this makes migration a _little_ easier (a lot easier in the
1970 # 0.5.0 switch, I hope!)
1971 #
1972 # Revision 1.46 2002/01/07 10:42:23 richard
1973 # oops
1974 #
1975 # Revision 1.45 2002/01/02 04:18:17 richard
1976 # hyperdb docstrings
1977 #
1978 # Revision 1.44 2002/01/02 02:31:38 richard
1979 # Sorry for the huge checkin message - I was only intending to implement #496356
1980 # but I found a number of places where things had been broken by transactions:
1981 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
1982 # for _all_ roundup-generated smtp messages to be sent to.
1983 # . the transaction cache had broken the roundupdb.Class set() reactors
1984 # . newly-created author users in the mailgw weren't being committed to the db
1985 #
1986 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
1987 # on when I found that stuff :):
1988 # . #496356 ] Use threading in messages
1989 # . detectors were being registered multiple times
1990 # . added tests for mailgw
1991 # . much better attaching of erroneous messages in the mail gateway
1992 #
1993 # Revision 1.43 2001/12/20 06:13:24 rochecompaan
1994 # Bugs fixed:
1995 # . Exception handling in hyperdb for strings-that-look-like numbers got
1996 # lost somewhere
1997 # . Internet Explorer submits full path for filename - we now strip away
1998 # the path
1999 # Features added:
2000 # . Link and multilink properties are now displayed sorted in the cgi
2001 # interface
2002 #
2003 # Revision 1.42 2001/12/16 10:53:37 richard
2004 # take a copy of the node dict so that the subsequent set
2005 # operation doesn't modify the oldvalues structure
2006 #
2007 # Revision 1.41 2001/12/15 23:47:47 richard
2008 # Cleaned up some bare except statements
2009 #
2010 # Revision 1.40 2001/12/14 23:42:57 richard
2011 # yuck, a gdbm instance tests false :(
2012 # I've left the debugging code in - it should be removed one day if we're ever
2013 # _really_ anal about performace :)
2014 #
2015 # Revision 1.39 2001/12/02 05:06:16 richard
2016 # . We now use weakrefs in the Classes to keep the database reference, so
2017 # the close() method on the database is no longer needed.
2018 # I bumped the minimum python requirement up to 2.1 accordingly.
2019 # . #487480 ] roundup-server
2020 # . #487476 ] INSTALL.txt
2021 #
2022 # I also cleaned up the change message / post-edit stuff in the cgi client.
2023 # There's now a clearly marked "TODO: append the change note" where I believe
2024 # the change note should be added there. The "changes" list will obviously
2025 # have to be modified to be a dict of the changes, or somesuch.
2026 #
2027 # More testing needed.
2028 #
2029 # Revision 1.38 2001/12/01 07:17:50 richard
2030 # . We now have basic transaction support! Information is only written to
2031 # the database when the commit() method is called. Only the anydbm
2032 # backend is modified in this way - neither of the bsddb backends have been.
2033 # The mail, admin and cgi interfaces all use commit (except the admin tool
2034 # doesn't have a commit command, so interactive users can't commit...)
2035 # . Fixed login/registration forwarding the user to the right page (or not,
2036 # on a failure)
2037 #
2038 # Revision 1.37 2001/11/28 21:55:35 richard
2039 # . login_action and newuser_action return values were being ignored
2040 # . Woohoo! Found that bloody re-login bug that was killing the mail
2041 # gateway.
2042 # (also a minor cleanup in hyperdb)
2043 #
2044 # Revision 1.36 2001/11/27 03:16:09 richard
2045 # Another place that wasn't handling missing properties.
2046 #
2047 # Revision 1.35 2001/11/22 15:46:42 jhermann
2048 # Added module docstrings to all modules.
2049 #
2050 # Revision 1.34 2001/11/21 04:04:43 richard
2051 # *sigh* more missing value handling
2052 #
2053 # Revision 1.33 2001/11/21 03:40:54 richard
2054 # more new property handling
2055 #
2056 # Revision 1.32 2001/11/21 03:11:28 richard
2057 # Better handling of new properties.
2058 #
2059 # Revision 1.31 2001/11/12 22:01:06 richard
2060 # Fixed issues with nosy reaction and author copies.
2061 #
2062 # Revision 1.30 2001/11/09 10:11:08 richard
2063 # . roundup-admin now handles all hyperdb exceptions
2064 #
2065 # Revision 1.29 2001/10/27 00:17:41 richard
2066 # Made Class.stringFind() do caseless matching.
2067 #
2068 # Revision 1.28 2001/10/21 04:44:50 richard
2069 # bug #473124: UI inconsistency with Link fields.
2070 # This also prompted me to fix a fairly long-standing usability issue -
2071 # that of being able to turn off certain filters.
2072 #
2073 # Revision 1.27 2001/10/20 23:44:27 richard
2074 # Hyperdatabase sorts strings-that-look-like-numbers as numbers now.
2075 #
2076 # Revision 1.26 2001/10/16 03:48:01 richard
2077 # admin tool now complains if a "find" is attempted with a non-link property.
2078 #
2079 # Revision 1.25 2001/10/11 00:17:51 richard
2080 # Reverted a change in hyperdb so the default value for missing property
2081 # values in a create() is None and not '' (the empty string.) This obviously
2082 # breaks CSV import/export - the string 'None' will be created in an
2083 # export/import operation.
2084 #
2085 # Revision 1.24 2001/10/10 03:54:57 richard
2086 # Added database importing and exporting through CSV files.
2087 # Uses the csv module from object-craft for exporting if it's available.
2088 # Requires the csv module for importing.
2089 #
2090 # Revision 1.23 2001/10/09 23:58:10 richard
2091 # Moved the data stringification up into the hyperdb.Class class' get, set
2092 # and create methods. This means that the data is also stringified for the
2093 # journal call, and removes duplication of code from the backends. The
2094 # backend code now only sees strings.
2095 #
2096 # Revision 1.22 2001/10/09 07:25:59 richard
2097 # Added the Password property type. See "pydoc roundup.password" for
2098 # implementation details. Have updated some of the documentation too.
2099 #
2100 # Revision 1.21 2001/10/05 02:23:24 richard
2101 # . roundup-admin create now prompts for property info if none is supplied
2102 # on the command-line.
2103 # . hyperdb Class getprops() method may now return only the mutable
2104 # properties.
2105 # . Login now uses cookies, which makes it a whole lot more flexible. We can
2106 # now support anonymous user access (read-only, unless there's an
2107 # "anonymous" user, in which case write access is permitted). Login
2108 # handling has been moved into cgi_client.Client.main()
2109 # . The "extended" schema is now the default in roundup init.
2110 # . The schemas have had their page headings modified to cope with the new
2111 # login handling. Existing installations should copy the interfaces.py
2112 # file from the roundup lib directory to their instance home.
2113 # . Incorrectly had a Bizar Software copyright on the cgitb.py module from
2114 # Ping - has been removed.
2115 # . Fixed a whole bunch of places in the CGI interface where we should have
2116 # been returning Not Found instead of throwing an exception.
2117 # . Fixed a deviation from the spec: trying to modify the 'id' property of
2118 # an item now throws an exception.
2119 #
2120 # Revision 1.20 2001/10/04 02:12:42 richard
2121 # Added nicer command-line item adding: passing no arguments will enter an
2122 # interactive more which asks for each property in turn. While I was at it, I
2123 # fixed an implementation problem WRT the spec - I wasn't raising a
2124 # ValueError if the key property was missing from a create(). Also added a
2125 # protected=boolean argument to getprops() so we can list only the mutable
2126 # properties (defaults to yes, which lists the immutables).
2127 #
2128 # Revision 1.19 2001/08/29 04:47:18 richard
2129 # Fixed CGI client change messages so they actually include the properties
2130 # changed (again).
2131 #
2132 # Revision 1.18 2001/08/16 07:34:59 richard
2133 # better CGI text searching - but hidden filter fields are disappearing...
2134 #
2135 # Revision 1.17 2001/08/16 06:59:58 richard
2136 # all searches use re now - and they're all case insensitive
2137 #
2138 # Revision 1.16 2001/08/15 23:43:18 richard
2139 # Fixed some isFooTypes that I missed.
2140 # Refactored some code in the CGI code.
2141 #
2142 # Revision 1.15 2001/08/12 06:32:36 richard
2143 # using isinstance(blah, Foo) now instead of isFooType
2144 #
2145 # Revision 1.14 2001/08/07 00:24:42 richard
2146 # stupid typo
2147 #
2148 # Revision 1.13 2001/08/07 00:15:51 richard
2149 # Added the copyright/license notice to (nearly) all files at request of
2150 # Bizar Software.
2151 #
2152 # Revision 1.12 2001/08/02 06:38:17 richard
2153 # Roundupdb now appends "mailing list" information to its messages which
2154 # include the e-mail address and web interface address. Templates may
2155 # override this in their db classes to include specific information (support
2156 # instructions, etc).
2157 #
2158 # Revision 1.11 2001/08/01 04:24:21 richard
2159 # mailgw was assuming certain properties existed on the issues being created.
2160 #
2161 # Revision 1.10 2001/07/30 02:38:31 richard
2162 # get() now has a default arg - for migration only.
2163 #
2164 # Revision 1.9 2001/07/29 09:28:23 richard
2165 # Fixed sorting by clicking on column headings.
2166 #
2167 # Revision 1.8 2001/07/29 08:27:40 richard
2168 # Fixed handling of passed-in values in form elements (ie. during a
2169 # drill-down)
2170 #
2171 # Revision 1.7 2001/07/29 07:01:39 richard
2172 # Added vim command to all source so that we don't get no steenkin' tabs :)
2173 #
2174 # Revision 1.6 2001/07/29 05:36:14 richard
2175 # Cleanup of the link label generation.
2176 #
2177 # Revision 1.5 2001/07/29 04:05:37 richard
2178 # Added the fabricated property "id".
2179 #
2180 # Revision 1.4 2001/07/27 06:25:35 richard
2181 # Fixed some of the exceptions so they're the right type.
2182 # Removed the str()-ification of node ids so we don't mask oopsy errors any
2183 # more.
2184 #
2185 # Revision 1.3 2001/07/27 05:17:14 richard
2186 # just some comments
2187 #
2188 # Revision 1.2 2001/07/22 12:09:32 richard
2189 # Final commit of Grande Splite
2190 #
2191 # Revision 1.1 2001/07/22 11:58:35 richard
2192 # More Grande Splite
2193 #
2194 #
2195 # vim: set filetype=python ts=4 sw=4 et si