Skip to content

Commit 59c08c4

Browse files
author
Richard Jones
committed
Beginnings of an interactive mode for roundup-admin
1 parent fa6f67b commit 59c08c4

File tree

2 files changed

+96
-67
lines changed

2 files changed

+96
-67
lines changed

roundup-admin

Lines changed: 91 additions & 65 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: 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 $
2020

2121
import sys
2222
if int(sys.version[0]) < 2:
@@ -125,6 +125,8 @@ def do_help(args):
125125
help = figureCommands().get(args[0], None)
126126
if help:
127127
print help.__doc__
128+
else:
129+
print 'Sorry, no help for "%s"'%args[0]
128130

129131
def help_initopts():
130132
import roundup.templates
@@ -525,82 +527,106 @@ def figureHelp():
525527
d[k[5:]] = v
526528
return d
527529

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]
554534

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()
559546
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
581547

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()
585551

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)
589555

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)
595557

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)
597619

598620

599621
if __name__ == '__main__':
600-
sys.exit(main())
622+
tool = AdminTool()
623+
sys.exit(tool.main())
601624

602625
#
603626
# $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+
#
604630
# Revision 1.28 2001/10/13 00:07:39 richard
605631
# More help in admin tool.
606632
#

setup.py

Lines changed: 5 additions & 2 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: setup.py,v 1.22 2001-10-11 05:01:28 richard Exp $
19+
# $Id: setup.py,v 1.23 2001-10-17 06:04:00 richard Exp $
2020

2121
from distutils.core import setup, Extension
2222
from distutils.util import get_platform
@@ -42,7 +42,7 @@
4242

4343

4444
setup ( name = "roundup",
45-
version = "0.3.0pre2",
45+
version = "0.3.0pre3",
4646
description = "Roundup issue tracking system.",
4747
author = "Richard Jones",
4848
author_email = "[email protected]",
@@ -53,6 +53,9 @@
5353

5454
#
5555
# $Log: not supported by cvs2svn $
56+
# Revision 1.22 2001/10/11 05:01:28 richard
57+
# Prep for pre-release #2
58+
#
5659
# Revision 1.21 2001/10/10 04:18:38 richard
5760
# Getting ready for a preview release for 0.3.0.
5861
#

0 commit comments

Comments
 (0)