Skip to content

Commit c526ae4

Browse files
author
Richard Jones
committed
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).
1 parent d857fc4 commit c526ae4

File tree

3 files changed

+69
-26
lines changed

3 files changed

+69
-26
lines changed

roundup-admin

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup-admin,v 1.19 2001-10-01 06:40:43 richard Exp $
19+
# $Id: roundup-admin,v 1.20 2001-10-04 02:12:42 richard Exp $
2020

2121
import sys
2222
if int(sys.version[0]) < 2:
@@ -224,10 +224,14 @@ def do_spec(db, args):
224224
'''
225225
classname = args[0]
226226
cl = db.getclass(classname)
227+
keyprop = cl.getkey()
227228
for key, value in cl.properties.items():
228-
print '%s: %s'%(key, value)
229+
if keyprop == key:
230+
print '%s: %s (key property)'%(key, value)
231+
else:
232+
print '%s: %s'%(key, value)
229233

230-
def do_create(db, args):
234+
def do_create(db, args, pretty_re=re.compile(r'<roundup\.hyperdb\.(.*)>')):
231235
'''Usage: create classname property=value ...
232236
Create a new entry of a given class.
233237
@@ -240,21 +244,38 @@ def do_create(db, args):
240244
classname = args[0]
241245
cl = db.getclass(classname)
242246
props = {}
243-
properties = cl.getprops()
244-
for prop in args[1:]:
245-
key, value = prop.split('=')
246-
type = properties[key]
247-
if isinstance(type, hyperdb.String):
247+
properties = cl.getprops(protected = 0)
248+
if len(args) == 1:
249+
# ask for the properties
250+
for key, value in properties.items():
251+
if key == 'id': continue
252+
m = pretty_re.match(str(value))
253+
if m:
254+
value = m.group(1)
255+
value = raw_input('%s (%s): '%(key.capitalize(), value))
256+
if value:
257+
props[key] = value
258+
else:
259+
# use the args
260+
for prop in args[1:]:
261+
key, value = prop.split('=')
248262
props[key] = value
249-
elif isinstance(type, hyperdb.Date):
263+
264+
# convert types
265+
for key in props.keys():
266+
type = properties[key]
267+
if isinstance(type, hyperdb.Date):
250268
props[key] = date.Date(value)
251269
elif isinstance(type, hyperdb.Interval):
252270
props[key] = date.Interval(value)
253-
elif isinstance(type, hyperdb.Link):
254-
props[key] = value
255271
elif isinstance(type, hyperdb.Multilink):
256272
props[key] = value.split(',')
257-
print apply(cl.create, (), props)
273+
274+
if cl.getkey() and not props.has_key(cl.getkey()):
275+
print "You must provide the '%s' property."%cl.getkey()
276+
else:
277+
print apply(cl.create, (), props)
278+
258279
return 0
259280

260281
def do_list(db, args):
@@ -428,6 +449,9 @@ if __name__ == '__main__':
428449

429450
#
430451
# $Log: not supported by cvs2svn $
452+
# Revision 1.19 2001/10/01 06:40:43 richard
453+
# made do_get have the args in the correct order
454+
#
431455
# Revision 1.18 2001/09/18 22:58:37 richard
432456
#
433457
# Added some more help to roundu-admin

roundup/hyperdb.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.19 2001-08-29 04:47:18 richard Exp $
18+
# $Id: hyperdb.py,v 1.20 2001-10-04 02:12:42 richard Exp $
1919

2020
# standard python modules
2121
import cPickle, re, string
@@ -200,6 +200,8 @@ def create(self, **propvalues):
200200
for key, prop in self.properties.items():
201201
if propvalues.has_key(key):
202202
continue
203+
if key == self.key:
204+
raise ValueError, 'key property "%s" is required'%key
203205
if isinstance(prop, Multilink):
204206
propvalues[key] = []
205207
else:
@@ -734,10 +736,13 @@ def count(self):
734736

735737
# Manipulating properties:
736738

737-
def getprops(self):
738-
"""Return a dictionary mapping property names to property objects."""
739+
def getprops(self, protected=1):
740+
"""Return a dictionary mapping property names to property objects.
741+
If the "protected" flag is true, we include protected properties -
742+
those which may not be modified."""
739743
d = self.properties.copy()
740-
d['id'] = String()
744+
if protected:
745+
d['id'] = String()
741746
return d
742747

743748
def addprop(self, **properties):
@@ -795,6 +800,10 @@ def Choice(name, *options):
795800

796801
#
797802
# $Log: not supported by cvs2svn $
803+
# Revision 1.19 2001/08/29 04:47:18 richard
804+
# Fixed CGI client change messages so they actually include the properties
805+
# changed (again).
806+
#
798807
# Revision 1.18 2001/08/16 07:34:59 richard
799808
# better CGI text searching - but hidden filter fields are disappearing...
800809
#

roundup/roundupdb.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.10 2001-08-07 00:24:42 richard Exp $
18+
# $Id: roundupdb.py,v 1.11 2001-10-04 02:12:42 richard Exp $
1919

2020
import re, os, smtplib, socket
2121

@@ -33,7 +33,7 @@ def getuid(self):
3333
that owns this connection to the hyperdatabase."""
3434
return self.user.lookup(self.journaltag)
3535

36-
def uidFromAddress(self, address):
36+
def uidFromAddress(self, address, create=1):
3737
''' address is from the rfc822 module, and therefore is (name, addr)
3838
3939
user is created if they don't exist in the db already
@@ -119,13 +119,17 @@ def get(self, nodeid, propname, default=_marker):
119119
else:
120120
return hyperdb.Class.get(self, nodeid, propname)
121121

122-
def getprops(self):
122+
def getprops(self, protected=1):
123123
"""In addition to the actual properties on the node, these
124-
methods provide the "creation" and "activity" properties."""
124+
methods provide the "creation" and "activity" properties. If the
125+
"protected" flag is true, we include protected properties - those
126+
which may not be modified.
127+
"""
125128
d = hyperdb.Class.getprops(self).copy()
126-
d['creation'] = hyperdb.Date()
127-
d['activity'] = hyperdb.Date()
128-
d['creator'] = hyperdb.Link("user")
129+
if protected:
130+
d['creation'] = hyperdb.Date()
131+
d['activity'] = hyperdb.Date()
132+
d['creator'] = hyperdb.Link("user")
129133
return d
130134

131135
#
@@ -176,12 +180,15 @@ def get(self, nodeid, propname, default=_marker):
176180
else:
177181
return Class.get(self, nodeid, propname)
178182

179-
def getprops(self):
183+
def getprops(self, protected=1):
180184
''' In addition to the actual properties on the node, these methods
181-
provide the "content" property.
185+
provide the "content" property. If the "protected" flag is true,
186+
we include protected properties - those which may not be
187+
modified.
182188
'''
183189
d = Class.getprops(self).copy()
184-
d['content'] = hyperdb.String()
190+
if protected:
191+
d['content'] = hyperdb.String()
185192
return d
186193

187194
# XXX deviation from spec - was called ItemClass
@@ -282,6 +289,9 @@ def email_footer(self, nodeid, msgid):
282289

283290
#
284291
# $Log: not supported by cvs2svn $
292+
# Revision 1.10 2001/08/07 00:24:42 richard
293+
# stupid typo
294+
#
285295
# Revision 1.9 2001/08/07 00:15:51 richard
286296
# Added the copyright/license notice to (nearly) all files at request of
287297
# Bizar Software.

0 commit comments

Comments
 (0)