comparison roundup/hyperdb.py @ 527:53839883cab6

[SF#502951] adding new properties to old database
author Richard Jones <richard@users.sourceforge.net>
date Mon, 14 Jan 2002 06:32:34 +0000
parents dce4c75bef5a
children 22e0edf7da6e
comparison
equal deleted inserted replaced
526:523b22a2c021 527:53839883cab6
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.47 2002-01-14 02:20:15 richard Exp $ 18 # $Id: hyperdb.py,v 1.48 2002-01-14 06:32:34 richard Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Hyperdatabase implementation, especially field types. 21 Hyperdatabase implementation, especially field types.
22 """ 22 """
23 23
362 if key == self.key: 362 if key == self.key:
363 raise ValueError, 'key property "%s" is required'%key 363 raise ValueError, 'key property "%s" is required'%key
364 if isinstance(prop, Multilink): 364 if isinstance(prop, Multilink):
365 propvalues[key] = [] 365 propvalues[key] = []
366 else: 366 else:
367 # TODO: None isn't right here, I think...
367 propvalues[key] = None 368 propvalues[key] = None
368 369
369 # convert all data to strings 370 # convert all data to strings
370 for key, prop in self.properties.items(): 371 for key, prop in self.properties.items():
371 if isinstance(prop, Date): 372 if isinstance(prop, Date):
393 set cache=0. 394 set cache=0.
394 """ 395 """
395 if propname == 'id': 396 if propname == 'id':
396 return nodeid 397 return nodeid
397 398
399 # get the property (raises KeyErorr if invalid)
400 prop = self.properties[propname]
401
398 # get the node's dict 402 # get the node's dict
399 d = self.db.getnode(self.classname, nodeid, cache=cache) 403 d = self.db.getnode(self.classname, nodeid, cache=cache)
400 if not d.has_key(propname) and default is not _marker: 404
401 return default 405 if not d.has_key(propname):
402 406 if default is _marker:
403 # get the value 407 if isinstance(prop, Multilink):
404 prop = self.properties[propname] 408 return []
409 else:
410 # TODO: None isn't right here, I think...
411 return None
412 else:
413 return default
405 414
406 # possibly convert the marshalled data to instances 415 # possibly convert the marshalled data to instances
407 if isinstance(prop, Date): 416 if isinstance(prop, Date):
408 return date.Date(d[propname]) 417 return date.Date(d[propname])
409 elif isinstance(prop, Interval): 418 elif isinstance(prop, Interval):
517 key, entry, self.properties[key].classname) 526 key, entry, self.properties[key].classname)
518 l.append(entry) 527 l.append(entry)
519 value = l 528 value = l
520 propvalues[key] = value 529 propvalues[key] = value
521 530
522 #handle removals 531 # handle removals
523 l = node[key] 532 if node.has_key(key):
533 l = node[key]
534 else:
535 l = []
524 for id in l[:]: 536 for id in l[:]:
525 if id in value: 537 if id in value:
526 continue 538 continue
527 # register the unlink with the old linked node 539 # register the unlink with the old linked node
528 self.db.addjournal(link_class, id, 'unlink', 540 self.db.addjournal(link_class, id, 'unlink',
1027 cl.create(name=option[i], order=i) 1039 cl.create(name=option[i], order=i)
1028 return hyperdb.Link(name) 1040 return hyperdb.Link(name)
1029 1041
1030 # 1042 #
1031 # $Log: not supported by cvs2svn $ 1043 # $Log: not supported by cvs2svn $
1044 # Revision 1.47 2002/01/14 02:20:15 richard
1045 # . changed all config accesses so they access either the instance or the
1046 # config attriubute on the db. This means that all config is obtained from
1047 # instance_config instead of the mish-mash of classes. This will make
1048 # switching to a ConfigParser setup easier too, I hope.
1049 #
1050 # At a minimum, this makes migration a _little_ easier (a lot easier in the
1051 # 0.5.0 switch, I hope!)
1052 #
1032 # Revision 1.46 2002/01/07 10:42:23 richard 1053 # Revision 1.46 2002/01/07 10:42:23 richard
1033 # oops 1054 # oops
1034 # 1055 #
1035 # Revision 1.45 2002/01/02 04:18:17 richard 1056 # Revision 1.45 2002/01/02 04:18:17 richard
1036 # hyperdb docstrings 1057 # hyperdb docstrings

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