# HG changeset patch
# User W. Trevor King <wking@tremily.us>
# Date 1340389836 14400
# Node ID 139a50e588d0052ee04cc75dcb78e05e8c16dedc
# Parent 45ac4cd1a3816199b188f969f5823301641c0b48
Add -f (force) option to roundup-admin.
This is necessary for the upcoming testAdminDuplicateInitialisation,
but it also makes it easier to mindlessly select defaults when you're
getting started.
While I was at it, I consolidated the "choose a value from a list"
logic into AdminTool._get_choice()
If this seems like a bad idea, we could keep the AdminTool.force
attribute, but not expose it through Getopt.
diff -r 45ac4cd1a381 -r 139a50e588d0 CHANGES.txt
--- a/CHANGES.txt Sun Jun 17 20:29:57 2012 +0800
+++ b/CHANGES.txt Fri Jun 22 14:30:36 2012 -0400
@@ -7,7 +7,10 @@
Features:
-- ...
+- Add -f (force) option to roundup-admin. This is necessary for
+ testAdminDuplicateInitialisation, but it also makes it easier to
+ mindlessly select defaults when you're getting started. Like most
+ --force options, this should probably be used sparingly.
Fixed:
diff -r 45ac4cd1a381 -r 139a50e588d0 roundup/admin.py
--- a/roundup/admin.py Sun Jun 17 20:29:57 2012 +0800
+++ b/roundup/admin.py Fri Jun 22 14:30:36 2012 -0400
@@ -72,6 +72,7 @@
self.tracker_home = ''
self.db = None
self.db_uncommitted = False
+ self.force = None
def get_class(self, classname):
"""Get the class - raise an exception if it doesn't exist.
@@ -113,6 +114,7 @@
-i instance home -- specify the issue tracker "home directory" to administer
-u -- the user[:password] to use for commands
-d -- print full designators not just class id numbers
+ -f -- force potentially dangerous action, never prompt
-c -- when outputting lists of data, comma-separate them.
Same as '-S ","'.
-S <string> -- when outputting lists of data, string-separate them
@@ -379,36 +381,35 @@
# check for both old- and new-style configs
if list(filter(os.path.exists, [config_ini_file,
os.path.join(tracker_home, 'config.py')])):
- ok = raw_input(_(
+ if not self.force:
+ ok = raw_input(_(
"""WARNING: There appears to be a tracker in "%(tracker_home)s"!
If you re-install it, you will lose all the data!
Erase it? Y/N: """) % locals())
- if ok.strip().lower() != 'y':
- return 0
+ if ok.strip().lower() != 'y':
+ return 0
# clear it out so the install isn't confused
shutil.rmtree(tracker_home)
# select template
templates = self.listTemplates()
- template = len(args) > 1 and args[1] or ''
- if template not in templates:
- print _('Templates:'), ', '.join(templates)
- while template not in templates:
- template = raw_input(_('Select template [classic]: ')).strip()
- if not template:
- template = 'classic'
+ template = self._get_choice(
+ list_name=_('Templates:'),
+ prompt=_('Select template'),
+ options=templates,
+ argument=len(args) > 1 and args[1] or '',
+ default='classic')
# select hyperdb backend
import roundup.backends
backends = roundup.backends.list_backends()
- backend = len(args) > 2 and args[2] or ''
- if backend not in backends:
- print _('Back ends:'), ', '.join(backends)
- while backend not in backends:
- backend = raw_input(_('Select backend [anydbm]: ')).strip()
- if not backend:
- backend = 'anydbm'
+ backend = self._get_choice(
+ list_name=_('Back ends:'),
+ prompt=_('Select backend'),
+ options=backends,
+ argument=len(args) > 2 and args[2] or '',
+ default='anydbm')
# XXX perform a unit test based on the user's selections
# Process configuration file definitions
@@ -457,6 +458,21 @@
}
return 0
+ def _get_choice(self, list_name, prompt, options, argument, default=None):
+ if default is None in options:
+ default = options[0] # just pick the first one
+ if argument in options:
+ return argument
+ if self.force:
+ return default
+ raw_prompt = '%s:' % (name.title())
+ print '%s: %s' % (list_name, ', '.join(options))
+ while argument not in options:
+ argument = raw_input('%s [%s]:' % (prompt, default))
+ if not argument:
+ return default
+ return argument
+
def do_genconfig(self, args):
''"""Usage: genconfig <filename>
Generate a new tracker config file (ini style) with default values
@@ -495,12 +511,13 @@
# is there already a database?
if tracker.exists():
- ok = raw_input(_(
+ if not self.force:
+ ok = raw_input(_(
"""WARNING: The database is already initialised!
If you re-initialise it, you will lose all the data!
Erase it? Y/N: """))
- if ok.strip().lower() != 'y':
- return 0
+ if ok.strip().lower() != 'y':
+ return 0
backend = tracker.get_backend_name()
@@ -1447,7 +1464,10 @@
# make sure we have a tracker_home
while not self.tracker_home:
- self.tracker_home = raw_input(_('Enter tracker home: ')).strip()
+ if not self.force:
+ self.tracker_home = raw_input(_('Enter tracker home: ')).strip()
+ else:
+ self.tracker_home = os.curdir
# before we open the db, we may be doing an install or init
if command == 'initialise':
@@ -1521,7 +1541,7 @@
def main(self):
try:
- opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV')
+ opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdfsS:vV')
except getopt.GetoptError, e:
self.usage(str(e))
return 1
@@ -1566,6 +1586,8 @@
self.separator = ' '
elif opt == '-d':
self.print_designator = 1
+ elif opt == '-f':
+ self.force = True
# if no command - go interactive
# wrap in a try/finally so we always close off the db |