Mercurial > p > roundup > code
annotate roundup/backends/back_anydbm.py @ 1558:7914c286b68e
sigh++
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 26 Mar 2003 05:30:23 +0000 |
| parents | 9e89f5394f6c |
| children | e2a8ce4d2317 |
| 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 # |
| 1558 | 18 #$Id: back_anydbm.py,v 1.116 2003-03-26 05:30:23 richard Exp $ |
|
440
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
19 ''' |
|
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
20 This module defines a backend that saves the hyperdatabase in a database |
|
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
21 chosen by anydbm. It is guaranteed to always be available in python |
|
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
22 versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several |
|
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
23 serious bugs, and is not available) |
|
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
24 ''' |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
26 import whichdb, anydbm, os, marshal, re, weakref, string, copy |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
27 from roundup import hyperdb, date, password, roundupdb, security |
|
646
07abfe8f0c01
use blobfiles in back_anydbm which is used in back_bsddb.
Engelbert Gruber <grubert@users.sourceforge.net>
parents:
624
diff
changeset
|
28 from blobfiles import FileStorage |
|
1467
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1442
diff
changeset
|
29 from sessions import Sessions, OneTimeKeys |
|
818
254b8d112eec
cleaned up the indexer code:
Richard Jones <richard@users.sourceforge.net>
parents:
787
diff
changeset
|
30 from roundup.indexer import Indexer |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
31 from roundup.backends import locking |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
32 from roundup.hyperdb import String, Password, Date, Interval, Link, \ |
|
1417
472c21af7f69
fixed error in indexargs_url (thanks Patrick Ohly)
Richard Jones <richard@users.sourceforge.net>
parents:
1409
diff
changeset
|
33 Multilink, DatabaseError, Boolean, Number, Node |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
34 from roundup.date import Range |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 |
|
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 # Now the database |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 # |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
39 class Database(FileStorage, hyperdb.Database, roundupdb.Database): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
40 '''A database for storing records containing flexible data types. |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
41 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
42 Transaction stuff TODO: |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
43 . check the timestamp of the class file and nuke the cache if it's |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
44 modified. Do some sort of conflict checking on the dirty stuff. |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
45 . perhaps detect write collisions (related to above)? |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
46 |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
47 ''' |
|
524
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
48 def __init__(self, config, journaltag=None): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
49 '''Open a hyperdatabase given a specifier to some storage. |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 |
|
524
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
51 The 'storagelocator' is obtained from config.DATABASE. |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 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
|
58 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
|
59 None, the database is opened in read-only mode: the Class.create(), |
|
1519
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
60 Class.set(), Class.retire(), and Class.restore() methods are |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
61 disabled. |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
62 ''' |
|
524
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
63 self.config, self.journaltag = config, journaltag |
|
dce4c75bef5a
changed all config accesses...
Richard Jones <richard@users.sourceforge.net>
parents:
475
diff
changeset
|
64 self.dir = config.DATABASE |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 self.classes = {} |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
66 self.cache = {} # cache of nodes loaded or created |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
67 self.dirtynodes = {} # keep track of the dirty nodes by class |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
68 self.newnodes = {} # keep track of the new nodes by class |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
69 self.destroyednodes = {}# keep track of the destroyed nodes by class |
|
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
|
70 self.transactions = [] |
|
818
254b8d112eec
cleaned up the indexer code:
Richard Jones <richard@users.sourceforge.net>
parents:
787
diff
changeset
|
71 self.indexer = Indexer(self.dir) |
|
916
76b783c69976
Session storage in the hyperdb was horribly, horribly inefficient.
Richard Jones <richard@users.sourceforge.net>
parents:
905
diff
changeset
|
72 self.sessions = Sessions(self.config) |
|
1467
378081f066cc
registration is now a two-step process with confirmation from the
Richard Jones <richard@users.sourceforge.net>
parents:
1442
diff
changeset
|
73 self.otks = OneTimeKeys(self.config) |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
74 self.security = security.Security(self) |
|
697
210e1ae39ab1
All database files are now created group readable and writable.
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
690
diff
changeset
|
75 # ensure files are group readable and writable |
|
210e1ae39ab1
All database files are now created group readable and writable.
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
690
diff
changeset
|
76 os.umask(0002) |
|
440
de5bf4191f11
Enabled transaction support in the bsddb backend.
Richard Jones <richard@users.sourceforge.net>
parents:
431
diff
changeset
|
77 |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
78 # lock it |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
79 lockfilenm = os.path.join(self.dir, 'lock') |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
80 self.lockfile = locking.acquire_lock(lockfilenm) |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
81 self.lockfile.write(str(os.getpid())) |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
82 self.lockfile.flush() |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
83 |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
84 def post_init(self): |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
85 ''' Called once the schema initialisation has finished. |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
86 ''' |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
87 # reindex the db if necessary |
|
826
6d7a45c8464a
Added reindex command to roundup-admin.
Richard Jones <richard@users.sourceforge.net>
parents:
825
diff
changeset
|
88 if self.indexer.should_reindex(): |
|
6d7a45c8464a
Added reindex command to roundup-admin.
Richard Jones <richard@users.sourceforge.net>
parents:
825
diff
changeset
|
89 self.reindex() |
|
6d7a45c8464a
Added reindex command to roundup-admin.
Richard Jones <richard@users.sourceforge.net>
parents:
825
diff
changeset
|
90 |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
91 # figure the "curuserid" |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
92 if self.journaltag is None: |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
93 self.curuserid = None |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
94 elif self.journaltag == 'admin': |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
95 # admin user may not exist, but always has ID 1 |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
96 self.curuserid = '1' |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
97 else: |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
98 self.curuserid = self.user.lookup(self.journaltag) |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
99 |
|
826
6d7a45c8464a
Added reindex command to roundup-admin.
Richard Jones <richard@users.sourceforge.net>
parents:
825
diff
changeset
|
100 def reindex(self): |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
101 for klass in self.classes.values(): |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
102 for nodeid in klass.list(): |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
103 klass.index(nodeid) |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
104 self.indexer.save_index() |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
105 |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
106 def __repr__(self): |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
107 return '<back_anydbm instance at %x>'%id(self) |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
108 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 # Classes |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
111 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
112 def __getattr__(self, classname): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
113 '''A convenient way of calling self.getclass(classname).''' |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
114 if self.classes.has_key(classname): |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
115 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
116 print >>hyperdb.DEBUG, '__getattr__', (self, classname) |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
117 return self.classes[classname] |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
118 raise AttributeError, classname |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
119 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
120 def addclass(self, cl): |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
121 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
122 print >>hyperdb.DEBUG, 'addclass', (self, cl) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
123 cn = cl.classname |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 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
|
125 raise ValueError, cn |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
126 self.classes[cn] = cl |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
127 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
128 def getclasses(self): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
129 '''Return a list of the names of all existing classes.''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
130 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
131 print >>hyperdb.DEBUG, 'getclasses', (self,) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
132 l = self.classes.keys() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 l.sort() |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 return l |
|
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 def getclass(self, classname): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
137 '''Get the Class object representing a particular class. |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
138 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
139 If 'classname' is not a valid class name, a KeyError is raised. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
140 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
141 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
142 print >>hyperdb.DEBUG, 'getclass', (self, classname) |
|
1145
81941abedb0a
nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents:
1143
diff
changeset
|
143 try: |
|
81941abedb0a
nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents:
1143
diff
changeset
|
144 return self.classes[classname] |
|
81941abedb0a
nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents:
1143
diff
changeset
|
145 except KeyError: |
|
81941abedb0a
nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents:
1143
diff
changeset
|
146 raise KeyError, 'There is no class called "%s"'%classname |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
147 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
148 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
149 # Class DBs |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
150 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
151 def clear(self): |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
152 '''Delete all database contents |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
153 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
154 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
155 print >>hyperdb.DEBUG, 'clear', (self,) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
156 for cn in self.classes.keys(): |
|
650
9b2575610953
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
646
diff
changeset
|
157 for dummy in 'nodes', 'journals': |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
158 path = os.path.join(self.dir, 'journals.%s'%cn) |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
159 if os.path.exists(path): |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
160 os.remove(path) |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
161 elif os.path.exists(path+'.db'): # dbm appends .db |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
162 os.remove(path+'.db') |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
163 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
164 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
|
165 ''' 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
|
166 multiple actions |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
167 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
168 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
169 print >>hyperdb.DEBUG, 'getclassdb', (self, classname, mode) |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
170 return self.opendb('nodes.%s'%classname, mode) |
|
444
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
171 |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
172 def determine_db_type(self, path): |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
173 ''' determine which DB wrote the class file |
|
444
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
174 ''' |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
175 db_type = '' |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
176 if os.path.exists(path): |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
177 db_type = whichdb.whichdb(path) |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
178 if not db_type: |
| 1143 | 179 raise DatabaseError, "Couldn't identify database type" |
|
444
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
180 elif os.path.exists(path+'.db'): |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
181 # if the path ends in '.db', it's a dbm database, whether |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
182 # anydbm says it's dbhash or not! |
|
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
183 db_type = 'dbm' |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
184 return db_type |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
185 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
186 def opendb(self, name, mode): |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
187 '''Low-level database opener that gets around anydbm/dbm |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
188 eccentricities. |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
189 ''' |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
190 if __debug__: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
191 print >>hyperdb.DEBUG, 'opendb', (self, name, mode) |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
192 |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
193 # figure the class db type |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
194 path = os.path.join(os.getcwd(), self.dir, name) |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
195 db_type = self.determine_db_type(path) |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
196 |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
197 # new database? let anydbm pick the best dbm |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
198 if not db_type: |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
199 if __debug__: |
|
1028
16498e77e3ff
allow overiding of the index args roundup/cgi/templating.py
Richard Jones <richard@users.sourceforge.net>
parents:
1022
diff
changeset
|
200 print >>hyperdb.DEBUG, "opendb anydbm.open(%r, 'c')"%path |
|
16498e77e3ff
allow overiding of the index args roundup/cgi/templating.py
Richard Jones <richard@users.sourceforge.net>
parents:
1022
diff
changeset
|
201 return anydbm.open(path, 'c') |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
202 |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
203 # open the database with the correct module |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
204 try: |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
205 dbm = __import__(db_type) |
|
444
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
206 except ImportError: |
| 1143 | 207 raise DatabaseError, \ |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
208 "Couldn't open database - the required module '%s'"\ |
|
818
254b8d112eec
cleaned up the indexer code:
Richard Jones <richard@users.sourceforge.net>
parents:
787
diff
changeset
|
209 " is not available"%db_type |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
210 if __debug__: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
211 print >>hyperdb.DEBUG, "opendb %r.open(%r, %r)"%(db_type, path, |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
212 mode) |
|
443
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
213 return dbm.open(path, mode) |
|
a0c598702f17
I fixed the problems with anydbm using the dbm module at the backend.
Richard Jones <richard@users.sourceforge.net>
parents:
440
diff
changeset
|
214 |
|
690
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
215 # |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
216 # Node IDs |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
217 # |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
218 def newid(self, classname): |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
219 ''' Generate a new id for the given class |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
220 ''' |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
221 # open the ids DB - create if if doesn't exist |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
222 db = self.opendb('_ids', 'c') |
|
690
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
223 if db.has_key(classname): |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
224 newid = db[classname] = str(int(db[classname]) + 1) |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
225 else: |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
226 # the count() bit is transitional - older dbs won't start at 1 |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
227 newid = str(self.getclass(classname).count()+1) |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
228 db[classname] = newid |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
229 db.close() |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
230 return newid |
|
509a101305da
node ids are now generated from a lockable store - no more race conditions
Richard Jones <richard@users.sourceforge.net>
parents:
676
diff
changeset
|
231 |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
232 def setid(self, classname, setid): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
233 ''' Set the id counter: used during import of database |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
234 ''' |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
235 # open the ids DB - create if if doesn't exist |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
236 db = self.opendb('_ids', 'c') |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
237 db[classname] = str(setid) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
238 db.close() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
239 |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
240 # |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
241 # Nodes |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
242 # |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
243 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
|
244 ''' 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
|
245 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
246 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
247 print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node) |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
248 |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
249 # we'll be supplied these props if we're doing an import |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
250 if not node.has_key('creator'): |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
251 # add in the "calculated" properties (dupe so we don't affect |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
252 # calling code's node assumptions) |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
253 node = node.copy() |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
254 node['creator'] = self.curuserid |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
255 node['creation'] = node['activity'] = date.Date() |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
256 |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
257 self.newnodes.setdefault(classname, {})[nodeid] = 1 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
258 self.cache.setdefault(classname, {})[nodeid] = node |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
259 self.savenode(classname, nodeid, node) |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
260 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
261 def setnode(self, classname, nodeid, node): |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
262 ''' change the specified node |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
263 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
264 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
265 print >>hyperdb.DEBUG, 'setnode', (self, classname, nodeid, node) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
266 self.dirtynodes.setdefault(classname, {})[nodeid] = 1 |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
267 |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
268 # update the activity time (dupe so we don't affect |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
269 # calling code's node assumptions) |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
270 node = node.copy() |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
271 node['activity'] = date.Date() |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
272 |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
273 # can't set without having already loaded the node |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
274 self.cache[classname][nodeid] = node |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
275 self.savenode(classname, nodeid, node) |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
276 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
277 def savenode(self, classname, nodeid, node): |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
278 ''' perform the saving of data specified by the set/addnode |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
279 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
280 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
281 print >>hyperdb.DEBUG, 'savenode', (self, classname, nodeid, node) |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
282 self.transactions.append((self.doSaveNode, (classname, nodeid, node))) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
283 |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
464
diff
changeset
|
284 def getnode(self, classname, nodeid, db=None, cache=1): |
|
460
9c895b44240a
take a copy of the node dict...
Richard Jones <richard@users.sourceforge.net>
parents:
452
diff
changeset
|
285 ''' get a node from the database |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
286 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
287 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
288 print >>hyperdb.DEBUG, 'getnode', (self, classname, nodeid, db) |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
464
diff
changeset
|
289 if cache: |
|
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
464
diff
changeset
|
290 # try the cache |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
291 cache_dict = self.cache.setdefault(classname, {}) |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
292 if cache_dict.has_key(nodeid): |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
293 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
294 print >>hyperdb.TRACE, 'get %s %s cached'%(classname, |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
295 nodeid) |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
296 return cache_dict[nodeid] |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
297 |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
298 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
299 print >>hyperdb.TRACE, 'get %s %s'%(classname, nodeid) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
300 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
301 # get from the database and save in the cache |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
302 if db is None: |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
303 db = self.getclassdb(classname) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
304 if not db.has_key(nodeid): |
|
1424
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
305 # try the cache - might be a brand-new node |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
306 cache_dict = self.cache.setdefault(classname, {}) |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
307 if cache_dict.has_key(nodeid): |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
308 if __debug__: |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
309 print >>hyperdb.TRACE, 'get %s %s cached'%(classname, |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
310 nodeid) |
|
6709b759b16a
anydbm should return brand new items, even if cache is turned off
Richard Jones <richard@users.sourceforge.net>
parents:
1417
diff
changeset
|
311 return cache_dict[nodeid] |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
464
diff
changeset
|
312 raise IndexError, "no such %s %s"%(classname, nodeid) |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
313 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
314 # check the uncommitted, destroyed nodes |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
315 if (self.destroyednodes.has_key(classname) and |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
316 self.destroyednodes[classname].has_key(nodeid)): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
317 raise IndexError, "no such %s %s"%(classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
318 |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
319 # decode |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
320 res = marshal.loads(db[nodeid]) |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
321 |
|
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
322 # reverse the serialisation |
|
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
323 res = self.unserialise(classname, res) |
|
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
324 |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
325 # store off in the cache dict |
|
475
a1a44636bace
Fix breakage caused by transaction changes.
Richard Jones <richard@users.sourceforge.net>
parents:
464
diff
changeset
|
326 if cache: |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
327 cache_dict[nodeid] = res |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
328 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
329 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
330 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
331 def destroynode(self, classname, nodeid): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
332 '''Remove a node from the database. Called exclusively by the |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
333 destroy() method on Class. |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
334 ''' |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
335 if __debug__: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
336 print >>hyperdb.DEBUG, 'destroynode', (self, classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
337 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
338 # remove from cache and newnodes if it's there |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
339 if (self.cache.has_key(classname) and |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
340 self.cache[classname].has_key(nodeid)): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
341 del self.cache[classname][nodeid] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
342 if (self.newnodes.has_key(classname) and |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
343 self.newnodes[classname].has_key(nodeid)): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
344 del self.newnodes[classname][nodeid] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
345 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
346 # see if there's any obvious commit actions that we should get rid of |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
347 for entry in self.transactions[:]: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
348 if entry[1][:2] == (classname, nodeid): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
349 self.transactions.remove(entry) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
350 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
351 # add to the destroyednodes map |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
352 self.destroyednodes.setdefault(classname, {})[nodeid] = 1 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
353 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
354 # add the destroy commit action |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
355 self.transactions.append((self.doDestroyNode, (classname, nodeid))) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
356 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
357 def serialise(self, classname, node): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
358 '''Copy the node contents, converting non-marshallable data into |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
359 marshallable data. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
360 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
361 if __debug__: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
362 print >>hyperdb.DEBUG, 'serialise', classname, node |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
363 properties = self.getclass(classname).getprops() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
364 d = {} |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
365 for k, v in node.items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
366 # if the property doesn't exist, or is the "retired" flag then |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
367 # it won't be in the properties dict |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
368 if not properties.has_key(k): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
369 d[k] = v |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
370 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
371 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
372 # get the property spec |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
373 prop = properties[k] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
374 |
|
1252
209a47ede743
allow blank passwords again [SF#619714]
Richard Jones <richard@users.sourceforge.net>
parents:
1249
diff
changeset
|
375 if isinstance(prop, Password) and v is not None: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
376 d[k] = str(v) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
377 elif isinstance(prop, Date) and v is not None: |
|
964
832d1209aaa2
Preparing to turn back on link/unlink journal events.
Richard Jones <richard@users.sourceforge.net>
parents:
952
diff
changeset
|
378 d[k] = v.serialise() |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
379 elif isinstance(prop, Interval) and v is not None: |
|
964
832d1209aaa2
Preparing to turn back on link/unlink journal events.
Richard Jones <richard@users.sourceforge.net>
parents:
952
diff
changeset
|
380 d[k] = v.serialise() |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
381 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
382 d[k] = v |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
383 return d |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
384 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
385 def unserialise(self, classname, node): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
386 '''Decode the marshalled node data |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
387 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
388 if __debug__: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
389 print >>hyperdb.DEBUG, 'unserialise', classname, node |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
390 properties = self.getclass(classname).getprops() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
391 d = {} |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
392 for k, v in node.items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
393 # if the property doesn't exist, or is the "retired" flag then |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
394 # it won't be in the properties dict |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
395 if not properties.has_key(k): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
396 d[k] = v |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
397 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
398 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
399 # get the property spec |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
400 prop = properties[k] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
401 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
402 if isinstance(prop, Date) and v is not None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
403 d[k] = date.Date(v) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
404 elif isinstance(prop, Interval) and v is not None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
405 d[k] = date.Interval(v) |
|
1252
209a47ede743
allow blank passwords again [SF#619714]
Richard Jones <richard@users.sourceforge.net>
parents:
1249
diff
changeset
|
406 elif isinstance(prop, Password) and v is not None: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
407 p = password.Password() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
408 p.unpack(v) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
409 d[k] = p |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
410 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
411 d[k] = v |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
412 return d |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
413 |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
414 def hasnode(self, classname, nodeid, db=None): |
|
460
9c895b44240a
take a copy of the node dict...
Richard Jones <richard@users.sourceforge.net>
parents:
452
diff
changeset
|
415 ''' determine if the database has a given node |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
416 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
417 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
418 print >>hyperdb.DEBUG, 'hasnode', (self, classname, nodeid, db) |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
419 |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
420 # try the cache |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
421 cache = self.cache.setdefault(classname, {}) |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
422 if cache.has_key(nodeid): |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
423 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
424 print >>hyperdb.TRACE, 'has %s %s cached'%(classname, nodeid) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
425 return 1 |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
426 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
427 print >>hyperdb.TRACE, 'has %s %s'%(classname, nodeid) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
428 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
429 # not in the cache - check the database |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
430 if db is None: |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
431 db = self.getclassdb(classname) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
432 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
|
433 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
434 |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
435 def countnodes(self, classname, db=None): |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
436 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
437 print >>hyperdb.DEBUG, 'countnodes', (self, classname, db) |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
438 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
439 count = 0 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
440 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
441 # include the uncommitted nodes |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
442 if self.newnodes.has_key(classname): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
443 count += len(self.newnodes[classname]) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
444 if self.destroyednodes.has_key(classname): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
445 count -= len(self.destroyednodes[classname]) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
446 |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
447 # and count those in the DB |
|
452
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
448 if db is None: |
|
7181efddce66
yuck, a gdbm instance tests false :(
Richard Jones <richard@users.sourceforge.net>
parents:
444
diff
changeset
|
449 db = self.getclassdb(classname) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
450 count = count + len(db.keys()) |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
451 return count |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
452 |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
453 |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
454 # |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
455 # Files - special node properties |
|
646
07abfe8f0c01
use blobfiles in back_anydbm which is used in back_bsddb.
Engelbert Gruber <grubert@users.sourceforge.net>
parents:
624
diff
changeset
|
456 # inherited from FileStorage |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
457 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
458 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
459 # Journal |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
460 # |
| 1143 | 461 def addjournal(self, classname, nodeid, action, params, creator=None, |
| 462 creation=None): | |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
463 ''' Journal the Action |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
464 'action' may be: |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
465 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
466 '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
|
467 '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
|
468 'retire' -- 'params' is None |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
469 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
470 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
471 print >>hyperdb.DEBUG, 'addjournal', (self, classname, nodeid, |
| 1143 | 472 action, params, creator, creation) |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
473 self.transactions.append((self.doSaveJournal, (classname, nodeid, |
| 1143 | 474 action, params, creator, creation))) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
475 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
476 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
|
477 ''' get the journal for id |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
478 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
479 Raise IndexError if the node doesn't exist (as per history()'s |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
480 API) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
481 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
482 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
483 print >>hyperdb.DEBUG, 'getjournal', (self, classname, nodeid) |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
484 # 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
|
485 # not exist |
|
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
486 try: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
487 db = self.opendb('journals.%s'%classname, 'r') |
|
444
3fa2268041a8
Cor blimey this anydbm/whichdb stuff is yecchy.
Richard Jones <richard@users.sourceforge.net>
parents:
443
diff
changeset
|
488 except anydbm.error, error: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
489 if str(error) == "need 'c' or 'n' flag to open new db": |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
490 raise IndexError, 'no such %s %s'%(classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
491 elif error.args[0] != 2: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
492 raise |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
493 raise IndexError, 'no such %s %s'%(classname, nodeid) |
|
787
b6b0a92e0738
More informative error message
Richard Jones <richard@users.sourceforge.net>
parents:
778
diff
changeset
|
494 try: |
|
b6b0a92e0738
More informative error message
Richard Jones <richard@users.sourceforge.net>
parents:
778
diff
changeset
|
495 journal = marshal.loads(db[nodeid]) |
|
b6b0a92e0738
More informative error message
Richard Jones <richard@users.sourceforge.net>
parents:
778
diff
changeset
|
496 except KeyError: |
|
843
01f9d02faea1
...except of course it's nice to use valid Python syntax
Richard Jones <richard@users.sourceforge.net>
parents:
842
diff
changeset
|
497 db.close() |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
498 raise IndexError, 'no such %s %s'%(classname, nodeid) |
|
843
01f9d02faea1
...except of course it's nice to use valid Python syntax
Richard Jones <richard@users.sourceforge.net>
parents:
842
diff
changeset
|
499 db.close() |
|
48
671203878652
Moved over to using marshal in the bsddb and anydbm backends.
Richard Jones <richard@users.sourceforge.net>
parents:
46
diff
changeset
|
500 res = [] |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
501 for nodeid, date_stamp, user, action, params in journal: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
502 res.append((nodeid, date.Date(date_stamp), user, action, params)) |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
503 return res |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
504 |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
505 def pack(self, pack_before): |
| 990 | 506 ''' Delete all journal entries except "create" before 'pack_before'. |
| 507 ''' | |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
508 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
509 print >>hyperdb.DEBUG, 'packjournal', (self, pack_before) |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
510 |
|
1222
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
511 pack_before = pack_before.serialise() |
| 990 | 512 for classname in self.getclasses(): |
| 513 # get the journal db | |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
514 db_name = 'journals.%s'%classname |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
515 path = os.path.join(os.getcwd(), self.dir, classname) |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
516 db_type = self.determine_db_type(path) |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
517 db = self.opendb(db_name, 'w') |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
518 |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
519 for key in db.keys(): |
| 990 | 520 # get the journal for this db entry |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
521 journal = marshal.loads(db[key]) |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
522 l = [] |
|
567
9ca63f7332a7
last_set_entry was referenced before assignment
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
566
diff
changeset
|
523 last_set_entry = None |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
524 for entry in journal: |
| 990 | 525 # unpack the entry |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
526 (nodeid, date_stamp, self.journaltag, action, |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
527 params) = entry |
| 990 | 528 # if the entry is after the pack date, _or_ the initial |
| 529 # create entry, then it stays | |
|
562
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
530 if date_stamp > pack_before or action == 'create': |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
531 l.append(entry) |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
532 db[key] = marshal.dumps(l) |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
533 if db_type == 'gdbm': |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
534 db.reorganize() |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
535 db.close() |
|
62febbd7ffec
You can now use the roundup-admin tool to pack the database
Roche Compaan <rochecompaan@users.sourceforge.net>
parents:
553
diff
changeset
|
536 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
537 |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
538 # |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
539 # Basic transaction support |
|
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
540 # |
|
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
|
541 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
|
542 ''' 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
|
543 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
544 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
545 print >>hyperdb.DEBUG, 'commit', (self,) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
546 |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
547 # keep a handle to all the database files opened |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
548 self.databases = {} |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
549 |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
550 # now, do all the transactions |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
551 reindex = {} |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
552 for method, args in self.transactions: |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
553 reindex[method(*args)] = 1 |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
554 |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
555 # now close all the database files |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
556 for db in self.databases.values(): |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
557 db.close() |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
558 del self.databases |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
559 |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
560 # reindex the nodes that request it |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
561 for classname, nodeid in filter(None, reindex.keys()): |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
562 print >>hyperdb.DEBUG, 'commit.reindex', (classname, nodeid) |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
563 self.getclass(classname).index(nodeid) |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
564 |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
565 # save the indexer state |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
566 self.indexer.save_index() |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
567 |
|
1181
49aebf5a8691
some speedups, some fixes to the benchmarking
Richard Jones <richard@users.sourceforge.net>
parents:
1176
diff
changeset
|
568 self.clearCache() |
|
49aebf5a8691
some speedups, some fixes to the benchmarking
Richard Jones <richard@users.sourceforge.net>
parents:
1176
diff
changeset
|
569 |
|
49aebf5a8691
some speedups, some fixes to the benchmarking
Richard Jones <richard@users.sourceforge.net>
parents:
1176
diff
changeset
|
570 def clearCache(self): |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
571 # all transactions committed, back to normal |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
572 self.cache = {} |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
573 self.dirtynodes = {} |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
574 self.newnodes = {} |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
575 self.destroyednodes = {} |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
576 self.transactions = [] |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
577 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
578 def getCachedClassDB(self, classname): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
579 ''' get the class db, looking in our cache of databases for commit |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
580 ''' |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
581 # get the database handle |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
582 db_name = 'nodes.%s'%classname |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
583 if not self.databases.has_key(db_name): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
584 self.databases[db_name] = self.getclassdb(classname, 'c') |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
585 return self.databases[db_name] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
586 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
587 def doSaveNode(self, classname, nodeid, node): |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
588 if __debug__: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
589 print >>hyperdb.DEBUG, 'doSaveNode', (self, classname, nodeid, |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
590 node) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
591 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
592 db = self.getCachedClassDB(classname) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
593 |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
594 # now save the marshalled data |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
595 db[nodeid] = marshal.dumps(self.serialise(classname, node)) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
596 |
|
825
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
597 # return the classname, nodeid so we reindex this content |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
598 return (classname, nodeid) |
|
0779ea9f1f18
More indexer work:
Richard Jones <richard@users.sourceforge.net>
parents:
818
diff
changeset
|
599 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
600 def getCachedJournalDB(self, classname): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
601 ''' get the journal db, looking in our cache of databases for commit |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
602 ''' |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
603 # get the database handle |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
604 db_name = 'journals.%s'%classname |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
605 if not self.databases.has_key(db_name): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
606 self.databases[db_name] = self.opendb(db_name, 'c') |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
607 return self.databases[db_name] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
608 |
| 1143 | 609 def doSaveJournal(self, classname, nodeid, action, params, creator, |
| 610 creation): | |
| 611 # serialise the parameters now if necessary | |
| 612 if isinstance(params, type({})): | |
| 613 if action in ('set', 'create'): | |
| 614 params = self.serialise(classname, params) | |
| 615 | |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
616 # handle supply of the special journalling parameters (usually |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
617 # supplied on importing an existing database) |
| 1143 | 618 if creator: |
| 619 journaltag = creator | |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
620 else: |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
621 journaltag = self.curuserid |
| 1143 | 622 if creation: |
| 623 journaldate = creation.serialise() | |
| 624 else: | |
|
964
832d1209aaa2
Preparing to turn back on link/unlink journal events.
Richard Jones <richard@users.sourceforge.net>
parents:
952
diff
changeset
|
625 journaldate = date.Date().serialise() |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
626 |
|
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
627 # create the journal entry |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
628 entry = (nodeid, journaldate, journaltag, action, params) |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
629 |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
630 if __debug__: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
631 print >>hyperdb.DEBUG, 'doSaveJournal', entry |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
632 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
633 db = self.getCachedJournalDB(classname) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
634 |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
635 # now insert the journal entry |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
636 if db.has_key(nodeid): |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
637 # append to existing |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
638 s = db[nodeid] |
|
650
9b2575610953
Ran it through pychecker, made fixes
Richard Jones <richard@users.sourceforge.net>
parents:
646
diff
changeset
|
639 l = marshal.loads(s) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
640 l.append(entry) |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
641 else: |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
642 l = [entry] |
|
676
bc46480e2a2b
Fixed serialisation problem...
Richard Jones <richard@users.sourceforge.net>
parents:
650
diff
changeset
|
643 |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
644 db[nodeid] = marshal.dumps(l) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
645 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
646 def doDestroyNode(self, classname, nodeid): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
647 if __debug__: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
648 print >>hyperdb.DEBUG, 'doDestroyNode', (self, classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
649 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
650 # delete from the class database |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
651 db = self.getCachedClassDB(classname) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
652 if db.has_key(nodeid): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
653 del db[nodeid] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
654 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
655 # delete from the database |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
656 db = self.getCachedJournalDB(classname) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
657 if db.has_key(nodeid): |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
658 del db[nodeid] |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
659 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
660 # return the classname, nodeid so we reindex this content |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
661 return (classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
662 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
663 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
|
664 ''' 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
|
665 ''' |
|
719
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
666 if __debug__: |
|
fed4c363a7f3
node caching now works, and gives a small boost in performance
Richard Jones <richard@users.sourceforge.net>
parents:
697
diff
changeset
|
667 print >>hyperdb.DEBUG, 'rollback', (self, ) |
|
461
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
668 for method, args in self.transactions: |
|
b579418f7ed1
Implemented file store rollback.
Richard Jones <richard@users.sourceforge.net>
parents:
460
diff
changeset
|
669 # delete temporary files |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
670 if method == self.doStoreFile: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
671 self.rollbackStoreFile(*args) |
|
430
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
672 self.cache = {} |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
673 self.dirtynodes = {} |
|
350685601f37
Database transactions.
Richard Jones <richard@users.sourceforge.net>
parents:
394
diff
changeset
|
674 self.newnodes = {} |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
675 self.destroyednodes = {} |
|
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
|
676 self.transactions = [] |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
677 |
|
1131
92e92ae58494
add close() methods where they are missing!
Richard Jones <richard@users.sourceforge.net>
parents:
1127
diff
changeset
|
678 def close(self): |
|
92e92ae58494
add close() methods where they are missing!
Richard Jones <richard@users.sourceforge.net>
parents:
1127
diff
changeset
|
679 ''' Nothing to do |
|
92e92ae58494
add close() methods where they are missing!
Richard Jones <richard@users.sourceforge.net>
parents:
1127
diff
changeset
|
680 ''' |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
681 if self.lockfile is not None: |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
682 locking.release_lock(self.lockfile) |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
683 if self.lockfile is not None: |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
684 self.lockfile.close() |
|
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
685 self.lockfile = None |
|
1131
92e92ae58494
add close() methods where they are missing!
Richard Jones <richard@users.sourceforge.net>
parents:
1127
diff
changeset
|
686 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
687 _marker = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
688 class Class(hyperdb.Class): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
689 '''The handle to a particular class of nodes in a hyperdatabase.''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
690 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
691 def __init__(self, db, classname, **properties): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
692 '''Create a new class with a given name and property specification. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
693 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
694 'classname' must not collide with the name of an existing class, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
695 or a ValueError is raised. The keyword arguments in 'properties' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
696 must map names to property objects, or a TypeError is raised. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
697 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
698 if (properties.has_key('creation') or properties.has_key('activity') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
699 or properties.has_key('creator')): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
700 raise ValueError, '"creation", "activity" and "creator" are '\ |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
701 'reserved' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
702 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
703 self.classname = classname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
704 self.properties = properties |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
705 self.db = weakref.proxy(db) # use a weak ref to avoid circularity |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
706 self.key = '' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
707 |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
708 # should we journal changes (default yes) |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
709 self.do_journal = 1 |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
710 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
711 # do the db-related init stuff |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
712 db.addclass(self) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
713 |
|
1519
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
714 self.auditors = {'create': [], 'set': [], 'retire': [], 'restore': []} |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
715 self.reactors = {'create': [], 'set': [], 'retire': [], 'restore': []} |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
716 |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
717 def enableJournalling(self): |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
718 '''Turn journalling on for this class |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
719 ''' |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
720 self.do_journal = 1 |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
721 |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
722 def disableJournalling(self): |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
723 '''Turn journalling off for this class |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
724 ''' |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
725 self.do_journal = 0 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
726 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
727 # Editing nodes: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
728 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
729 def create(self, **propvalues): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
730 '''Create a new node of this class and return its id. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
731 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
732 The keyword arguments in 'propvalues' map property names to values. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
733 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
734 The values of arguments must be acceptable for the types of their |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
735 corresponding properties or a TypeError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
736 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
737 If this class has a key property, it must be present and its value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
738 must not collide with other key strings or a ValueError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
739 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
740 Any other properties on this class that are missing from the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
741 'propvalues' dictionary are set to None. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
742 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
743 If an id in a link or multilink property does not refer to a valid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
744 node, an IndexError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
745 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
746 These operations trigger detectors and can be vetoed. Attempts |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
747 to modify the "creation" or "activity" properties cause a KeyError. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
748 ''' |
|
1431
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
749 self.fireAuditors('create', None, propvalues) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
750 newid = self.create_inner(**propvalues) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
751 self.fireReactors('create', newid, None) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
752 return newid |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
753 |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
754 def create_inner(self, **propvalues): |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
755 ''' Called by create, in-between the audit and react calls. |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
756 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
757 if propvalues.has_key('id'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
758 raise KeyError, '"id" is reserved' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
759 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
760 if self.db.journaltag is None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
761 raise DatabaseError, 'Database open read-only' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
762 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
763 if propvalues.has_key('creation') or propvalues.has_key('activity'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
764 raise KeyError, '"creation" and "activity" are reserved' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
765 # new node's id |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
766 newid = self.db.newid(self.classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
767 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
768 # validate propvalues |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
769 num_re = re.compile('^\d+$') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
770 for key, value in propvalues.items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
771 if key == self.key: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
772 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
773 self.lookup(value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
774 except KeyError: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
775 pass |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
776 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
777 raise ValueError, 'node with key "%s" exists'%value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
778 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
779 # try to handle this property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
780 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
781 prop = self.properties[key] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
782 except KeyError: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
783 raise KeyError, '"%s" has no property "%s"'%(self.classname, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
784 key) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
785 |
|
950
cb821cc1c00b
handle "unset" initial Link values (!)
Richard Jones <richard@users.sourceforge.net>
parents:
940
diff
changeset
|
786 if value is not None and isinstance(prop, Link): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
787 if type(value) != type(''): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
788 raise ValueError, 'link value must be String' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
789 link_class = self.properties[key].classname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
790 # if it isn't a number, it's a key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
791 if not num_re.match(value): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
792 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
793 value = self.db.classes[link_class].lookup(value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
794 except (TypeError, KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
795 raise IndexError, 'new property "%s": %s not a %s'%( |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
796 key, value, link_class) |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
797 elif not self.db.getclass(link_class).hasnode(value): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
798 raise IndexError, '%s has no node %s'%(link_class, value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
799 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
800 # save off the value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
801 propvalues[key] = value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
802 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
803 # register the link with the newly linked node |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
804 if self.do_journal and self.properties[key].do_journal: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
805 self.db.addjournal(link_class, value, 'link', |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
806 (self.classname, newid, key)) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
807 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
808 elif isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
809 if type(value) != type([]): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
810 raise TypeError, 'new property "%s" not a list of ids'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
811 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
812 # clean up and validate the list of links |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
813 link_class = self.properties[key].classname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
814 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
815 for entry in value: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
816 if type(entry) != type(''): |
| 1049 | 817 raise ValueError, '"%s" multilink value (%r) '\ |
|
1045
0564eb2f4bda
better error message
Richard Jones <richard@users.sourceforge.net>
parents:
1038
diff
changeset
|
818 'must contain Strings'%(key, value) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
819 # if it isn't a number, it's a key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
820 if not num_re.match(entry): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
821 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
822 entry = self.db.classes[link_class].lookup(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
823 except (TypeError, KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
824 raise IndexError, 'new property "%s": %s not a %s'%( |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
825 key, entry, self.properties[key].classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
826 l.append(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
827 value = l |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
828 propvalues[key] = value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
829 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
830 # handle additions |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
831 for nodeid in value: |
|
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
832 if not self.db.getclass(link_class).hasnode(nodeid): |
|
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
833 raise IndexError, '%s has no node %s'%(link_class, |
|
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
834 nodeid) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
835 # register the link with the newly linked node |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
836 if self.do_journal and self.properties[key].do_journal: |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
837 self.db.addjournal(link_class, nodeid, 'link', |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
838 (self.classname, newid, key)) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
839 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
840 elif isinstance(prop, String): |
|
1383
f19dde90e473
applied unicode patch
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1351
diff
changeset
|
841 if type(value) != type('') and type(value) != type(u''): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
842 raise TypeError, 'new property "%s" not a string'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
843 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
844 elif isinstance(prop, Password): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
845 if not isinstance(value, password.Password): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
846 raise TypeError, 'new property "%s" not a Password'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
847 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
848 elif isinstance(prop, Date): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
849 if value is not None and not isinstance(value, date.Date): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
850 raise TypeError, 'new property "%s" not a Date'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
851 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
852 elif isinstance(prop, Interval): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
853 if value is not None and not isinstance(value, date.Interval): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
854 raise TypeError, 'new property "%s" not an Interval'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
855 |
|
887
e7169d6e6e45
added tests for number type too
Richard Jones <richard@users.sourceforge.net>
parents:
886
diff
changeset
|
856 elif value is not None and isinstance(prop, Number): |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
857 try: |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
858 float(value) |
|
887
e7169d6e6e45
added tests for number type too
Richard Jones <richard@users.sourceforge.net>
parents:
886
diff
changeset
|
859 except ValueError: |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
860 raise TypeError, 'new property "%s" not numeric'%key |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
861 |
|
887
e7169d6e6e45
added tests for number type too
Richard Jones <richard@users.sourceforge.net>
parents:
886
diff
changeset
|
862 elif value is not None and isinstance(prop, Boolean): |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
863 try: |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
864 int(value) |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
865 except ValueError: |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
866 raise TypeError, 'new property "%s" not boolean'%key |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
867 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
868 # make sure there's data where there needs to be |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
869 for key, prop in self.properties.items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
870 if propvalues.has_key(key): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
871 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
872 if key == self.key: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
873 raise ValueError, 'key property "%s" is required'%key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
874 if isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
875 propvalues[key] = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
876 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
877 propvalues[key] = None |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
878 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
879 # done |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
880 self.db.addnode(self.classname, newid, propvalues) |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
881 if self.do_journal: |
|
1304
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
882 self.db.addjournal(self.classname, newid, 'create', {}) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
883 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
884 return newid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
885 |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
886 def export_list(self, propnames, nodeid): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
887 ''' Export a node - generate a list of CSV-able data in the order |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
888 specified by propnames for the given node. |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
889 ''' |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
890 properties = self.getprops() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
891 l = [] |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
892 for prop in propnames: |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
893 proptype = properties[prop] |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
894 value = self.get(nodeid, prop) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
895 # "marshal" data where needed |
| 1143 | 896 if value is None: |
| 897 pass | |
| 898 elif isinstance(proptype, hyperdb.Date): | |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
899 value = value.get_tuple() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
900 elif isinstance(proptype, hyperdb.Interval): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
901 value = value.get_tuple() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
902 elif isinstance(proptype, hyperdb.Password): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
903 value = str(value) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
904 l.append(repr(value)) |
|
1476
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
905 |
|
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
906 # append retired flag |
|
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
907 l.append(self.is_retired(nodeid)) |
|
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
908 |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
909 return l |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
910 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
911 def import_list(self, propnames, proplist): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
912 ''' Import a node - all information including "id" is present and |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
913 should not be sanity checked. Triggers are not triggered. The |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
914 journal should be initialised using the "creator" and "created" |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
915 information. |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
916 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
917 Return the nodeid of the node imported. |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
918 ''' |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
919 if self.db.journaltag is None: |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
920 raise DatabaseError, 'Database open read-only' |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
921 properties = self.getprops() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
922 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
923 # make the new node's property map |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
924 d = {} |
|
1496
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
925 newid = None |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
926 for i in range(len(propnames)): |
|
1496
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
927 # Figure the property for this column |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
928 propname = propnames[i] |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
929 |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
930 # Use eval to reverse the repr() used to output the CSV |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
931 value = eval(proplist[i]) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
932 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
933 # "unmarshal" where necessary |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
934 if propname == 'id': |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
935 newid = value |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
936 continue |
|
1496
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
937 elif propname == 'is retired': |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
938 # is the item retired? |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
939 if int(value): |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
940 d[self.db.RETIRED_FLAG] = 1 |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
941 continue |
| 1143 | 942 elif value is None: |
| 943 # don't set Nones | |
| 944 continue | |
|
1496
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
945 |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
946 prop = properties[propname] |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
947 if isinstance(prop, hyperdb.Date): |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
948 value = date.Date(value) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
949 elif isinstance(prop, hyperdb.Interval): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
950 value = date.Interval(value) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
951 elif isinstance(prop, hyperdb.Password): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
952 pwd = password.Password() |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
953 pwd.unpack(value) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
954 value = pwd |
| 1143 | 955 d[propname] = value |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
956 |
|
1496
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
957 # get a new id if necessary |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
958 if newid is None: |
|
e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
Richard Jones <richard@users.sourceforge.net>
parents:
1486
diff
changeset
|
959 newid = self.db.newid(self.classname) |
|
1476
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
960 |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
961 # add the node and journal |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
962 self.db.addnode(self.classname, newid, d) |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
963 |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
964 # extract the journalling stuff and nuke it |
| 1143 | 965 if d.has_key('creator'): |
| 966 creator = d['creator'] | |
| 967 del d['creator'] | |
| 968 else: | |
| 969 creator = None | |
| 970 if d.has_key('creation'): | |
| 971 creation = d['creation'] | |
| 972 del d['creation'] | |
| 973 else: | |
| 974 creation = None | |
| 975 if d.has_key('activity'): | |
| 976 del d['activity'] | |
|
1304
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
977 self.db.addjournal(self.classname, newid, 'create', {}, creator, |
| 1143 | 978 creation) |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
979 return newid |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
980 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
981 def get(self, nodeid, propname, default=_marker, cache=1): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
982 '''Get the value of a property on an existing node of this class. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
983 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
984 'nodeid' must be the id of an existing node of this class or an |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
985 IndexError is raised. 'propname' must be the name of a property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
986 of this class or a KeyError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
987 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
988 'cache' indicates whether the transaction cache should be queried |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
989 for the node. If the node has been modified and you need to |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
990 determine what its values prior to modification are, you need to |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
991 set cache=0. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
992 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
993 Attempts to get the "creation" or "activity" properties should |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
994 do the right thing. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
995 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
996 if propname == 'id': |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
997 return nodeid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
998 |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
999 # get the node's dict |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1000 d = self.db.getnode(self.classname, nodeid, cache=cache) |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1001 |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1002 # check for one of the special props |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1003 if propname == 'creation': |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1004 if d.has_key('creation'): |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1005 return d['creation'] |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1006 if not self.do_journal: |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1007 raise ValueError, 'Journalling is disabled for this class' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1008 journal = self.db.getjournal(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1009 if journal: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1010 return self.db.getjournal(self.classname, nodeid)[0][1] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1011 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1012 # on the strange chance that there's no journal |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1013 return date.Date() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1014 if propname == 'activity': |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1015 if d.has_key('activity'): |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1016 return d['activity'] |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1017 if not self.do_journal: |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1018 raise ValueError, 'Journalling is disabled for this class' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1019 journal = self.db.getjournal(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1020 if journal: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1021 return self.db.getjournal(self.classname, nodeid)[-1][1] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1022 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1023 # on the strange chance that there's no journal |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1024 return date.Date() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1025 if propname == 'creator': |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1026 if d.has_key('creator'): |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1027 return d['creator'] |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1028 if not self.do_journal: |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1029 raise ValueError, 'Journalling is disabled for this class' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1030 journal = self.db.getjournal(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1031 if journal: |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1032 num_re = re.compile('^\d+$') |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1033 value = self.db.getjournal(self.classname, nodeid)[0][2] |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1034 if num_re.match(value): |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1035 return value |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1036 else: |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1037 # old-style "username" journal tag |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1038 try: |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1039 return self.db.user.lookup(value) |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1040 except KeyError: |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1041 # user's been retired, return admin |
|
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1042 return '1' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1043 else: |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1044 return self.db.curuserid |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1045 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1046 # get the property (raises KeyErorr if invalid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1047 prop = self.properties[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1048 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1049 if not d.has_key(propname): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1050 if default is _marker: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1051 if isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1052 return [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1053 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1054 return None |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1055 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1056 return default |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1057 |
|
1014
8816534e6a1a
Fixed nasty bug that was preventing changes to multilinks going through.
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
1058 # return a dupe of the list so code doesn't get confused |
|
8816534e6a1a
Fixed nasty bug that was preventing changes to multilinks going through.
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
1059 if isinstance(prop, Multilink): |
|
8816534e6a1a
Fixed nasty bug that was preventing changes to multilinks going through.
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
1060 return d[propname][:] |
|
8816534e6a1a
Fixed nasty bug that was preventing changes to multilinks going through.
Richard Jones <richard@users.sourceforge.net>
parents:
1002
diff
changeset
|
1061 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1062 return d[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1063 |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1064 # not in spec |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1065 def getnode(self, nodeid, cache=1): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1066 ''' Return a convenience wrapper for the node. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1067 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1068 'nodeid' must be the id of an existing node of this class or an |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1069 IndexError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1070 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1071 'cache' indicates whether the transaction cache should be queried |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1072 for the node. If the node has been modified and you need to |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1073 determine what its values prior to modification are, you need to |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1074 set cache=0. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1075 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1076 return Node(self, nodeid, cache=cache) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1077 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1078 def set(self, nodeid, **propvalues): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1079 '''Modify a property on an existing node of this class. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1080 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1081 'nodeid' must be the id of an existing node of this class or an |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1082 IndexError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1083 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1084 Each key in 'propvalues' must be the name of a property of this |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1085 class or a KeyError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1086 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1087 All values in 'propvalues' must be acceptable types for their |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1088 corresponding properties or a TypeError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1089 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1090 If the value of the key property is set, it must not collide with |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1091 other key strings or a ValueError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1092 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1093 If the value of a Link or Multilink property contains an invalid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1094 node id, a ValueError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1095 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1096 These operations trigger detectors and can be vetoed. Attempts |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1097 to modify the "creation" or "activity" properties cause a KeyError. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1098 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1099 if not propvalues: |
|
930
3c344e942055
Use same regex to split search terms as used to index text.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
927
diff
changeset
|
1100 return propvalues |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1101 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1102 if propvalues.has_key('creation') or propvalues.has_key('activity'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1103 raise KeyError, '"creation" and "activity" are reserved' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1104 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1105 if propvalues.has_key('id'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1106 raise KeyError, '"id" is reserved' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1107 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1108 if self.db.journaltag is None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1109 raise DatabaseError, 'Database open read-only' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1110 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1111 self.fireAuditors('set', nodeid, propvalues) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1112 # Take a copy of the node dict so that the subsequent set |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1113 # operation doesn't modify the oldvalues structure. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1114 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1115 # try not using the cache initially |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1116 oldvalues = copy.deepcopy(self.db.getnode(self.classname, nodeid, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1117 cache=0)) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1118 except IndexError: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1119 # this will be needed if somone does a create() and set() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1120 # with no intervening commit() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1121 oldvalues = copy.deepcopy(self.db.getnode(self.classname, nodeid)) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1122 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1123 node = self.db.getnode(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1124 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1125 raise IndexError |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1126 num_re = re.compile('^\d+$') |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1127 |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1128 # if the journal value is to be different, store it in here |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1129 journalvalues = {} |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1130 |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1131 for propname, value in propvalues.items(): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1132 # check to make sure we're not duplicating an existing key |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1133 if propname == self.key and node[propname] != value: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1134 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1135 self.lookup(value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1136 except KeyError: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1137 pass |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1138 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1139 raise ValueError, 'node with key "%s" exists'%value |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1140 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1141 # this will raise the KeyError if the property isn't valid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1142 # ... we don't use getprops() here because we only care about |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1143 # the writeable properties. |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1144 try: |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1145 prop = self.properties[propname] |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1146 except KeyError: |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1147 raise KeyError, '"%s" has no property named "%s"'%( |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1148 self.classname, propname) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1149 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1150 # if the value's the same as the existing value, no sense in |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1151 # doing anything |
|
1304
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
1152 current = node.get(propname, None) |
|
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
1153 if value == current: |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1154 del propvalues[propname] |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1155 continue |
|
1304
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
1156 journalvalues[propname] = current |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1157 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1158 # do stuff based on the prop type |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1159 if isinstance(prop, Link): |
|
927
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1160 link_class = prop.classname |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1161 # if it isn't a number, it's a key |
|
927
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1162 if value is not None and not isinstance(value, type('')): |
|
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1163 raise ValueError, 'property "%s" link value be a string'%( |
|
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1164 propname) |
|
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1165 if isinstance(value, type('')) and not num_re.match(value): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1166 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1167 value = self.db.classes[link_class].lookup(value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1168 except (TypeError, KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1169 raise IndexError, 'new property "%s": %s not a %s'%( |
|
927
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1170 propname, value, prop.classname) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1171 |
|
927
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1172 if (value is not None and |
|
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1173 not self.db.getclass(link_class).hasnode(value)): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1174 raise IndexError, '%s has no node %s'%(link_class, value) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1175 |
|
927
51519406b73e
web forms may now unset Link values (like assignedto)
Richard Jones <richard@users.sourceforge.net>
parents:
924
diff
changeset
|
1176 if self.do_journal and prop.do_journal: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1177 # register the unlink with the old linked node |
|
1246
46515c0d115e
merge from maint-0-5
Richard Jones <richard@users.sourceforge.net>
parents:
1222
diff
changeset
|
1178 if node.has_key(propname) and node[propname] is not None: |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1179 self.db.addjournal(link_class, node[propname], 'unlink', |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1180 (self.classname, nodeid, propname)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1181 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1182 # register the link with the newly linked node |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1183 if value is not None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1184 self.db.addjournal(link_class, value, 'link', |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1185 (self.classname, nodeid, propname)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1186 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1187 elif isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1188 if type(value) != type([]): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1189 raise TypeError, 'new property "%s" not a list of'\ |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1190 ' ids'%propname |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1191 link_class = self.properties[propname].classname |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1192 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1193 for entry in value: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1194 # if it isn't a number, it's a key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1195 if type(entry) != type(''): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1196 raise ValueError, 'new property "%s" link value ' \ |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1197 'must be a string'%propname |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1198 if not num_re.match(entry): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1199 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1200 entry = self.db.classes[link_class].lookup(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1201 except (TypeError, KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1202 raise IndexError, 'new property "%s": %s not a %s'%( |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1203 propname, entry, |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1204 self.properties[propname].classname) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1205 l.append(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1206 value = l |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1207 propvalues[propname] = value |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1208 |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1209 # figure the journal entry for this property |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1210 add = [] |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1211 remove = [] |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1212 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1213 # handle removals |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1214 if node.has_key(propname): |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1215 l = node[propname] |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1216 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1217 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1218 for id in l[:]: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1219 if id in value: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1220 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1221 # register the unlink with the old linked node |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1222 if self.do_journal and self.properties[propname].do_journal: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1223 self.db.addjournal(link_class, id, 'unlink', |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1224 (self.classname, nodeid, propname)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1225 l.remove(id) |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1226 remove.append(id) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1227 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1228 # handle additions |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1229 for id in value: |
|
902
b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
891
diff
changeset
|
1230 if not self.db.getclass(link_class).hasnode(id): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1231 raise IndexError, '%s has no node %s'%(link_class, id) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1232 if id in l: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1233 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1234 # register the link with the newly linked node |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1235 if self.do_journal and self.properties[propname].do_journal: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1236 self.db.addjournal(link_class, id, 'link', |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1237 (self.classname, nodeid, propname)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1238 l.append(id) |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1239 add.append(id) |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1240 |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1241 # figure the journal entry |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1242 l = [] |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1243 if add: |
|
967
dd35bab19dd9
use more robust date stamp comparisons in pack(), make journal smaller too
Richard Jones <richard@users.sourceforge.net>
parents:
964
diff
changeset
|
1244 l.append(('+', add)) |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1245 if remove: |
|
967
dd35bab19dd9
use more robust date stamp comparisons in pack(), make journal smaller too
Richard Jones <richard@users.sourceforge.net>
parents:
964
diff
changeset
|
1246 l.append(('-', remove)) |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1247 if l: |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1248 journalvalues[propname] = tuple(l) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1249 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1250 elif isinstance(prop, String): |
|
1383
f19dde90e473
applied unicode patch
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1351
diff
changeset
|
1251 if value is not None and type(value) != type('') and type(value) != type(u''): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1252 raise TypeError, 'new property "%s" not a string'%propname |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1253 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1254 elif isinstance(prop, Password): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1255 if not isinstance(value, password.Password): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1256 raise TypeError, 'new property "%s" not a Password'%propname |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1257 propvalues[propname] = value |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1258 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1259 elif value is not None and isinstance(prop, Date): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1260 if not isinstance(value, date.Date): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1261 raise TypeError, 'new property "%s" not a Date'% propname |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1262 propvalues[propname] = value |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1263 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1264 elif value is not None and isinstance(prop, Interval): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1265 if not isinstance(value, date.Interval): |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1266 raise TypeError, 'new property "%s" not an '\ |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1267 'Interval'%propname |
|
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1268 propvalues[propname] = value |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1269 |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1270 elif value is not None and isinstance(prop, Number): |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1271 try: |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1272 float(value) |
|
887
e7169d6e6e45
added tests for number type too
Richard Jones <richard@users.sourceforge.net>
parents:
886
diff
changeset
|
1273 except ValueError: |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1274 raise TypeError, 'new property "%s" not numeric'%propname |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1275 |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1276 elif value is not None and isinstance(prop, Boolean): |
|
890
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1277 try: |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1278 int(value) |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1279 except ValueError: |
|
a568596dbea7
Unit tests and a few fixes.
Richard Jones <richard@users.sourceforge.net>
parents:
887
diff
changeset
|
1280 raise TypeError, 'new property "%s" not boolean'%propname |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1281 |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1282 node[propname] = value |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1283 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1284 # nothing to do? |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1285 if not propvalues: |
|
930
3c344e942055
Use same regex to split search terms as used to index text.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
927
diff
changeset
|
1286 return propvalues |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1287 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1288 # do the set, and journal it |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1289 self.db.setnode(self.classname, nodeid, node) |
|
869
6d98bec4e52e
fixed the journal bloat from multilink changes
Richard Jones <richard@users.sourceforge.net>
parents:
862
diff
changeset
|
1290 |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1291 if self.do_journal: |
|
1304
61ad556cfc8d
working toward 0.5.2 release
Richard Jones <richard@users.sourceforge.net>
parents:
1303
diff
changeset
|
1292 self.db.addjournal(self.classname, nodeid, 'set', journalvalues) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1293 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1294 self.fireReactors('set', nodeid, oldvalues) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1295 |
|
930
3c344e942055
Use same regex to split search terms as used to index text.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
927
diff
changeset
|
1296 return propvalues |
|
3c344e942055
Use same regex to split search terms as used to index text.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
927
diff
changeset
|
1297 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1298 def retire(self, nodeid): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1299 '''Retire a node. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1300 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1301 The properties on the node remain available from the get() method, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1302 and the node's id is never reused. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1303 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1304 Retired nodes are not returned by the find(), list(), or lookup() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1305 methods, and other nodes may reuse the values of their key properties. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1306 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1307 These operations trigger detectors and can be vetoed. Attempts |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1308 to modify the "creation" or "activity" properties cause a KeyError. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1309 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1310 if self.db.journaltag is None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1311 raise DatabaseError, 'Database open read-only' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1312 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1313 self.fireAuditors('retire', nodeid, None) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1314 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1315 node = self.db.getnode(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1316 node[self.db.RETIRED_FLAG] = 1 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1317 self.db.setnode(self.classname, nodeid, node) |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1318 if self.do_journal: |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1319 self.db.addjournal(self.classname, nodeid, 'retired', None) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1320 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1321 self.fireReactors('retire', nodeid, None) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1322 |
|
1519
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1323 def restore(self, nodeid): |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1324 '''Restpre a retired node. |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1325 |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1326 Make node available for all operations like it was before retirement. |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1327 ''' |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1328 if self.db.journaltag is None: |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1329 raise DatabaseError, 'Database open read-only' |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1330 |
|
1523
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1331 node = self.db.getnode(self.classname, nodeid) |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1332 # check if key property was overrided |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1333 key = self.getkey() |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1334 try: |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1335 id = self.lookup(node[key]) |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1336 except KeyError: |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1337 pass |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1338 else: |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1339 raise KeyError, "Key property (%s) of retired node clashes with \ |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1340 existing one (%s)" % (key, node[key]) |
|
63aa7be52d2c
checked to make sure that the restored item doesn't clash...
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1519
diff
changeset
|
1341 # Now we can safely restore node |
|
1519
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1342 self.fireAuditors('restore', nodeid, None) |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1343 del node[self.db.RETIRED_FLAG] |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1344 self.db.setnode(self.classname, nodeid, node) |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1345 if self.do_journal: |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1346 self.db.addjournal(self.classname, nodeid, 'restored', None) |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1347 |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1348 self.fireReactors('restore', nodeid, None) |
|
6fede2aa6a12
added ability to restore retired nodes
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1505
diff
changeset
|
1349 |
|
1476
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
1350 def is_retired(self, nodeid, cldb=None): |
|
940
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1351 '''Return true if the node is retired. |
|
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1352 ''' |
|
1476
5a01e90b7dc9
fixed export/import of retired nodes [SF#685273]
Richard Jones <richard@users.sourceforge.net>
parents:
1467
diff
changeset
|
1353 node = self.db.getnode(self.classname, nodeid, cldb) |
|
940
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1354 if node.has_key(self.db.RETIRED_FLAG): |
|
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1355 return 1 |
|
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1356 return 0 |
|
301a02ea6020
added is_retired query to Class
Richard Jones <richard@users.sourceforge.net>
parents:
930
diff
changeset
|
1357 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1358 def destroy(self, nodeid): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1359 '''Destroy a node. |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
1360 |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1361 WARNING: this method should never be used except in extremely rare |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1362 situations where there could never be links to the node being |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1363 deleted |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1364 WARNING: use retire() instead |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1365 WARNING: the properties of this node will not be available ever again |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1366 WARNING: really, use retire() instead |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1367 |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1368 Well, I think that's enough warnings. This method exists mostly to |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1369 support the session storage of the cgi interface. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1370 ''' |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1371 if self.db.journaltag is None: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1372 raise DatabaseError, 'Database open read-only' |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1373 self.db.destroynode(self.classname, nodeid) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1374 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1375 def history(self, nodeid): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1376 '''Retrieve the journal of edits on a particular node. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1377 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1378 'nodeid' must be the id of an existing node of this class or an |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1379 IndexError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1380 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1381 The returned list contains tuples of the form |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1382 |
|
1409
8dc60d87ab42
Fixed a backlog of bug reports, and worked on python 2.3 compatibility:
Richard Jones <richard@users.sourceforge.net>
parents:
1408
diff
changeset
|
1383 (nodeid, date, tag, action, params) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1384 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1385 'date' is a Timestamp object specifying the time of the change and |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1386 'tag' is the journaltag specified when the database was opened. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1387 ''' |
|
860
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1388 if not self.do_journal: |
|
2df32a73eb45
Implemented a switch to disable journalling for a Class.
Richard Jones <richard@users.sourceforge.net>
parents:
858
diff
changeset
|
1389 raise ValueError, 'Journalling is disabled for this class' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1390 return self.db.getjournal(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1391 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1392 # Locating nodes: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1393 def hasnode(self, nodeid): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1394 '''Determine if the given nodeid actually exists |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1395 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1396 return self.db.hasnode(self.classname, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1397 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1398 def setkey(self, propname): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1399 '''Select a String property of this class to be the key property. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1400 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1401 'propname' must be the name of a String property of this class or |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1402 None, or a TypeError is raised. The values of the key property on |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
1403 all existing nodes must be unique or a ValueError is raised. If the |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
1404 property doesn't exist, KeyError is raised. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1405 ''' |
|
862
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
1406 prop = self.getprops()[propname] |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
1407 if not isinstance(prop, String): |
|
37fb48c3a136
Did some old TODOs
Richard Jones <richard@users.sourceforge.net>
parents:
860
diff
changeset
|
1408 raise TypeError, 'key properties must be String' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1409 self.key = propname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1410 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1411 def getkey(self): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1412 '''Return the name of the key property for this class or None.''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1413 return self.key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1414 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1415 def labelprop(self, default_to_id=0): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1416 ''' Return the property name for a label for the given node. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1417 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1418 This method attempts to generate a consistent label for the node. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1419 It tries the following in order: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1420 1. key property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1421 2. "name" property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1422 3. "title" property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1423 4. first property from the sorted property name list |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1424 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1425 k = self.getkey() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1426 if k: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1427 return k |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1428 props = self.getprops() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1429 if props.has_key('name'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1430 return 'name' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1431 elif props.has_key('title'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1432 return 'title' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1433 if default_to_id: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1434 return 'id' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1435 props = props.keys() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1436 props.sort() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1437 return props[0] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1438 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1439 # TODO: set up a separate index db file for this? profile? |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1440 def lookup(self, keyvalue): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1441 '''Locate a particular node by its key property and return its id. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1442 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1443 If this class has no key property, a TypeError is raised. If the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1444 'keyvalue' matches one of the values for the key property among |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1445 the nodes in this class, the matching node's id is returned; |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1446 otherwise a KeyError is raised. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1447 ''' |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1448 if not self.key: |
|
1127
22517f9e3b1e
nicer error message
Richard Jones <richard@users.sourceforge.net>
parents:
1103
diff
changeset
|
1449 raise TypeError, 'No key property set for class %s'%self.classname |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1450 cldb = self.db.getclassdb(self.classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1451 try: |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1452 for nodeid in self.getnodeids(cldb): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1453 node = self.db.getnode(self.classname, nodeid, cldb) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1454 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1455 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1456 if node[self.key] == keyvalue: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1457 return nodeid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1458 finally: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1459 cldb.close() |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1460 raise KeyError, 'No key (%s) value "%s" for "%s"'%(self.key, |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1461 keyvalue, self.classname) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1462 |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
1463 # change from spec - allows multiple props to match |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1464 def find(self, **propspec): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1465 '''Get the ids of nodes in this class which link to the given nodes. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1466 |
|
1222
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1467 'propspec' consists of keyword args propname=nodeid or |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1468 propname={nodeid:1, } |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1469 'propname' must be the name of a property in this class, or a |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1470 KeyError is raised. That property must be a Link or |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1471 Multilink property, or a TypeError is raised. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1472 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1473 Any node in this class whose 'propname' property links to any of the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1474 nodeids will be returned. Used by the full text indexing, which knows |
|
1222
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1475 that "foo" occurs in msg1, msg3 and file7, so we have hits on these |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1476 issues: |
|
bc3bc3248dd1
added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents:
1195
diff
changeset
|
1477 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1478 db.issue.find(messages={'1':1,'3':1}, files={'7':1}) |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1479 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1480 propspec = propspec.items() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1481 for propname, nodeids in propspec: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1482 # check the prop is OK |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1483 prop = self.properties[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1484 if not isinstance(prop, Link) and not isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1485 raise TypeError, "'%s' not a Link/Multilink property"%propname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1486 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1487 # ok, now do the find |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1488 cldb = self.db.getclassdb(self.classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1489 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1490 try: |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1491 for id in self.getnodeids(db=cldb): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1492 node = self.db.getnode(self.classname, id, db=cldb) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1493 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1494 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1495 for propname, nodeids in propspec: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1496 # can't test if the node doesn't have this property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1497 if not node.has_key(propname): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1498 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1499 if type(nodeids) is type(''): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1500 nodeids = {nodeids:1} |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1501 prop = self.properties[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1502 value = node[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1503 if isinstance(prop, Link) and nodeids.has_key(value): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1504 l.append(id) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1505 break |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1506 elif isinstance(prop, Multilink): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1507 hit = 0 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1508 for v in value: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1509 if nodeids.has_key(v): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1510 l.append(id) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1511 hit = 1 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1512 break |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1513 if hit: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1514 break |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1515 finally: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1516 cldb.close() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1517 return l |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1518 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1519 def stringFind(self, **requirements): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1520 '''Locate a particular node by matching a set of its String |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1521 properties in a caseless search. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1522 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1523 If the property is not a String property, a TypeError is raised. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1524 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1525 The return is a list of the id of all nodes that match. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1526 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1527 for propname in requirements.keys(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1528 prop = self.properties[propname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1529 if isinstance(not prop, String): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1530 raise TypeError, "'%s' not a String property"%propname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1531 requirements[propname] = requirements[propname].lower() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1532 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1533 cldb = self.db.getclassdb(self.classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1534 try: |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1535 for nodeid in self.getnodeids(cldb): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1536 node = self.db.getnode(self.classname, nodeid, cldb) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1537 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1538 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1539 for key, value in requirements.items(): |
|
1296
34b1e6490e65
hardening for stringFind with missing props
Richard Jones <richard@users.sourceforge.net>
parents:
1252
diff
changeset
|
1540 if not node.has_key(key): |
|
34b1e6490e65
hardening for stringFind with missing props
Richard Jones <richard@users.sourceforge.net>
parents:
1252
diff
changeset
|
1541 break |
|
905
502a5ae11cc5
Very close now. The cgi and mailgw now use the new security API.
Richard Jones <richard@users.sourceforge.net>
parents:
902
diff
changeset
|
1542 if node[key] is None or node[key].lower() != value: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1543 break |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1544 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1545 l.append(nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1546 finally: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1547 cldb.close() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1548 return l |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1549 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1550 def list(self): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1551 ''' Return a list of the ids of the active nodes in this class. |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1552 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1553 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1554 cn = self.classname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1555 cldb = self.db.getclassdb(cn) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1556 try: |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1557 for nodeid in self.getnodeids(cldb): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1558 node = self.db.getnode(cn, nodeid, cldb) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1559 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1560 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1561 l.append(nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1562 finally: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1563 cldb.close() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1564 l.sort() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1565 return l |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1566 |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1567 def getnodeids(self, db=None): |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1568 ''' Return a list of ALL nodeids |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1569 ''' |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1570 if __debug__: |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1571 print >>hyperdb.DEBUG, 'getnodeids', (self, self.classname, db) |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1572 |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1573 res = [] |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1574 |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1575 # start off with the new nodes |
|
1486
f5f60c75a458
added test for error in sqlite backend, and fixed *dbm backend error
Richard Jones <richard@users.sourceforge.net>
parents:
1484
diff
changeset
|
1576 if self.db.newnodes.has_key(self.classname): |
|
f5f60c75a458
added test for error in sqlite backend, and fixed *dbm backend error
Richard Jones <richard@users.sourceforge.net>
parents:
1484
diff
changeset
|
1577 res += self.db.newnodes[self.classname].keys() |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1578 |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1579 if db is None: |
|
1486
f5f60c75a458
added test for error in sqlite backend, and fixed *dbm backend error
Richard Jones <richard@users.sourceforge.net>
parents:
1484
diff
changeset
|
1580 db = self.db.getclassdb(self.classname) |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1581 res = res + db.keys() |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1582 |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1583 # remove the uncommitted, destroyed nodes |
|
1486
f5f60c75a458
added test for error in sqlite backend, and fixed *dbm backend error
Richard Jones <richard@users.sourceforge.net>
parents:
1484
diff
changeset
|
1584 if self.db.destroyednodes.has_key(self.classname): |
|
f5f60c75a458
added test for error in sqlite backend, and fixed *dbm backend error
Richard Jones <richard@users.sourceforge.net>
parents:
1484
diff
changeset
|
1585 for nodeid in self.db.destroyednodes[self.classname].keys(): |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1586 if db.has_key(nodeid): |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1587 res.remove(nodeid) |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1588 |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1589 return res |
|
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1590 |
|
1249
6c24a86a12ae
Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents:
1246
diff
changeset
|
1591 def filter(self, search_matches, filterspec, sort=(None,None), |
|
6c24a86a12ae
Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents:
1246
diff
changeset
|
1592 group=(None,None), num_re = re.compile('^\d+$')): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1593 ''' Return a list of the ids of the active nodes in this class that |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1594 match the 'filter' spec, sorted by the group spec and then the |
| 924 | 1595 sort spec. |
| 1596 | |
| 1597 "filterspec" is {propname: value(s)} | |
| 1002 | 1598 "sort" and "group" are (dir, prop) where dir is '+', '-' or None |
| 1599 and prop is a prop name or None | |
| 990 | 1600 "search_matches" is {nodeid: marker} |
|
1170
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1159
diff
changeset
|
1601 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1159
diff
changeset
|
1602 The filter must match all properties specificed - but if the |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1159
diff
changeset
|
1603 property value to match is a list, any one of the values in the |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1604 list may match for that property to match. Unless the property |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1605 is a Multilink, in which case the item's property list must |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1606 match the filterspec list. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1607 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1608 cn = self.classname |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1609 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1610 # optimise filterspec |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1611 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1612 props = self.getprops() |
| 924 | 1613 LINK = 0 |
| 1614 MULTILINK = 1 | |
| 1615 STRING = 2 | |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1616 DATE = 3 |
| 924 | 1617 OTHER = 6 |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1618 |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1619 timezone = self.db.getUserTimezone() |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1620 for k, v in filterspec.items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1621 propclass = props[k] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1622 if isinstance(propclass, Link): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1623 if type(v) is not type([]): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1624 v = [v] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1625 # replace key values with node ids |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1626 u = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1627 link_class = self.db.classes[propclass.classname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1628 for entry in v: |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1629 # the value -1 is a special "not set" sentinel |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1630 if entry == '-1': |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1631 entry = None |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1632 elif not num_re.match(entry): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1633 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1634 entry = link_class.lookup(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1635 except (TypeError,KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1636 raise ValueError, 'property "%s": %s not a %s'%( |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1637 k, entry, self.properties[k].classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1638 u.append(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1639 |
| 924 | 1640 l.append((LINK, k, u)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1641 elif isinstance(propclass, Multilink): |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1642 # the value -1 is a special "not set" sentinel |
| 1558 | 1643 if v in ('-1', ['-1']): |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1644 v = [] |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1645 elif type(v) is not type([]): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1646 v = [v] |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1647 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1648 # replace key values with node ids |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1649 u = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1650 link_class = self.db.classes[propclass.classname] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1651 for entry in v: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1652 if not num_re.match(entry): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1653 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1654 entry = link_class.lookup(entry) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1655 except (TypeError,KeyError): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1656 raise ValueError, 'new property "%s": %s not a %s'%( |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1657 k, entry, self.properties[k].classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1658 u.append(entry) |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1659 u.sort() |
| 924 | 1660 l.append((MULTILINK, k, u)) |
|
1303
71be6588904f
fixed filtering by id in anydbm
Richard Jones <richard@users.sourceforge.net>
parents:
1296
diff
changeset
|
1661 elif isinstance(propclass, String) and k != 'id': |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1662 # simple glob searching |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1663 v = re.sub(r'([\|\{\}\\\.\+\[\]\(\)])', r'\\\1', v) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1664 v = v.replace('?', '.') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1665 v = v.replace('*', '.*?') |
| 924 | 1666 l.append((STRING, k, re.compile(v, re.I))) |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1667 elif isinstance(propclass, Date): |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1668 try: |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1669 date_rng = Range(v, date.Date, offset=timezone) |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1670 l.append((DATE, k, date_rng)) |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1671 except ValueError: |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1672 # If range creation fails - ignore that search parameter |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1673 pass |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1674 elif isinstance(propclass, Boolean): |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1675 if type(v) is type(''): |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1676 bv = v.lower() in ('yes', 'true', 'on', '1') |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1677 else: |
|
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1678 bv = v |
| 924 | 1679 l.append((OTHER, k, bv)) |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1680 # kedder: dates are filtered by ranges |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1681 #elif isinstance(propclass, Date): |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1682 # l.append((OTHER, k, date.Date(v))) |
|
1351
d1bfb479e527
fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents:
1333
diff
changeset
|
1683 elif isinstance(propclass, Interval): |
|
d1bfb479e527
fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents:
1333
diff
changeset
|
1684 l.append((OTHER, k, date.Interval(v))) |
|
880
de3da99a7c02
Add Number and Boolean types to hyperdb.
Gordon B. McMillan <gmcm@users.sourceforge.net>
parents:
869
diff
changeset
|
1685 elif isinstance(propclass, Number): |
| 924 | 1686 l.append((OTHER, k, int(v))) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1687 else: |
| 924 | 1688 l.append((OTHER, k, v)) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1689 filterspec = l |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1690 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1691 # now, find all the nodes that are active and pass filtering |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1692 l = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1693 cldb = self.db.getclassdb(cn) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1694 try: |
| 924 | 1695 # TODO: only full-scan once (use items()) |
|
1484
b3f2484babce
fixes to import/export
Richard Jones <richard@users.sourceforge.net>
parents:
1476
diff
changeset
|
1696 for nodeid in self.getnodeids(cldb): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1697 node = self.db.getnode(cn, nodeid, cldb) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1698 if node.has_key(self.db.RETIRED_FLAG): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1699 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1700 # apply filter |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1701 for t, k, v in filterspec: |
|
1303
71be6588904f
fixed filtering by id in anydbm
Richard Jones <richard@users.sourceforge.net>
parents:
1296
diff
changeset
|
1702 # handle the id prop |
|
71be6588904f
fixed filtering by id in anydbm
Richard Jones <richard@users.sourceforge.net>
parents:
1296
diff
changeset
|
1703 if k == 'id' and v == nodeid: |
|
71be6588904f
fixed filtering by id in anydbm
Richard Jones <richard@users.sourceforge.net>
parents:
1296
diff
changeset
|
1704 continue |
|
71be6588904f
fixed filtering by id in anydbm
Richard Jones <richard@users.sourceforge.net>
parents:
1296
diff
changeset
|
1705 |
| 924 | 1706 # make sure the node has the property |
| 1707 if not node.has_key(k): | |
| 1708 # this node doesn't have this property, so reject it | |
| 1709 break | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1710 |
| 924 | 1711 # now apply the property filter |
| 1712 if t == LINK: | |
| 1713 # link - if this node's property doesn't appear in the | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1714 # filterspec's nodeid list, skip it |
| 924 | 1715 if node[k] not in v: |
| 1716 break | |
| 1717 elif t == MULTILINK: | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1718 # multilink - if any of the nodeids required by the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1719 # filterspec aren't in this node's property, then skip |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1720 # it |
| 924 | 1721 have = node[k] |
|
1555
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1722 # check for matching the absence of multilink values |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1723 if not v and have: |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1724 break |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1725 |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1726 # othewise, make sure this node has each of the |
|
948c7764d46c
implemented ability to search for multilink properties with no value (not in mk)
Richard Jones <richard@users.sourceforge.net>
parents:
1523
diff
changeset
|
1727 # required values |
| 924 | 1728 for want in v: |
| 1729 if want not in have: | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1730 break |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1731 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1732 continue |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1733 break |
| 924 | 1734 elif t == STRING: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1735 # RE search |
| 924 | 1736 if node[k] is None or not v.search(node[k]): |
| 1737 break | |
|
1499
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1738 elif t == DATE: |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1739 if node[k] is None: break |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1740 if v.to_value: |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1741 if not (v.from_value < node[k] and v.to_value > node[k]): |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1742 break |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1743 else: |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1744 if not (v.from_value < node[k]): |
|
8ee69708da0c
added support for searching on ranges of dates
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1496
diff
changeset
|
1745 break |
| 924 | 1746 elif t == OTHER: |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1747 # straight value comparison for the other types |
| 924 | 1748 if node[k] != v: |
| 1749 break | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1750 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1751 l.append((nodeid, node)) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1752 finally: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1753 cldb.close() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1754 l.sort() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1755 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1756 # filter based on full text search |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1757 if search_matches is not None: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1758 k = [] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1759 for v in l: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1760 if search_matches.has_key(v[0]): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1761 k.append(v) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1762 l = k |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1763 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1764 # now, sort the result |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1765 def sortfun(a, b, sort=sort, group=group, properties=self.getprops(), |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1766 db = self.db, cl=self): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1767 a_id, an = a |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1768 b_id, bn = b |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1769 # sort by group and then sort |
| 1002 | 1770 for dir, prop in group, sort: |
| 1038 | 1771 if dir is None or prop is None: continue |
| 1002 | 1772 |
| 1773 # sorting is class-specific | |
| 1774 propclass = properties[prop] | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1775 |
| 1002 | 1776 # handle the properties that might be "faked" |
| 1777 # also, handle possible missing properties | |
| 1778 try: | |
| 1779 if not an.has_key(prop): | |
| 1780 an[prop] = cl.get(a_id, prop) | |
| 1781 av = an[prop] | |
| 1782 except KeyError: | |
| 1783 # the node doesn't have a value for this property | |
| 1784 if isinstance(propclass, Multilink): av = [] | |
| 1785 else: av = '' | |
| 1786 try: | |
| 1787 if not bn.has_key(prop): | |
| 1788 bn[prop] = cl.get(b_id, prop) | |
| 1789 bv = bn[prop] | |
| 1790 except KeyError: | |
| 1791 # the node doesn't have a value for this property | |
| 1792 if isinstance(propclass, Multilink): bv = [] | |
| 1793 else: bv = '' | |
| 1794 | |
| 1795 # String and Date values are sorted in the natural way | |
| 1796 if isinstance(propclass, String): | |
| 1797 # clean up the strings | |
| 1798 if av and av[0] in string.uppercase: | |
|
1327
7af3f0df307b
fixed nasty sorting bug that was lowercasing properties
Richard Jones <richard@users.sourceforge.net>
parents:
1312
diff
changeset
|
1799 av = av.lower() |
| 1002 | 1800 if bv and bv[0] in string.uppercase: |
|
1327
7af3f0df307b
fixed nasty sorting bug that was lowercasing properties
Richard Jones <richard@users.sourceforge.net>
parents:
1312
diff
changeset
|
1801 bv = bv.lower() |
| 1002 | 1802 if (isinstance(propclass, String) or |
| 1803 isinstance(propclass, Date)): | |
| 1804 # it might be a string that's really an integer | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1805 try: |
| 1002 | 1806 av = int(av) |
| 1807 bv = int(bv) | |
| 1808 except: | |
| 1809 pass | |
| 1810 if dir == '+': | |
| 1811 r = cmp(av, bv) | |
| 1812 if r != 0: return r | |
| 1813 elif dir == '-': | |
| 1814 r = cmp(bv, av) | |
| 1815 if r != 0: return r | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1816 |
| 1002 | 1817 # Link properties are sorted according to the value of |
| 1818 # the "order" property on the linked nodes if it is | |
| 1819 # present; or otherwise on the key string of the linked | |
| 1820 # nodes; or finally on the node ids. | |
| 1821 elif isinstance(propclass, Link): | |
| 1822 link = db.classes[propclass.classname] | |
| 1823 if av is None and bv is not None: return -1 | |
| 1824 if av is not None and bv is None: return 1 | |
| 1825 if av is None and bv is None: continue | |
| 1826 if link.getprops().has_key('order'): | |
| 1827 if dir == '+': | |
| 1828 r = cmp(link.get(av, 'order'), | |
| 1829 link.get(bv, 'order')) | |
| 1830 if r != 0: return r | |
| 1831 elif dir == '-': | |
| 1832 r = cmp(link.get(bv, 'order'), | |
| 1833 link.get(av, 'order')) | |
| 1834 if r != 0: return r | |
| 1835 elif link.getkey(): | |
| 1836 key = link.getkey() | |
| 1837 if dir == '+': | |
| 1838 r = cmp(link.get(av, key), link.get(bv, key)) | |
| 1839 if r != 0: return r | |
| 1840 elif dir == '-': | |
| 1841 r = cmp(link.get(bv, key), link.get(av, key)) | |
| 1842 if r != 0: return r | |
| 1843 else: | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1844 if dir == '+': |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1845 r = cmp(av, bv) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1846 if r != 0: return r |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1847 elif dir == '-': |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1848 r = cmp(bv, av) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1849 if r != 0: return r |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1850 |
| 1002 | 1851 # Multilink properties are sorted according to how many |
| 1852 # links are present. | |
| 1853 elif isinstance(propclass, Multilink): | |
|
1408
01c02e81e08d
more proper multilink sorting/grouping
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1395
diff
changeset
|
1854 r = cmp(len(av), len(bv)) |
|
01c02e81e08d
more proper multilink sorting/grouping
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1395
diff
changeset
|
1855 if r == 0: |
|
01c02e81e08d
more proper multilink sorting/grouping
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1395
diff
changeset
|
1856 # Compare contents of multilink property if lenghts is |
|
01c02e81e08d
more proper multilink sorting/grouping
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1395
diff
changeset
|
1857 # equal |
|
01c02e81e08d
more proper multilink sorting/grouping
Andrey Lebedev <kedder@users.sourceforge.net>
parents:
1395
diff
changeset
|
1858 r = cmp ('.'.join(av), '.'.join(bv)) |
|
1505
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1859 if r: |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1860 if dir == '+': |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1861 return r |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1862 else: |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1863 return -r |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1864 |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1865 else: |
|
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1866 # all other types just compare |
| 1002 | 1867 if dir == '+': |
| 1868 r = cmp(av, bv) | |
| 1869 elif dir == '-': | |
| 1870 r = cmp(bv, av) | |
|
1505
c101d2ff5a20
fix to [SF#691071], really this time
Richard Jones <richard@users.sourceforge.net>
parents:
1499
diff
changeset
|
1871 if r != 0: return r |
| 1002 | 1872 |
| 1873 # end for dir, prop in sort, group: | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1874 # if all else fails, compare the ids |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1875 return cmp(a[0], b[0]) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1876 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1877 l.sort(sortfun) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1878 return [i[0] for i in l] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1879 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1880 def count(self): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1881 '''Get the number of nodes in this class. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1882 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1883 If the returned integer is 'numnodes', the ids of all the nodes |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1884 in this class run from 1 to numnodes, and numnodes+1 will be the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1885 id of the next node to be created in this class. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1886 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1887 return self.db.countnodes(self.classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1888 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1889 # Manipulating properties: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1890 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1891 def getprops(self, protected=1): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1892 '''Return a dictionary mapping property names to property objects. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1893 If the "protected" flag is true, we include protected properties - |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1894 those which may not be modified. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1895 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1896 In addition to the actual properties on the node, these |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1897 methods provide the "creation" and "activity" properties. If the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1898 "protected" flag is true, we include protected properties - those |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1899 which may not be modified. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1900 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1901 d = self.properties.copy() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1902 if protected: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1903 d['id'] = String() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1904 d['creation'] = hyperdb.Date() |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1905 d['activity'] = hyperdb.Date() |
|
1176
bd3b57859c37
On second thought, that last checkin was dumb.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
1906 d['creator'] = hyperdb.Link('user') |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1907 return d |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1908 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1909 def addprop(self, **properties): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1910 '''Add properties to this class. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1911 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1912 The keyword arguments in 'properties' must map names to property |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1913 objects, or a TypeError is raised. None of the keys in 'properties' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1914 may collide with the names of existing properties, or a ValueError |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1915 is raised before any properties have been added. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1916 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1917 for key in properties.keys(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1918 if self.properties.has_key(key): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1919 raise ValueError, key |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1920 self.properties.update(properties) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1921 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1922 def index(self, nodeid): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1923 '''Add (or refresh) the node to search indexes |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1924 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1925 # find all the String properties that have indexme |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1926 for prop, propclass in self.getprops().items(): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1927 if isinstance(propclass, String) and propclass.indexme: |
|
891
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1928 try: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1929 value = str(self.get(nodeid, prop)) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1930 except IndexError: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1931 # node no longer exists - entry should be removed |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1932 self.db.indexer.purge_entry((self.classname, nodeid, prop)) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1933 else: |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1934 # and index them under (classname, nodeid, property) |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1935 self.db.indexer.add_text((self.classname, nodeid, prop), |
|
974a4b94c5e3
Implemented the destroy() method needed by the session database...
Richard Jones <richard@users.sourceforge.net>
parents:
890
diff
changeset
|
1936 value) |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1937 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1938 # |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1939 # Detector interface |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1940 # |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1941 def audit(self, event, detector): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1942 '''Register a detector |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1943 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1944 l = self.auditors[event] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1945 if detector not in l: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1946 self.auditors[event].append(detector) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1947 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1948 def fireAuditors(self, action, nodeid, newvalues): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1949 '''Fire all registered auditors. |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1950 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1951 for audit in self.auditors[action]: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1952 audit(self.db, self, nodeid, newvalues) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1953 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1954 def react(self, event, detector): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1955 '''Register a detector |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1956 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1957 l = self.reactors[event] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1958 if detector not in l: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1959 self.reactors[event].append(detector) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1960 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1961 def fireReactors(self, action, nodeid, oldvalues): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1962 '''Fire all registered reactors. |
|
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
1963 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1964 for react in self.reactors[action]: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1965 react(self.db, self, nodeid, oldvalues) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1966 |
|
1442
b42fa71754c9
don't attempt to create FileClass items if no content is supplied
Richard Jones <richard@users.sourceforge.net>
parents:
1431
diff
changeset
|
1967 class FileClass(Class, hyperdb.FileClass): |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1968 '''This class defines a large chunk of data. To support this, it has a |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1969 mandatory String property "content" which is typically saved off |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1970 externally to the hyperdb. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1971 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1972 The default MIME type of this data is defined by the |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1973 "default_mime_type" class attribute, which may be overridden by each |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1974 node if the class defines a "type" String property. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1975 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1976 default_mime_type = 'text/plain' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1977 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1978 def create(self, **propvalues): |
|
1431
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1979 ''' Snarf the "content" propvalue and store in a file |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1980 ''' |
|
1431
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1981 # we need to fire the auditors now, or the content property won't |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1982 # be in propvalues for the auditors to play with |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1983 self.fireAuditors('create', None, propvalues) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1984 |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1985 # now remove the content property so it's not stored in the db |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1986 content = propvalues['content'] |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1987 del propvalues['content'] |
|
1431
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1988 |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1989 # do the database create |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1990 newid = Class.create_inner(self, **propvalues) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1991 |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1992 # fire reactors |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1993 self.fireReactors('create', newid, None) |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1994 |
|
c70068162e64
Altered Class.create() and FileClass.create() methods...
Richard Jones <richard@users.sourceforge.net>
parents:
1424
diff
changeset
|
1995 # store off the content as a file |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1996 self.db.storefile(self.classname, newid, None, content) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1997 return newid |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
1998 |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
1999 def import_list(self, propnames, proplist): |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2000 ''' Trap the "content" property... |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2001 ''' |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2002 # dupe this list so we don't affect others |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2003 propnames = propnames[:] |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2004 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2005 # extract the "content" property from the proplist |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2006 i = propnames.index('content') |
| 1143 | 2007 content = eval(proplist[i]) |
|
952
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2008 del propnames[i] |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2009 del proplist[i] |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2010 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2011 # do the normal import |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2012 newid = Class.import_list(self, propnames, proplist) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2013 |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2014 # save off the "content" file |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2015 self.db.storefile(self.classname, newid, None, content) |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2016 return newid |
|
f615fbd02c18
full database export and import is done
Richard Jones <richard@users.sourceforge.net>
parents:
950
diff
changeset
|
2017 |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2018 def get(self, nodeid, propname, default=_marker, cache=1): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2019 ''' trap the content propname and get it from the file |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2020 ''' |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
2021 poss_msg = 'Possibly an access right configuration problem.' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2022 if propname == 'content': |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2023 try: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2024 return self.db.getfile(self.classname, nodeid, None) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2025 except IOError, (strerror): |
|
1333
80d27b7d6db5
implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents:
1327
diff
changeset
|
2026 # XXX by catching this we donot see an error in the log. |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2027 return 'ERROR reading file: %s%s\n%s\n%s'%( |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2028 self.classname, nodeid, poss_msg, strerror) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2029 if default is not _marker: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2030 return Class.get(self, nodeid, propname, default, cache=cache) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2031 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2032 return Class.get(self, nodeid, propname, cache=cache) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2033 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2034 def getprops(self, protected=1): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2035 ''' In addition to the actual properties on the node, these methods |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2036 provide the "content" property. If the "protected" flag is true, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2037 we include protected properties - those which may not be |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2038 modified. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2039 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2040 d = Class.getprops(self, protected=protected).copy() |
|
1159
a1a548c15260
include the "content" property in getprops....
Richard Jones <richard@users.sourceforge.net>
parents:
1145
diff
changeset
|
2041 d['content'] = hyperdb.String() |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2042 return d |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2043 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2044 def index(self, nodeid): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2045 ''' Index the node in the search index. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2046 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2047 We want to index the content in addition to the normal String |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2048 property indexing. |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2049 ''' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2050 # perform normal indexing |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2051 Class.index(self, nodeid) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2052 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2053 # get the content to index |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2054 content = self.get(nodeid, 'content') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2055 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2056 # figure the mime type |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2057 if self.properties.has_key('type'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2058 mime_type = self.get(nodeid, 'type') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2059 else: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2060 mime_type = self.default_mime_type |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2061 |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2062 # and index! |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2063 self.db.indexer.add_text((self.classname, nodeid, 'content'), content, |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2064 mime_type) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2065 |
|
1103
db787cef1385
handled some XXXs
Richard Jones <richard@users.sourceforge.net>
parents:
1099
diff
changeset
|
2066 # deviation from spec - was called ItemClass |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2067 class IssueClass(Class, roundupdb.IssueClass): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2068 # Overridden methods: |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2069 def __init__(self, db, classname, **properties): |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
2070 '''The newly-created class automatically includes the "messages", |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2071 "files", "nosy", and "superseder" properties. If the 'properties' |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2072 dictionary attempts to specify any of these properties or a |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2073 "creation" or "activity" property, a ValueError is raised. |
|
969
ddcb527491ba
Consistent quoting
Richard Jones <richard@users.sourceforge.net>
parents:
967
diff
changeset
|
2074 ''' |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2075 if not properties.has_key('title'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2076 properties['title'] = hyperdb.String(indexme='yes') |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2077 if not properties.has_key('messages'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2078 properties['messages'] = hyperdb.Multilink("msg") |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2079 if not properties.has_key('files'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2080 properties['files'] = hyperdb.Multilink("file") |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2081 if not properties.has_key('nosy'): |
| 1002 | 2082 # note: journalling is turned off as it really just wastes |
| 2083 # space. this behaviour may be overridden in an instance | |
| 2084 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") | |
|
858
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2085 if not properties.has_key('superseder'): |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2086 properties['superseder'] = hyperdb.Multilink(classname) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2087 Class.__init__(self, db, classname, **properties) |
|
2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
Richard Jones <richard@users.sourceforge.net>
parents:
843
diff
changeset
|
2088 |
|
46
3c5920433866
*sigh* some databases have _foo.so as their underlying implementation.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2089 # |
