|
16 | 16 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
17 | 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 | 21 | import sys |
22 | 22 | if int(sys.version[0]) < 2: |
@@ -125,6 +125,8 @@ def do_help(args): |
125 | 125 | help = figureCommands().get(args[0], None) |
126 | 126 | if help: |
127 | 127 | print help.__doc__ |
| 128 | + else: |
| 129 | + print 'Sorry, no help for "%s"'%args[0] |
128 | 130 |
|
129 | 131 | def help_initopts(): |
130 | 132 | import roundup.templates |
@@ -525,82 +527,106 @@ def figureHelp(): |
525 | 527 | d[k[5:]] = v |
526 | 528 | return d |
527 | 529 |
|
528 | | -def main(): |
529 | | - opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc') |
530 | | - |
531 | | - # handle command-line args |
532 | | - instance_home = os.environ.get('ROUNDUP_INSTANCE', '') |
533 | | - name = password = '' |
534 | | - if os.environ.has_key('ROUNDUP_LOGIN'): |
535 | | - l = os.environ['ROUNDUP_LOGIN'].split(':') |
536 | | - name = l[0] |
537 | | - if len(l) > 1: |
538 | | - password = l[1] |
539 | | - comma_sep = 0 |
540 | | - for opt, arg in opts: |
541 | | - if opt == '-h': |
542 | | - args = ['help'] |
543 | | - break |
544 | | - if opt == '-i': |
545 | | - instance_home = arg |
546 | | - if opt == '-c': |
547 | | - comma_sep = 1 |
548 | | - |
549 | | - # figure the command |
550 | | - if not args: |
551 | | - usage('No command specified') |
552 | | - return 1 |
553 | | - command = args[0] |
| 530 | +class AdminTool: |
| 531 | + |
| 532 | + def run_command(self, args): |
| 533 | + command = args[0] |
554 | 534 |
|
555 | | - # handle help now |
556 | | - if command == 'help': |
557 | | - if len(args)>1: |
558 | | - do_help(args[1:]) |
| 535 | + # handle help now |
| 536 | + if command == 'help': |
| 537 | + if len(args)>1: |
| 538 | + do_help(args[1:]) |
| 539 | + return 0 |
| 540 | + do_help(['help']) |
| 541 | + return 0 |
| 542 | + if command == 'morehelp': |
| 543 | + do_help(['help']) |
| 544 | + help_commands() |
| 545 | + help_all() |
559 | 546 | return 0 |
560 | | - usage() |
561 | | - return 0 |
562 | | - if command == 'morehelp': |
563 | | - usage() |
564 | | - help_all() |
565 | | - return 0 |
566 | | - |
567 | | - # make sure we have an instance_home |
568 | | - while not instance_home: |
569 | | - instance_home = raw_input('Enter instance home: ').strip() |
570 | | - |
571 | | - # before we open the db, we may be doing an init |
572 | | - if command == 'init': |
573 | | - return do_init(instance_home, args) |
574 | | - |
575 | | - function = figureCommands().get(command, None) |
576 | | - |
577 | | - # not a valid command |
578 | | - if function is None: |
579 | | - usage('Unknown command "%s"'%command) |
580 | | - return 1 |
581 | 547 |
|
582 | | - # get the instance |
583 | | - instance = roundup.instance.open(instance_home) |
584 | | - db = instance.open('admin') |
| 548 | + # make sure we have an instance_home |
| 549 | + while not self.instance_home: |
| 550 | + self.instance_home = raw_input('Enter instance home: ').strip() |
585 | 551 |
|
586 | | - if len(args) < 2: |
587 | | - print function.__doc__ |
588 | | - return 1 |
| 552 | + # before we open the db, we may be doing an init |
| 553 | + if command == 'init': |
| 554 | + return do_init(self.instance_home, args) |
589 | 555 |
|
590 | | - # do the command |
591 | | - try: |
592 | | - return function(db, args[1:], comma_sep=comma_sep) |
593 | | - finally: |
594 | | - db.close() |
| 556 | + function = figureCommands().get(command, None) |
595 | 557 |
|
596 | | - return 1 |
| 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 | + |
| 577 | + return 1 |
| 578 | + |
| 579 | + def interactive(self, ws_re=re.compile(r'\s+')): |
| 580 | + '''Run in an interactive mode |
| 581 | + ''' |
| 582 | + while 1: |
| 583 | + try: |
| 584 | + command = raw_input('roundup> ') |
| 585 | + except EOFError: |
| 586 | + print '.. exit' |
| 587 | + return 0 |
| 588 | + args = ws_re.split(command) |
| 589 | + if not args: continue |
| 590 | + if args[0] in ('quit', 'exit'): return 0 |
| 591 | + self.run_command(args) |
| 592 | + |
| 593 | + def main(self): |
| 594 | + opts, args = getopt.getopt(sys.argv[1:], 'i:u:hc') |
| 595 | + |
| 596 | + # handle command-line args |
| 597 | + self.instance_home = os.environ.get('ROUNDUP_INSTANCE', '') |
| 598 | + name = password = '' |
| 599 | + if os.environ.has_key('ROUNDUP_LOGIN'): |
| 600 | + l = os.environ['ROUNDUP_LOGIN'].split(':') |
| 601 | + name = l[0] |
| 602 | + if len(l) > 1: |
| 603 | + password = l[1] |
| 604 | + self.comma_sep = 0 |
| 605 | + for opt, arg in opts: |
| 606 | + if opt == '-h': |
| 607 | + usage() |
| 608 | + return 0 |
| 609 | + if opt == '-i': |
| 610 | + self.instance_home = arg |
| 611 | + if opt == '-c': |
| 612 | + self.comma_sep = 1 |
| 613 | + |
| 614 | + # if no command - go interactive |
| 615 | + if not args: |
| 616 | + return self.interactive() |
| 617 | + |
| 618 | + self.run_command(args) |
597 | 619 |
|
598 | 620 |
|
599 | 621 | if __name__ == '__main__': |
600 | | - sys.exit(main()) |
| 622 | + tool = AdminTool() |
| 623 | + sys.exit(tool.main()) |
601 | 624 |
|
602 | 625 | # |
603 | 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 | 630 | # Revision 1.28 2001/10/13 00:07:39 richard |
605 | 631 | # More help in admin tool. |
606 | 632 | # |
|
0 commit comments