Skip to content

Commit c137c5a

Browse files
author
Richard Jones
committed
implemented set for all items in a class, and unset
1 parent 35ff1ac commit c137c5a

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

roundup/admin.py

Lines changed: 36 additions & 17 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: admin.py,v 1.28 2002-09-10 12:44:42 richard Exp $
19+
# $Id: admin.py,v 1.29 2002-09-11 01:19:45 richard Exp $
2020

2121
import sys, os, getpass, getopt, re, UserDict, shlex, shutil
2222
try:
@@ -81,7 +81,10 @@ def props_from_args(self, args):
8181
key, value = arg.split('=')
8282
except ValueError:
8383
raise UsageError, _('argument "%(arg)s" not propname=value')%locals()
84-
props[key] = value
84+
if value:
85+
props[key] = value
86+
else:
87+
props[key] = None
8588
return props
8689

8790
def usage(self, message=''):
@@ -394,35 +397,53 @@ def do_get(self, args):
394397

395398

396399
def do_set(self, args):
397-
'''Usage: set designator[,designator]* propname=value ...
398-
Set the given property of one or more designator(s).
400+
'''Usage: set [items] property=value property=value ...
401+
Set the given properties of one or more items(s).
402+
403+
The items may be specified as a class or as a comma-separeted
404+
list of item designators (ie "designator[,designator,...]").
399405
400-
Sets the property to the value for all designators given.
406+
This command sets the properties to the values for all designators
407+
given. If the value is missing (ie. "property=") then the property is
408+
un-set.
401409
'''
402410
if len(args) < 2:
403411
raise UsageError, _('Not enough arguments supplied')
404412
from roundup import hyperdb
405413

406414
designators = args[0].split(',')
415+
if len(designators) == 1:
416+
designator = designators[0]
417+
try:
418+
designator = hyperdb.splitDesignator(designator)
419+
designators = [designator]
420+
except hyperdb.DesignatorError:
421+
cl = self.get_class(designator)
422+
designators = [(designator, x) for x in cl.list()]
423+
else:
424+
try:
425+
designators = [hyperdb.splitDesignator(x) for x in designators]
426+
except hyperdb.DesignatorError, message:
427+
raise UsageError, message
407428

408429
# get the props from the args
409430
props = self.props_from_args(args[1:])
410431

411432
# now do the set for all the nodes
412-
for designator in designators:
413-
# decode the node designator
414-
try:
415-
classname, nodeid = hyperdb.splitDesignator(designator)
416-
except hyperdb.DesignatorError, message:
417-
raise UsageError, message
418-
419-
# get the class
433+
for classname, itemid in designators:
420434
cl = self.get_class(classname)
421435

422436
properties = cl.getprops()
423437
for key, value in props.items():
424438
proptype = properties[key]
425-
if isinstance(proptype, hyperdb.String):
439+
if isinstance(proptype, hyperdb.Multilink):
440+
if value is None:
441+
props[key] = []
442+
else:
443+
props[key] = value.split(',')
444+
elif value is None:
445+
continue
446+
elif isinstance(proptype, hyperdb.String):
426447
continue
427448
elif isinstance(proptype, hyperdb.Password):
428449
props[key] = password.Password(value)
@@ -438,16 +459,14 @@ def do_set(self, args):
438459
raise UsageError, '"%s": %s'%(value, message)
439460
elif isinstance(proptype, hyperdb.Link):
440461
props[key] = value
441-
elif isinstance(proptype, hyperdb.Multilink):
442-
props[key] = value.split(',')
443462
elif isinstance(proptype, hyperdb.Boolean):
444463
props[key] = value.lower() in ('yes', 'true', 'on', '1')
445464
elif isinstance(proptype, hyperdb.Number):
446465
props[key] = int(value)
447466

448467
# try the set
449468
try:
450-
apply(cl.set, (nodeid, ), props)
469+
apply(cl.set, (itemid, ), props)
451470
except (TypeError, IndexError, ValueError), message:
452471
raise UsageError, message
453472
return 0

0 commit comments

Comments
 (0)