1616# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818#
19- # $Id: roundup-admin,v 1.26 2001-10-11 05:03:51 richard Exp $
19+ # $Id: roundup-admin,v 1.27 2001-10-11 23:43:04 richard Exp $
2020
2121import sys
2222if int (sys .version [0 ]) < 2 :
@@ -108,7 +108,7 @@ Command help:
108108 print '%s:' % name
109109 print ' ' ,command .__doc__
110110
111- def do_init (instance_home , args ):
111+ def do_init (instance_home , args , comma_sep = 0 ):
112112 '''Usage: init [template [backend [admin password]]]
113113 Initialise a new Roundup instance.
114114
@@ -148,22 +148,27 @@ def do_init(instance_home, args):
148148 return 0
149149
150150
151- def do_get (db , args ):
151+ def do_get (db , args , comma_sep = 0 ):
152152 '''Usage: get property designator[,designator]*
153153 Get the given property of one or more designator(s).
154154
155155 Retrieves the property value of the nodes specified by the designators.
156156 '''
157157 propname = args [0 ]
158158 designators = string .split (args [1 ], ',' )
159- # TODO: handle the -c option
159+ l = []
160160 for designator in designators :
161161 classname , nodeid = roundupdb .splitDesignator (designator )
162- print db .getclass (classname ).get (nodeid , propname )
162+ if comma_sep :
163+ l .append (db .getclass (classname ).get (nodeid , propname ))
164+ else :
165+ print db .getclass (classname ).get (nodeid , propname )
166+ if comma_sep :
167+ print ',' .join (l )
163168 return 0
164169
165170
166- def do_set (db , args ):
171+ def do_set (db , args , comma_sep = 0 ):
167172 '''Usage: set designator[,designator]* propname=value ...
168173 Set the given property of one or more designator(s).
169174
@@ -197,7 +202,7 @@ def do_set(db, args):
197202 apply (cl .set , (nodeid , ), props )
198203 return 0
199204
200- def do_find (db , args ):
205+ def do_find (db , args , comma_sep = 0 ):
201206 '''Usage: find classname propname=value ...
202207 Find the nodes of the given class with a given property value.
203208
@@ -210,19 +215,19 @@ def do_find(db, args):
210215 # look up the linked-to class and get the nodeid that has the value
211216 propname , value = args [1 ].split ('=' )
212217 num_re = re .compile ('^\d+$' )
213- if num_re .match (value ):
214- nodeid = value
215- else :
218+ if not num_re .match (value ):
216219 propcl = cl .properties [propname ].classname
217220 propcl = db .getclass (propcl )
218- nodeid = propcl .lookup (value )
221+ value = propcl .lookup (value )
219222
220223 # now do the find
221- # TODO: handle the -c option
222- print cl .find (** {propname : nodeid })
224+ if comma_sep :
225+ print ',' .join (cl .find (** {propname : value }))
226+ else :
227+ print cl .find (** {propname : value })
223228 return 0
224229
225- def do_spec (db , args ):
230+ def do_spec (db , args , comma_sep = 0 ):
226231 '''Usage: spec classname
227232 Show the properties for a classname.
228233
@@ -237,7 +242,7 @@ def do_spec(db, args):
237242 else :
238243 print '%s: %s' % (key , value )
239244
240- def do_create (db , args ):
245+ def do_create (db , args , comma_sep = 0 ):
241246 '''Usage: create classname property=value ...
242247 Create a new entry of a given class.
243248
@@ -293,7 +298,7 @@ def do_create(db, args):
293298
294299 return 0
295300
296- def do_list (db , args ):
301+ def do_list (db , args , comma_sep = 0 ):
297302 '''Usage: list classname [property]
298303 List the instances of a class.
299304
@@ -308,24 +313,26 @@ def do_list(db, args):
308313 key = args [1 ]
309314 else :
310315 key = cl .labelprop ()
311- # TODO: handle the -c option
312- for nodeid in cl .list ():
313- value = cl .get (nodeid , key )
314- print "%4s: %s" % (nodeid , value )
316+ if comma_sep :
317+ print ',' .join (cl .list ())
318+ else :
319+ for nodeid in cl .list ():
320+ value = cl .get (nodeid , key )
321+ print "%4s: %s" % (nodeid , value )
315322 return 0
316323
317- def do_history (db , args ):
324+ def do_history (db , args , comma_sep = 0 ):
318325 '''Usage: history designator
319326 Show the history entries of a designator.
320327
321328 Lists the journal entries for the node identified by the designator.
322329 '''
323330 classname , nodeid = roundupdb .splitDesignator (args [0 ])
324- # TODO: handle the -c option
331+ # TODO: handle the -c option?
325332 print db .getclass (classname ).history (nodeid )
326333 return 0
327334
328- def do_retire (db , args ):
335+ def do_retire (db , args , comma_sep = 0 ):
329336 '''Usage: retire designator[,designator]*
330337 Retire the node specified by designator.
331338
@@ -338,7 +345,7 @@ def do_retire(db, args):
338345 db .getclass (classname ).retire (nodeid )
339346 return 0
340347
341- def do_export (db , args ):
348+ def do_export (db , args , comma_sep = 0 ):
342349 '''Usage: export class[,class] destination_dir
343350 ** EXPERIMENTAL **
344351 Export the database to CSV files by class in the given directory.
@@ -380,7 +387,7 @@ def do_export(db, args):
380387 f .write (',' .join (l ) + '\n ' )
381388 return 0
382389
383- def do_import (db , args ):
390+ def do_import (db , args , comma_sep = 0 ):
384391 '''Usage: import class file
385392 ** EXPERIMENTAL **
386393 Import the contents of the CSV file as new nodes for the given class.
@@ -448,7 +455,7 @@ def do_import(db, args):
448455 apply (cl .create , (), d )
449456 return 0
450457
451- def do_freshen (db , args ):
458+ def do_freshen (db , args , comma_sep = 0 ):
452459 '''Usage: freshen
453460 Freshen an existing instance. **DO NOT USE**
454461
@@ -555,7 +562,7 @@ def main():
555562
556563 # do the command
557564 try :
558- return function (db , args [1 :])
565+ return function (db , args [1 :], comma_sep = comma_sep )
559566 finally :
560567 db .close ()
561568
@@ -567,6 +574,10 @@ if __name__ == '__main__':
567574
568575#
569576# $Log: not supported by cvs2svn $
577+ # Revision 1.26 2001/10/11 05:03:51 richard
578+ # Marked the roundup-admin import/export as experimental since they're not fully
579+ # operational.
580+ #
570581# Revision 1.25 2001/10/10 04:12:32 richard
571582# The setup.cfg file is just causing pain. Away it goes.
572583#
0 commit comments