comparison roundup/hyperdb.py @ 431:a28a80b714f9

Eliminate database close method by using weakrefs. . We now use weakrefs in the Classes to keep the database reference, so the close() method on the database is no longer needed. I bumped the minimum python requirement up to 2.1 accordingly. . [SF#487480] roundup-server . [SF#487476] INSTALL.txt I also cleaned up the change message / post-edit stuff in the cgi client. There's now a clearly marked "TODO: append the change note" where I believe the change note should be added there. The "changes" list will obviously have to be modified to be a dict of the changes, or somesuch. More testing needed.
author Richard Jones <richard@users.sourceforge.net>
date Sun, 02 Dec 2001 05:06:16 +0000
parents 350685601f37
children 7181efddce66
comparison
equal deleted inserted replaced
430:350685601f37 431:a28a80b714f9
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: hyperdb.py,v 1.38 2001-12-01 07:17:50 richard Exp $ 18 # $Id: hyperdb.py,v 1.39 2001-12-02 05:06:16 richard Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Hyperdatabase implementation, especially field types. 21 Hyperdatabase implementation, especially field types.
22 """ 22 """
23 23
24 # standard python modules 24 # standard python modules
25 import cPickle, re, string 25 import cPickle, re, string, weakref
26 26
27 # roundup modules 27 # roundup modules
28 import date, password 28 import date, password
29 29
30 30
94 or a ValueError is raised. The keyword arguments in 'properties' 94 or a ValueError is raised. The keyword arguments in 'properties'
95 must map names to property objects, or a TypeError is raised. 95 must map names to property objects, or a TypeError is raised.
96 """ 96 """
97 self.classname = classname 97 self.classname = classname
98 self.properties = properties 98 self.properties = properties
99 self.db = db 99 self.db = weakref.proxy(db) # use a weak ref to avoid circularity
100 self.key = '' 100 self.key = ''
101 101
102 # do the db-related init stuff 102 # do the db-related init stuff
103 db.addclass(self) 103 db.addclass(self)
104 104
493 node = self.db.getnode(self.classname, nodeid, cldb) 493 node = self.db.getnode(self.classname, nodeid, cldb)
494 if node.has_key(self.db.RETIRED_FLAG): 494 if node.has_key(self.db.RETIRED_FLAG):
495 continue 495 continue
496 if node[self.key] == keyvalue: 496 if node[self.key] == keyvalue:
497 return nodeid 497 return nodeid
498 cldb.close()
499 raise KeyError, keyvalue 498 raise KeyError, keyvalue
500 499
501 # XXX: change from spec - allows multiple props to match 500 # XXX: change from spec - allows multiple props to match
502 def find(self, **propspec): 501 def find(self, **propspec):
503 """Get the ids of nodes in this class which link to a given node. 502 """Get the ids of nodes in this class which link to a given node.
530 property = node[propname] 529 property = node[propname]
531 if isinstance(prop, Link) and nodeid == property: 530 if isinstance(prop, Link) and nodeid == property:
532 l.append(id) 531 l.append(id)
533 elif isinstance(prop, Multilink) and nodeid in property: 532 elif isinstance(prop, Multilink) and nodeid in property:
534 l.append(id) 533 l.append(id)
535 cldb.close()
536 return l 534 return l
537 535
538 def stringFind(self, **requirements): 536 def stringFind(self, **requirements):
539 """Locate a particular node by matching a set of its String 537 """Locate a particular node by matching a set of its String
540 properties in a caseless search. 538 properties in a caseless search.
557 for key, value in requirements.items(): 555 for key, value in requirements.items():
558 if node[key] and node[key].lower() != value: 556 if node[key] and node[key].lower() != value:
559 break 557 break
560 else: 558 else:
561 l.append(nodeid) 559 l.append(nodeid)
562 cldb.close()
563 return l 560 return l
564 561
565 def list(self): 562 def list(self):
566 """Return a list of the ids of the active nodes in this class.""" 563 """Return a list of the ids of the active nodes in this class."""
567 l = [] 564 l = []
571 node = self.db.getnode(cn, nodeid, cldb) 568 node = self.db.getnode(cn, nodeid, cldb)
572 if node.has_key(self.db.RETIRED_FLAG): 569 if node.has_key(self.db.RETIRED_FLAG):
573 continue 570 continue
574 l.append(nodeid) 571 l.append(nodeid)
575 l.sort() 572 l.sort()
576 cldb.close()
577 return l 573 return l
578 574
579 # XXX not in spec 575 # XXX not in spec
580 def filter(self, filterspec, sort, group, num_re = re.compile('^\d+$')): 576 def filter(self, filterspec, sort, group, num_re = re.compile('^\d+$')):
581 ''' Return a list of the ids of the active nodes in this class that 577 ''' Return a list of the ids of the active nodes in this class that
664 # straight value comparison for the other types 660 # straight value comparison for the other types
665 break 661 break
666 else: 662 else:
667 l.append((nodeid, node)) 663 l.append((nodeid, node))
668 l.sort() 664 l.sort()
669 cldb.close()
670 665
671 # optimise sort 666 # optimise sort
672 m = [] 667 m = []
673 for entry in sort: 668 for entry in sort:
674 if entry[0] != '-': 669 if entry[0] != '-':
871 cl.create(name=option[i], order=i) 866 cl.create(name=option[i], order=i)
872 return hyperdb.Link(name) 867 return hyperdb.Link(name)
873 868
874 # 869 #
875 # $Log: not supported by cvs2svn $ 870 # $Log: not supported by cvs2svn $
871 # Revision 1.38 2001/12/01 07:17:50 richard
872 # . We now have basic transaction support! Information is only written to
873 # the database when the commit() method is called. Only the anydbm
874 # backend is modified in this way - neither of the bsddb backends have been.
875 # The mail, admin and cgi interfaces all use commit (except the admin tool
876 # doesn't have a commit command, so interactive users can't commit...)
877 # . Fixed login/registration forwarding the user to the right page (or not,
878 # on a failure)
879 #
876 # Revision 1.37 2001/11/28 21:55:35 richard 880 # Revision 1.37 2001/11/28 21:55:35 richard
877 # . login_action and newuser_action return values were being ignored 881 # . login_action and newuser_action return values were being ignored
878 # . Woohoo! Found that bloody re-login bug that was killing the mail 882 # . Woohoo! Found that bloody re-login bug that was killing the mail
879 # gateway. 883 # gateway.
880 # (also a minor cleanup in hyperdb) 884 # (also a minor cleanup in hyperdb)

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