1616# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818#
19- # $Id: roundup-admin,v 1.50 2001-12-02 05:06:16 richard Exp $
19+ # $Id: roundup-admin,v 1.51 2001-12-10 00:57:38 richard Exp $
2020
2121import sys
2222if not hasattr (sys , 'version_info' ) or sys .version_info [:2 ] < (2 ,1 ):
@@ -64,6 +64,7 @@ class AdminTool:
6464 for k in AdminTool .__dict__ .keys ():
6565 if k [:5 ] == 'help_' :
6666 self .help [k [5 :]] = getattr (self , k )
67+ self .instance_home = ''
6768 self .db = None
6869
6970 def usage (self , message = '' ):
@@ -205,6 +206,8 @@ Command help:
205206
206207 See also initopts help.
207208 '''
209+ if len (args ) < 1 :
210+ raise UsageError , 'Not enough arguments supplied'
208211 # select template
209212 import roundup .templates
210213 templates = roundup .templates .listTemplates ()
@@ -243,6 +246,8 @@ Command help:
243246
244247 Retrieves the property value of the nodes specified by the designators.
245248 '''
249+ if len (args ) < 2 :
250+ raise UsageError , 'Not enough arguments supplied'
246251 propname = args [0 ]
247252 designators = string .split (args [1 ], ',' )
248253 l = []
@@ -279,6 +284,8 @@ Command help:
279284
280285 Sets the property to the value for all designators given.
281286 '''
287+ if len (args ) < 2 :
288+ raise UsageError , 'Not enough arguments supplied'
282289 from roundup import hyperdb
283290
284291 designators = string .split (args [0 ], ',' )
@@ -340,6 +347,8 @@ Command help:
340347 Find the nodes of the given class with a given link property value. The
341348 value may be either the nodeid of the linked node, or its key value.
342349 '''
350+ if len (args ) < 1 :
351+ raise UsageError , 'Not enough arguments supplied'
343352 classname = args [0 ]
344353 # get the class
345354 try :
@@ -401,6 +410,8 @@ Command help:
401410
402411 This lists the properties for a given class.
403412 '''
413+ if len (args ) < 1 :
414+ raise UsageError , 'Not enough arguments supplied'
404415 classname = args [0 ]
405416 # get the class
406417 try :
@@ -416,6 +427,33 @@ Command help:
416427 else :
417428 print '%s: %s' % (key , value )
418429
430+ def do_display (self , args ):
431+ '''Usage: display designator
432+ Show the property values for the given node.
433+
434+ This lists the properties and their associated values for the given
435+ node.
436+ '''
437+ if len (args ) < 1 :
438+ raise UsageError , 'Not enough arguments supplied'
439+
440+ # decode the node designator
441+ try :
442+ classname , nodeid = roundupdb .splitDesignator (args [0 ])
443+ except roundupdb .DesignatorError , message :
444+ raise UsageError , message
445+
446+ # get the class
447+ try :
448+ cl = self .db .getclass (classname )
449+ except KeyError :
450+ raise UsageError , 'invalid class "%s"' % classname
451+
452+ # display the values
453+ for key in cl .properties .keys ():
454+ value = cl .get (nodeid , key )
455+ print '%s: %s' % (key , value )
456+
419457 def do_create (self , args ):
420458 '''Usage: create classname property=value ...
421459 Create a new entry of a given class.
@@ -424,6 +462,8 @@ Command help:
424462 name=value arguments provided on the command line after the "create"
425463 command.
426464 '''
465+ if len (args ) < 1 :
466+ raise UsageError , 'Not enough arguments supplied'
427467 from roundup import hyperdb
428468
429469 classname = args [0 ]
@@ -508,6 +548,8 @@ Command help:
508548 in order: the key, "name", "title" and then the first property,
509549 alphabetically.
510550 '''
551+ if len (args ) < 1 :
552+ raise UsageError , 'Not enough arguments supplied'
511553 classname = args [0 ]
512554
513555 # get the class
@@ -548,6 +590,8 @@ Command help:
548590 3 usability
549591 4 feature
550592 '''
593+ if len (args ) < 1 :
594+ raise UsageError , 'Not enough arguments supplied'
551595 classname = args [0 ]
552596
553597 # get the class
@@ -600,6 +644,8 @@ Command help:
600644
601645 Lists the journal entries for the node identified by the designator.
602646 '''
647+ if len (args ) < 1 :
648+ raise UsageError , 'Not enough arguments supplied'
603649 try :
604650 classname , nodeid = roundupdb .splitDesignator (args [0 ])
605651 except roundupdb .DesignatorError , message :
@@ -637,7 +683,7 @@ Command help:
637683 manually. This command undoes all those changes, so a commit
638684 immediately after would make no changes to the database.
639685 '''
640- self .db .commit ()
686+ self .db .rollback ()
641687 return 0
642688
643689 def do_retire (self , args ):
@@ -647,6 +693,8 @@ Command help:
647693 This action indicates that a particular node is not to be retrieved by
648694 the list or find commands, and its key value may be re-used.
649695 '''
696+ if len (args ) < 1 :
697+ raise UsageError , 'Not enough arguments supplied'
650698 designators = string .split (args [0 ], ',' )
651699 for designator in designators :
652700 try :
@@ -670,8 +718,7 @@ Command help:
670718 directory. The journals are not exported.
671719 '''
672720 if len (args ) < 2 :
673- print do_export .__doc__
674- return 1
721+ raise UsageError , 'Not enough arguments supplied'
675722 classes = string .split (args [0 ], ',' )
676723 dir = args [1 ]
677724
@@ -834,13 +881,13 @@ Command help:
834881 try :
835882 instance = roundup .instance .open (self .instance_home )
836883 except ValueError , message :
884+ self .instance_home = ''
837885 print "Couldn't open instance: %s" % message
838886 return 1
839- self .db = instance .open ('admin' )
840887
841- if len ( args ) < 2 :
842- print function . __doc__
843- return 1
888+ # only open the database once!
889+ if not self . db :
890+ self . db = instance . open ( 'admin' )
844891
845892 # do the command
846893 ret = 0
@@ -870,13 +917,21 @@ Command help:
870917 try :
871918 command = raw_input ('roundup> ' )
872919 except EOFError :
873- print '.. exit'
874- return 0
920+ print 'exit...'
921+ break
922+ if not command : continue
875923 args = ws_re .split (command )
876924 if not args : continue
877- if args [0 ] in ('quit' , 'exit' ): return 0
925+ if args [0 ] in ('quit' , 'exit' ): break
878926 self .run_command (args )
879927
928+ # exit.. check for transactions
929+ if self .db and self .db .transactions :
930+ commit = raw_input ("There are unsaved changes. Commit them (y/N)? " )
931+ if commit [0 ].lower () == 'y' :
932+ self .db .commit ()
933+ return 0
934+
880935 def main (self ):
881936 try :
882937 opts , args = getopt .getopt (sys .argv [1 :], 'i:u:hc' )
@@ -918,6 +973,20 @@ if __name__ == '__main__':
918973
919974#
920975# $Log: not supported by cvs2svn $
976+ # Revision 1.50 2001/12/02 05:06:16 richard
977+ # . We now use weakrefs in the Classes to keep the database reference, so
978+ # the close() method on the database is no longer needed.
979+ # I bumped the minimum python requirement up to 2.1 accordingly.
980+ # . #487480 ] roundup-server
981+ # . #487476 ] INSTALL.txt
982+ #
983+ # I also cleaned up the change message / post-edit stuff in the cgi client.
984+ # There's now a clearly marked "TODO: append the change note" where I believe
985+ # the change note should be added there. The "changes" list will obviously
986+ # have to be modified to be a dict of the changes, or somesuch.
987+ #
988+ # More testing needed.
989+ #
921990# Revision 1.49 2001/12/01 07:17:50 richard
922991# . We now have basic transaction support! Information is only written to
923992# the database when the commit() method is called. Only the anydbm
0 commit comments