comparison roundup-admin @ 296:e155eca83f40

Beginnings of an interactive mode for roundup-admin
author Richard Jones <richard@users.sourceforge.net>
date Wed, 17 Oct 2001 06:04:00 +0000
parents 49be38bb6e9a
children 1bbc16563d89
comparison
equal deleted inserted replaced
295:0eb026a5257d 296:e155eca83f40
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 # 18 #
19 # $Id: roundup-admin,v 1.29 2001-10-16 03:48:01 richard Exp $ 19 # $Id: roundup-admin,v 1.30 2001-10-17 06:04:00 richard Exp $
20 20
21 import sys 21 import sys
22 if int(sys.version[0]) < 2: 22 if int(sys.version[0]) < 2:
23 print 'Roundup requires python 2.0 or later.' 23 print 'Roundup requires python 2.0 or later.'
24 sys.exit(1) 24 sys.exit(1)
123 help() 123 help()
124 return 124 return
125 help = figureCommands().get(args[0], None) 125 help = figureCommands().get(args[0], None)
126 if help: 126 if help:
127 print help.__doc__ 127 print help.__doc__
128 else:
129 print 'Sorry, no help for "%s"'%args[0]
128 130
129 def help_initopts(): 131 def help_initopts():
130 import roundup.templates 132 import roundup.templates
131 templates = roundup.templates.listTemplates() 133 templates = roundup.templates.listTemplates()
132 print 'Templates:', ', '.join(templates) 134 print 'Templates:', ', '.join(templates)
523 for k, v in globals().items(): 525 for k, v in globals().items():
524 if k[:5] == 'help_': 526 if k[:5] == 'help_':
525 d[k[5:]] = v 527 d[k[5:]] = v
526 return d 528 return d
527 529
528 def main(): 530 class AdminTool:
529 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc') 531
530 532 def run_command(self, args):
531 # handle command-line args 533 command = args[0]
532 instance_home = os.environ.get('ROUNDUP_INSTANCE', '') 534
533 name = password = '' 535 # handle help now
534 if os.environ.has_key('ROUNDUP_LOGIN'): 536 if command == 'help':
535 l = os.environ['ROUNDUP_LOGIN'].split(':') 537 if len(args)>1:
536 name = l[0] 538 do_help(args[1:])
537 if len(l) > 1: 539 return 0
538 password = l[1] 540 do_help(['help'])
539 comma_sep = 0 541 return 0
540 for opt, arg in opts: 542 if command == 'morehelp':
541 if opt == '-h': 543 do_help(['help'])
542 args = ['help'] 544 help_commands()
543 break 545 help_all()
544 if opt == '-i': 546 return 0
545 instance_home = arg 547
546 if opt == '-c': 548 # make sure we have an instance_home
547 comma_sep = 1 549 while not self.instance_home:
548 550 self.instance_home = raw_input('Enter instance home: ').strip()
549 # figure the command 551
550 if not args: 552 # before we open the db, we may be doing an init
551 usage('No command specified') 553 if command == 'init':
554 return do_init(self.instance_home, args)
555
556 function = figureCommands().get(command, None)
557
558 # not a valid command
559 if function is None:
560 usage('Unknown command "%s"'%command)
561 return 1
562
563 # get the instance
564 instance = roundup.instance.open(self.instance_home)
565 db = instance.open('admin')
566
567 if len(args) < 2:
568 print function.__doc__
569 return 1
570
571 # do the command
572 try:
573 return function(db, args[1:], comma_sep=self.comma_sep)
574 finally:
575 db.close()
576
552 return 1 577 return 1
553 command = args[0] 578
554 579 def interactive(self, ws_re=re.compile(r'\s+')):
555 # handle help now 580 '''Run in an interactive mode
556 if command == 'help': 581 '''
557 if len(args)>1: 582 while 1:
558 do_help(args[1:]) 583 try:
559 return 0 584 command = raw_input('roundup> ')
560 usage() 585 except EOFError:
561 return 0 586 print '.. exit'
562 if command == 'morehelp': 587 return 0
563 usage() 588 args = ws_re.split(command)
564 help_all() 589 if not args: continue
565 return 0 590 if args[0] in ('quit', 'exit'): return 0
566 591 self.run_command(args)
567 # make sure we have an instance_home 592
568 while not instance_home: 593 def main(self):
569 instance_home = raw_input('Enter instance home: ').strip() 594 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc')
570 595
571 # before we open the db, we may be doing an init 596 # handle command-line args
572 if command == 'init': 597 self.instance_home = os.environ.get('ROUNDUP_INSTANCE', '')
573 return do_init(instance_home, args) 598 name = password = ''
574 599 if os.environ.has_key('ROUNDUP_LOGIN'):
575 function = figureCommands().get(command, None) 600 l = os.environ['ROUNDUP_LOGIN'].split(':')
576 601 name = l[0]
577 # not a valid command 602 if len(l) > 1:
578 if function is None: 603 password = l[1]
579 usage('Unknown command "%s"'%command) 604 self.comma_sep = 0
580 return 1 605 for opt, arg in opts:
581 606 if opt == '-h':
582 # get the instance 607 usage()
583 instance = roundup.instance.open(instance_home) 608 return 0
584 db = instance.open('admin') 609 if opt == '-i':
585 610 self.instance_home = arg
586 if len(args) < 2: 611 if opt == '-c':
587 print function.__doc__ 612 self.comma_sep = 1
588 return 1 613
589 614 # if no command - go interactive
590 # do the command 615 if not args:
591 try: 616 return self.interactive()
592 return function(db, args[1:], comma_sep=comma_sep) 617
593 finally: 618 self.run_command(args)
594 db.close()
595
596 return 1
597 619
598 620
599 if __name__ == '__main__': 621 if __name__ == '__main__':
600 sys.exit(main()) 622 tool = AdminTool()
623 sys.exit(tool.main())
601 624
602 # 625 #
603 # $Log: not supported by cvs2svn $ 626 # $Log: not supported by cvs2svn $
627 # Revision 1.29 2001/10/16 03:48:01 richard
628 # admin tool now complains if a "find" is attempted with a non-link property.
629 #
604 # Revision 1.28 2001/10/13 00:07:39 richard 630 # Revision 1.28 2001/10/13 00:07:39 richard
605 # More help in admin tool. 631 # More help in admin tool.
606 # 632 #
607 # Revision 1.27 2001/10/11 23:43:04 richard 633 # Revision 1.27 2001/10/11 23:43:04 richard
608 # Implemented the comma-separated printing option in the admin tool. 634 # Implemented the comma-separated printing option in the admin tool.

Roundup Issue Tracker: http://roundup-tracker.org/