Mercurial > p > roundup > code
changeset 262:ab921dc53ccd
Added nicer command-line item adding:
passing no arguments will enter an interactive more which asks for
each property in turn. While I was at it, I fixed an implementation
problem WRT the spec - I wasn't raising a ValueError if the key
property was missing from a create(). Also added a protected=boolean
argument to getprops() so we can list only the mutable properties
(defaults to yes, which lists the immutables).
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 04 Oct 2001 02:12:42 +0000 |
| parents | 0ca5381a72b5 |
| children | e13d55912cd4 |
| files | roundup-admin roundup/hyperdb.py roundup/roundupdb.py |
| diffstat | 3 files changed, 69 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup-admin Mon Oct 01 06:40:43 2001 +0000 +++ b/roundup-admin Thu Oct 04 02:12:42 2001 +0000 @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundup-admin,v 1.19 2001-10-01 06:40:43 richard Exp $ +# $Id: roundup-admin,v 1.20 2001-10-04 02:12:42 richard Exp $ import sys if int(sys.version[0]) < 2: @@ -224,10 +224,14 @@ ''' classname = args[0] cl = db.getclass(classname) + keyprop = cl.getkey() for key, value in cl.properties.items(): - print '%s: %s'%(key, value) + if keyprop == key: + print '%s: %s (key property)'%(key, value) + else: + print '%s: %s'%(key, value) -def do_create(db, args): +def do_create(db, args, pretty_re=re.compile(r'<roundup\.hyperdb\.(.*)>')): '''Usage: create classname property=value ... Create a new entry of a given class. @@ -240,21 +244,38 @@ classname = args[0] cl = db.getclass(classname) props = {} - properties = cl.getprops() - for prop in args[1:]: - key, value = prop.split('=') + properties = cl.getprops(protected = 0) + if len(args) == 1: + # ask for the properties + for key, value in properties.items(): + if key == 'id': continue + m = pretty_re.match(str(value)) + if m: + value = m.group(1) + value = raw_input('%s (%s): '%(key.capitalize(), value)) + if value: + props[key] = value + else: + # use the args + for prop in args[1:]: + key, value = prop.split('=') + props[key] = value + + # convert types + for key in props.keys(): type = properties[key] - if isinstance(type, hyperdb.String): - props[key] = value - elif isinstance(type, hyperdb.Date): + if isinstance(type, hyperdb.Date): props[key] = date.Date(value) elif isinstance(type, hyperdb.Interval): props[key] = date.Interval(value) - elif isinstance(type, hyperdb.Link): - props[key] = value elif isinstance(type, hyperdb.Multilink): props[key] = value.split(',') - print apply(cl.create, (), props) + + if cl.getkey() and not props.has_key(cl.getkey()): + print "You must provide the '%s' property."%cl.getkey() + else: + print apply(cl.create, (), props) + return 0 def do_list(db, args): @@ -428,6 +449,9 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.19 2001/10/01 06:40:43 richard +# made do_get have the args in the correct order +# # Revision 1.18 2001/09/18 22:58:37 richard # # Added some more help to roundu-admin
--- a/roundup/hyperdb.py Mon Oct 01 06:40:43 2001 +0000 +++ b/roundup/hyperdb.py Thu Oct 04 02:12:42 2001 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: hyperdb.py,v 1.19 2001-08-29 04:47:18 richard Exp $ +# $Id: hyperdb.py,v 1.20 2001-10-04 02:12:42 richard Exp $ # standard python modules import cPickle, re, string @@ -200,6 +200,8 @@ for key, prop in self.properties.items(): if propvalues.has_key(key): continue + if key == self.key: + raise ValueError, 'key property "%s" is required'%key if isinstance(prop, Multilink): propvalues[key] = [] else: @@ -734,10 +736,13 @@ # Manipulating properties: - def getprops(self): - """Return a dictionary mapping property names to property objects.""" + def getprops(self, protected=1): + """Return a dictionary mapping property names to property objects. + If the "protected" flag is true, we include protected properties - + those which may not be modified.""" d = self.properties.copy() - d['id'] = String() + if protected: + d['id'] = String() return d def addprop(self, **properties): @@ -795,6 +800,10 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.19 2001/08/29 04:47:18 richard +# Fixed CGI client change messages so they actually include the properties +# changed (again). +# # Revision 1.18 2001/08/16 07:34:59 richard # better CGI text searching - but hidden filter fields are disappearing... #
--- a/roundup/roundupdb.py Mon Oct 01 06:40:43 2001 +0000 +++ b/roundup/roundupdb.py Thu Oct 04 02:12:42 2001 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundupdb.py,v 1.10 2001-08-07 00:24:42 richard Exp $ +# $Id: roundupdb.py,v 1.11 2001-10-04 02:12:42 richard Exp $ import re, os, smtplib, socket @@ -33,7 +33,7 @@ that owns this connection to the hyperdatabase.""" return self.user.lookup(self.journaltag) - def uidFromAddress(self, address): + def uidFromAddress(self, address, create=1): ''' address is from the rfc822 module, and therefore is (name, addr) user is created if they don't exist in the db already @@ -119,13 +119,17 @@ else: return hyperdb.Class.get(self, nodeid, propname) - def getprops(self): + def getprops(self, protected=1): """In addition to the actual properties on the node, these - methods provide the "creation" and "activity" properties.""" + methods provide the "creation" and "activity" properties. If the + "protected" flag is true, we include protected properties - those + which may not be modified. + """ d = hyperdb.Class.getprops(self).copy() - d['creation'] = hyperdb.Date() - d['activity'] = hyperdb.Date() - d['creator'] = hyperdb.Link("user") + if protected: + d['creation'] = hyperdb.Date() + d['activity'] = hyperdb.Date() + d['creator'] = hyperdb.Link("user") return d # @@ -176,12 +180,15 @@ else: return Class.get(self, nodeid, propname) - def getprops(self): + def getprops(self, protected=1): ''' In addition to the actual properties on the node, these methods - provide the "content" property. + provide the "content" property. If the "protected" flag is true, + we include protected properties - those which may not be + modified. ''' d = Class.getprops(self).copy() - d['content'] = hyperdb.String() + if protected: + d['content'] = hyperdb.String() return d # XXX deviation from spec - was called ItemClass @@ -282,6 +289,9 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.10 2001/08/07 00:24:42 richard +# stupid typo +# # Revision 1.9 2001/08/07 00:15:51 richard # Added the copyright/license notice to (nearly) all files at request of # Bizar Software.
