Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 2909:2fc6c508b537
Database instances must have method close()
trim trailing spaces, fix vim modeline
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Sat, 13 Nov 2004 07:11:14 +0000 |
| parents | a8808157f892 |
| children | 4607f58a007b |
comparison
equal
deleted
inserted
replaced
| 2908:95813789cf70 | 2909:2fc6c508b537 |
|---|---|
| 12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: hyperdb.py,v 1.105 2004-11-12 04:07:03 richard Exp $ | 18 # $Id: hyperdb.py,v 1.106 2004-11-13 07:11:14 a1s Exp $ |
| 19 | 19 |
| 20 """Hyperdatabase implementation, especially field types. | 20 """Hyperdatabase implementation, especially field types. |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 161 Class.set(), and Class.retire() methods are disabled. | 161 Class.set(), and Class.retire() methods are disabled. |
| 162 """ | 162 """ |
| 163 raise NotImplementedError | 163 raise NotImplementedError |
| 164 | 164 |
| 165 def post_init(self): | 165 def post_init(self): |
| 166 """Called once the schema initialisation has finished. | 166 """Called once the schema initialisation has finished. |
| 167 If 'refresh' is true, we want to rebuild the backend | 167 If 'refresh' is true, we want to rebuild the backend |
| 168 structures. | 168 structures. |
| 169 """ | 169 """ |
| 170 raise NotImplementedError | 170 raise NotImplementedError |
| 171 | 171 |
| 243 ''' | 243 ''' |
| 244 raise NotImplementedError | 244 raise NotImplementedError |
| 245 | 245 |
| 246 def storefile(self, classname, nodeid, property, content): | 246 def storefile(self, classname, nodeid, property, content): |
| 247 '''Store the content of the file in the database. | 247 '''Store the content of the file in the database. |
| 248 | 248 |
| 249 The property may be None, in which case the filename does not | 249 The property may be None, in which case the filename does not |
| 250 indicate which property is being saved. | 250 indicate which property is being saved. |
| 251 ''' | 251 ''' |
| 252 raise NotImplementedError | 252 raise NotImplementedError |
| 253 | 253 |
| 290 Undo all the changes made since the database was opened or the last | 290 Undo all the changes made since the database was opened or the last |
| 291 commit() or rollback() was performed. | 291 commit() or rollback() was performed. |
| 292 ''' | 292 ''' |
| 293 raise NotImplementedError | 293 raise NotImplementedError |
| 294 | 294 |
| 295 def close(self): | |
| 296 """Close the database. | |
| 297 | |
| 298 This method must be called at the end of processing. | |
| 299 | |
| 300 """ | |
| 301 | |
| 295 # | 302 # |
| 296 # The base Class class | 303 # The base Class class |
| 297 # | 304 # |
| 298 class Class: | 305 class Class: |
| 299 """ The handle to a particular class of nodes in a hyperdatabase. | 306 """ The handle to a particular class of nodes in a hyperdatabase. |
| 300 | 307 |
| 301 All methods except __repr__ and getnode must be implemented by a | 308 All methods except __repr__ and getnode must be implemented by a |
| 302 concrete backend Class. | 309 concrete backend Class. |
| 303 """ | 310 """ |
| 304 | 311 |
| 305 def __init__(self, db, classname, **properties): | 312 def __init__(self, db, classname, **properties): |
| 323 | 330 |
| 324 The keyword arguments in 'propvalues' map property names to values. | 331 The keyword arguments in 'propvalues' map property names to values. |
| 325 | 332 |
| 326 The values of arguments must be acceptable for the types of their | 333 The values of arguments must be acceptable for the types of their |
| 327 corresponding properties or a TypeError is raised. | 334 corresponding properties or a TypeError is raised. |
| 328 | 335 |
| 329 If this class has a key property, it must be present and its value | 336 If this class has a key property, it must be present and its value |
| 330 must not collide with other key strings or a ValueError is raised. | 337 must not collide with other key strings or a ValueError is raised. |
| 331 | 338 |
| 332 Any other properties on this class that are missing from the | 339 Any other properties on this class that are missing from the |
| 333 'propvalues' dictionary are set to None. | 340 'propvalues' dictionary are set to None. |
| 334 | 341 |
| 335 If an id in a link or multilink property does not refer to a valid | 342 If an id in a link or multilink property does not refer to a valid |
| 336 node, an IndexError is raised. | 343 node, an IndexError is raised. |
| 337 """ | 344 """ |
| 338 raise NotImplementedError | 345 raise NotImplementedError |
| 339 | 346 |
| 365 ''' | 372 ''' |
| 366 raise NotImplementedError | 373 raise NotImplementedError |
| 367 | 374 |
| 368 def set(self, nodeid, **propvalues): | 375 def set(self, nodeid, **propvalues): |
| 369 """Modify a property on an existing node of this class. | 376 """Modify a property on an existing node of this class. |
| 370 | 377 |
| 371 'nodeid' must be the id of an existing node of this class or an | 378 'nodeid' must be the id of an existing node of this class or an |
| 372 IndexError is raised. | 379 IndexError is raised. |
| 373 | 380 |
| 374 Each key in 'propvalues' must be the name of a property of this | 381 Each key in 'propvalues' must be the name of a property of this |
| 375 class or a KeyError is raised. | 382 class or a KeyError is raised. |
| 385 """ | 392 """ |
| 386 raise NotImplementedError | 393 raise NotImplementedError |
| 387 | 394 |
| 388 def retire(self, nodeid): | 395 def retire(self, nodeid): |
| 389 """Retire a node. | 396 """Retire a node. |
| 390 | 397 |
| 391 The properties on the node remain available from the get() method, | 398 The properties on the node remain available from the get() method, |
| 392 and the node's id is never reused. | 399 and the node's id is never reused. |
| 393 | 400 |
| 394 Retired nodes are not returned by the find(), list(), or lookup() | 401 Retired nodes are not returned by the find(), list(), or lookup() |
| 395 methods, and other nodes may reuse the values of their key properties. | 402 methods, and other nodes may reuse the values of their key properties. |
| 396 """ | 403 """ |
| 397 raise NotImplementedError | 404 raise NotImplementedError |
| 398 | 405 |
| 400 '''Restpre a retired node. | 407 '''Restpre a retired node. |
| 401 | 408 |
| 402 Make node available for all operations like it was before retirement. | 409 Make node available for all operations like it was before retirement. |
| 403 ''' | 410 ''' |
| 404 raise NotImplementedError | 411 raise NotImplementedError |
| 405 | 412 |
| 406 def is_retired(self, nodeid): | 413 def is_retired(self, nodeid): |
| 407 '''Return true if the node is rerired | 414 '''Return true if the node is rerired |
| 408 ''' | 415 ''' |
| 409 raise NotImplementedError | 416 raise NotImplementedError |
| 410 | 417 |
| 411 def destroy(self, nodeid): | 418 def destroy(self, nodeid): |
| 412 """Destroy a node. | 419 """Destroy a node. |
| 413 | 420 |
| 414 WARNING: this method should never be used except in extremely rare | 421 WARNING: this method should never be used except in extremely rare |
| 415 situations where there could never be links to the node being | 422 situations where there could never be links to the node being |
| 416 deleted | 423 deleted |
| 417 | 424 |
| 418 WARNING: use retire() instead | 425 WARNING: use retire() instead |
| 487 raise NotImplementedError | 494 raise NotImplementedError |
| 488 | 495 |
| 489 def find(self, **propspec): | 496 def find(self, **propspec): |
| 490 """Get the ids of nodes in this class which link to the given nodes. | 497 """Get the ids of nodes in this class which link to the given nodes. |
| 491 | 498 |
| 492 'propspec' consists of keyword args propname={nodeid:1,} | 499 'propspec' consists of keyword args propname={nodeid:1,} |
| 493 'propname' must be the name of a property in this class, or a | 500 'propname' must be the name of a property in this class, or a |
| 494 KeyError is raised. That property must be a Link or Multilink | 501 KeyError is raised. That property must be a Link or Multilink |
| 495 property, or a TypeError is raised. | 502 property, or a TypeError is raised. |
| 496 | 503 |
| 497 Any node in this class whose 'propname' property links to any of the | 504 Any node in this class whose 'propname' property links to any of the |
| 780 for name in self.cl.getprops(protected=protected).keys(): | 787 for name in self.cl.getprops(protected=protected).keys(): |
| 781 l.append((name, self.cl.get(self.nodeid, name))) | 788 l.append((name, self.cl.get(self.nodeid, name))) |
| 782 return l | 789 return l |
| 783 def has_key(self, name): | 790 def has_key(self, name): |
| 784 return self.cl.getprops().has_key(name) | 791 return self.cl.getprops().has_key(name) |
| 785 def get(self, name, default=None): | 792 def get(self, name, default=None): |
| 786 if self.has_key(name): | 793 if self.has_key(name): |
| 787 return self[name] | 794 return self[name] |
| 788 else: | 795 else: |
| 789 return default | 796 return default |
| 790 def __getattr__(self, name): | 797 def __getattr__(self, name): |
| 819 cl = Class(db, name, name=String(), order=String()) | 826 cl = Class(db, name, name=String(), order=String()) |
| 820 for i in range(len(options)): | 827 for i in range(len(options)): |
| 821 cl.create(name=options[i], order=i) | 828 cl.create(name=options[i], order=i) |
| 822 return hyperdb.Link(name) | 829 return hyperdb.Link(name) |
| 823 | 830 |
| 824 # vim: set filetype=python ts=4 sw=4 et si | 831 # vim: set filetype=python sts=4 sw=4 et si : |
