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