From 2d81a2057b5baa6afb0fdf1b7cfde4c4b192fcfa Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 4 Oct 2001 02:12:42 +0000 Subject: [PATCH] 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). git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@270 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup-admin | 48 +++++++++++++++++++++++++++++++++----------- roundup/hyperdb.py | 17 ++++++++++++---- roundup/roundupdb.py | 30 ++++++++++++++++++--------- 3 files changed, 69 insertions(+), 26 deletions(-) diff --git a/roundup-admin b/roundup-admin index a29c055..e8082a4 100755 --- a/roundup-admin +++ b/roundup-admin @@ -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 @@ def do_spec(db, args): ''' 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'')): '''Usage: create classname property=value ... Create a new entry of a given class. @@ -240,21 +244,38 @@ def do_create(db, args): classname = args[0] cl = db.getclass(classname) props = {} - properties = cl.getprops() - for prop in args[1:]: - key, value = prop.split('=') - type = properties[key] - if isinstance(type, hyperdb.String): + 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 - elif isinstance(type, hyperdb.Date): + + # convert types + for key in props.keys(): + type = properties[key] + 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 @@ if __name__ == '__main__': # # $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 diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py index 57a95b1..367abac 100644 --- a/roundup/hyperdb.py +++ b/roundup/hyperdb.py @@ -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 @@ class Class: 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 @@ class Class: # 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 @@ def Choice(name, *options): # # $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... # diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index 0e30f71..1840147 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -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 @@ class Database: 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 @@ class Class(hyperdb.Class): 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 @@ class FileClass(Class): 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 @@ Roundup issue tracker # # $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. -- 2.30.2