Mercurial > p > roundup > code
annotate roundup/backends/back_anydbm.py @ 252:76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 29 Sep 2001 13:27:00 +0000 |
| parents | ad2c98faec97 |
| children | a4241ddd22d7 |
| rev | line source |
|---|---|
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
1 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
3 # This module is free software, and you may redistribute it and/or modify |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
4 # under the same terms as Python, so long as this copyright message and |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
5 # disclaimer are retained in their original form. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
6 # |
| 214 | 7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
10 # POSSIBILITY OF SUCH DAMAGE. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
11 # |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
17 # |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
18 #$Id: back_anydbm.py,v 1.8 2001-09-29 13:27:00 richard Exp $ |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
20 import anydbm, os, marshal |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 from roundup import hyperdb, date |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 # Now the database |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 class Database(hyperdb.Database): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
27 """A database for storing records containing flexible data types.""" |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 def __init__(self, storagelocator, journaltag=None): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 """Open a hyperdatabase given a specifier to some storage. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 The meaning of 'storagelocator' depends on the particular |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 implementation of the hyperdatabase. It could be a file name, |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 a directory path, a socket descriptor for a connection to a |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 database over the network, etc. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 The 'journaltag' is a token that will be attached to the journal |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 entries for any edits done on the database. If 'journaltag' is |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 None, the database is opened in read-only mode: the Class.create(), |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 Class.set(), and Class.retire() methods are disabled. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 """ |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 self.dir, self.journaltag = storagelocator, journaltag |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 self.classes = {} |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
44 self.transactions = [] |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 # Classes |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 def __getattr__(self, classname): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 """A convenient way of calling self.getclass(classname).""" |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 return self.classes[classname] |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
53 def addclass(self, cl): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 cn = cl.classname |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 if self.classes.has_key(cn): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 raise ValueError, cn |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 self.classes[cn] = cl |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
58 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
59 def getclasses(self): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 """Return a list of the names of all existing classes.""" |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 l = self.classes.keys() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 l.sort() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 return l |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 def getclass(self, classname): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 """Get the Class object representing a particular class. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 If 'classname' is not a valid class name, a KeyError is raised. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 """ |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 return self.classes[classname] |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 # Class DBs |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 def clear(self): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 for cn in self.classes.keys(): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 db = os.path.join(self.dir, 'nodes.%s'%cn) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 anydbm.open(db, 'n') |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 db = os.path.join(self.dir, 'journals.%s'%cn) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 anydbm.open(db, 'n') |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
81 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
82 def getclassdb(self, classname, mode='r'): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
83 ''' grab a connection to the class db that will be used for |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
84 multiple actions |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
85 ''' |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
86 path = os.path.join(os.getcwd(), self.dir, 'nodes.%s'%classname) |
|
71
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
87 if os.path.exists(path): |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
88 return anydbm.open(path, mode) |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
89 else: |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
90 return anydbm.open(path, 'n') |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
91 |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
92 # |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
93 # Nodes |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
94 # |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
95 def addnode(self, classname, nodeid, node): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
96 ''' add the specified node to its class's db |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
97 ''' |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
98 db = self.getclassdb(classname, 'c') |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
99 |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
100 # convert the instance data to builtin types |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
101 properties = self.classes[classname].properties |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
102 for key in properties.keys(): |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
103 if isinstance(properties[key], hyperdb.Date): |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
104 node[key] = node[key].get_tuple() |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
105 elif isinstance(properties[key], hyperdb.Interval): |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
106 node[key] = node[key].get_tuple() |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
107 |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
108 # now save the marshalled data |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
109 db[nodeid] = marshal.dumps(node) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
111 setnode = addnode |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
112 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
113 def getnode(self, classname, nodeid, cldb=None): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
114 ''' add the specified node to its class's db |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
115 ''' |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
116 db = cldb or self.getclassdb(classname) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
117 if not db.has_key(nodeid): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
118 raise IndexError, nodeid |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
119 res = marshal.loads(db[nodeid]) |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
120 |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
121 # convert the marshalled data to instances |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
122 properties = self.classes[classname].properties |
|
149
fbc77ecf133b
Makes schema changes mucho easier.
Richard Jones <richard@users.sourceforge.net>
parents:
71
diff
changeset
|
123 for key in properties.keys(): |
|
71
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
124 if key == self.RETIRED_FLAG: continue |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
125 if isinstance(properties[key], hyperdb.Date): |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
126 res[key] = date.Date(res[key]) |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
127 elif isinstance(properties[key], hyperdb.Interval): |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
128 res[key] = date.Interval(res[key]) |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
129 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
130 if not cldb: db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
131 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
132 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 def hasnode(self, classname, nodeid, cldb=None): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 ''' add the specified node to its class's db |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 ''' |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
136 db = cldb or self.getclassdb(classname) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
137 res = db.has_key(nodeid) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
138 if not cldb: db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
139 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
140 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
141 def countnodes(self, classname, cldb=None): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
142 db = cldb or self.getclassdb(classname) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
143 return len(db.keys()) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
144 if not cldb: db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
145 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
146 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
147 def getnodeids(self, classname, cldb=None): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
148 db = cldb or self.getclassdb(classname) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
149 res = db.keys() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
150 if not cldb: db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
151 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
152 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
153 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
154 # Journal |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
155 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
156 def addjournal(self, classname, nodeid, action, params): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
157 ''' Journal the Action |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
158 'action' may be: |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
159 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
160 'create' or 'set' -- 'params' is a dictionary of property values |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
161 'link' or 'unlink' -- 'params' is (classname, nodeid, propname) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
162 'retire' -- 'params' is None |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
163 ''' |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
164 entry = (nodeid, date.Date().get_tuple(), self.journaltag, action, |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
165 params) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
166 db = anydbm.open(os.path.join(self.dir, 'journals.%s'%classname), 'c') |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
167 if db.has_key(nodeid): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
168 s = db[nodeid] |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
169 l = marshal.loads(db[nodeid]) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
170 l.append(entry) |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
171 else: |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
172 l = [entry] |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
173 db[nodeid] = marshal.dumps(l) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
174 db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
175 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
176 def getjournal(self, classname, nodeid): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
177 ''' get the journal for id |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
178 ''' |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
179 # attempt to open the journal - in some rare cases, the journal may |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
180 # not exist |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
181 try: |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
182 db = anydbm.open(os.path.join(self.dir, 'journals.%s'%classname), |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
183 'r') |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
184 except anydbm.open, error: |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
185 if error.args[0] != 2: raise |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
186 return [] |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
187 journal = marshal.loads(db[nodeid]) |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
188 res = [] |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
189 for entry in journal: |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
190 (nodeid, date_stamp, self.journaltag, action, params) = entry |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
191 date_obj = date.Date(date_stamp) |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
192 res.append((nodeid, date_obj, self.journaltag, action, params)) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
193 db.close() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
194 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
195 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
196 def close(self): |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
197 ''' Close the Database - we must release the circular refs so that |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
198 we can be del'ed and the underlying anydbm connections closed |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
199 cleanly. |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
200 ''' |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
201 self.classes = None |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
202 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
203 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
204 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
205 # Basic transaction support |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
206 # |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
207 def commit(self): |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
208 ''' Commit the current transactions. |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
209 ''' |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
210 # lock the DB |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
211 for action, classname, entry in self.transactions: |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
212 # write the node, figure what's changed for the journal. |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
213 pass |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
214 # unlock the DB |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
215 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
216 def rollback(self): |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
217 ''' Reverse all actions from the current transaction. |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
218 ''' |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
219 self.transactions = [] |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
220 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
221 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
222 #$Log: not supported by cvs2svn $ |
|
252
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
223 #Revision 1.7 2001/08/12 06:32:36 richard |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
224 #using isinstance(blah, Foo) now instead of isFooType |
|
76c6994aa4e8
CGI interfaces now spit up a top-level index of all instances they can serve.
Richard Jones <richard@users.sourceforge.net>
parents:
224
diff
changeset
|
225 # |
|
224
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
226 #Revision 1.6 2001/08/07 00:24:42 richard |
|
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
227 #stupid typo |
|
ad2c98faec97
using isinstance(blah, Foo) now instead of isFooType
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
228 # |
| 214 | 229 #Revision 1.5 2001/08/07 00:15:51 richard |
| 230 #Added the copyright/license notice to (nearly) all files at request of | |
| 231 #Bizar Software. | |
| 232 # | |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
233 #Revision 1.4 2001/07/30 01:41:36 richard |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
234 #Makes schema changes mucho easier. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
149
diff
changeset
|
235 # |
|
149
fbc77ecf133b
Makes schema changes mucho easier.
Richard Jones <richard@users.sourceforge.net>
parents:
71
diff
changeset
|
236 #Revision 1.3 2001/07/25 01:23:07 richard |
|
fbc77ecf133b
Makes schema changes mucho easier.
Richard Jones <richard@users.sourceforge.net>
parents:
71
diff
changeset
|
237 #Added the Roundup spec to the new documentation directory. |
|
fbc77ecf133b
Makes schema changes mucho easier.
Richard Jones <richard@users.sourceforge.net>
parents:
71
diff
changeset
|
238 # |
|
71
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
239 #Revision 1.2 2001/07/23 08:20:44 richard |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
240 #Moved over to using marshal in the bsddb and anydbm backends. |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
241 #roundup-admin now has a "freshen" command that'll load/save all nodes (not |
|
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
242 # retired - mod hyperdb.Class.list() so it lists retired nodes) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
243 # |
|
71
5147b4c51fd5
Added the Roundup spec to the new documentation directory.
Richard Jones <richard@users.sourceforge.net>
parents:
48
diff
changeset
|
244 # |
