comparison roundup/admin.py @ 7182:0c6617db0b97

Add testing interactive mode to roundup_admin. remove redundant imports
author John Rouillard <rouilj@ieee.org>
date Sun, 26 Feb 2023 13:34:14 -0500
parents db06d4aeb978
children 12a3cd86668f
comparison
equal deleted inserted replaced
7181:6971c9249c6d 7182:0c6617db0b97
81 Actions are defined by do_*() methods, with help for the action 81 Actions are defined by do_*() methods, with help for the action
82 given in the method docstring. 82 given in the method docstring.
83 83
84 Additional help may be supplied by help_*() methods. 84 Additional help may be supplied by help_*() methods.
85 """ 85 """
86
87 # Make my_input a property to allow overriding in testing.
88 # my_input is imported in other places, so just set it from
89 # the imported value rather than moving def here.
90 my_input = my_input
91
86 def __init__(self): 92 def __init__(self):
87 self.commands = CommandDict() 93 self.commands = CommandDict()
88 for k in AdminTool.__dict__: 94 for k in AdminTool.__dict__:
89 if k[:3] == 'do_': 95 if k[:3] == 'do_':
90 self.commands[k[3:]] = getattr(self, k) 96 self.commands[k[3:]] = getattr(self, k)
440 config_ini_file = os.path.join(tracker_home, CoreConfig.INI_FILE) 446 config_ini_file = os.path.join(tracker_home, CoreConfig.INI_FILE)
441 # check for both old- and new-style configs 447 # check for both old- and new-style configs
442 if list(filter(os.path.exists, [config_ini_file, 448 if list(filter(os.path.exists, [config_ini_file,
443 os.path.join(tracker_home, 'config.py')])): 449 os.path.join(tracker_home, 'config.py')])):
444 if not self.force: 450 if not self.force:
445 ok = my_input(_( 451 ok = self.my_input(_(
446 """WARNING: There appears to be a tracker in "%(tracker_home)s"! 452 """WARNING: There appears to be a tracker in "%(tracker_home)s"!
447 If you re-install it, you will lose all the data! 453 If you re-install it, you will lose all the data!
448 Erase it? Y/N: """) % locals()) # noqa: E122 454 Erase it? Y/N: """) % locals()) # noqa: E122
449 if ok.strip().lower() != 'y': 455 if ok.strip().lower() != 'y':
450 return 0 456 return 0
546 return argument 552 return argument
547 if self.force: 553 if self.force:
548 return default 554 return default
549 sys.stdout.write('%s: %s\n' % (list_name, ', '.join(options))) 555 sys.stdout.write('%s: %s\n' % (list_name, ', '.join(options)))
550 while argument not in options: 556 while argument not in options:
551 argument = my_input('%s [%s]: ' % (prompt, default)) 557 argument = self.my_input('%s [%s]: ' % (prompt, default))
552 if not argument: 558 if not argument:
553 return default 559 return default
554 return argument 560 return argument
555 561
556 def do_genconfig(self, args, update=False): 562 def do_genconfig(self, args, update=False):
603 raise UsageError(_('Instance has not been installed') % locals()) 609 raise UsageError(_('Instance has not been installed') % locals())
604 610
605 # is there already a database? 611 # is there already a database?
606 if tracker.exists(): 612 if tracker.exists():
607 if not self.force: 613 if not self.force:
608 ok = my_input(_( 614 ok = self.my_input(_(
609 """WARNING: The database is already initialised! 615 """WARNING: The database is already initialised!
610 If you re-initialise it, you will lose all the data! 616 If you re-initialise it, you will lose all the data!
611 Erase it? Y/N: """)) # noqa: E122 617 Erase it? Y/N: """)) # noqa: E122
612 if ok.strip().lower() != 'y': 618 if ok.strip().lower() != 'y':
613 return 0 619 return 0
1015 if value != again: 1021 if value != again:
1016 print(_('Sorry, try again...')) 1022 print(_('Sorry, try again...'))
1017 if value: 1023 if value:
1018 props[key] = value 1024 props[key] = value
1019 else: 1025 else:
1020 value = my_input(_('%(propname)s (%(proptype)s): ') % { 1026 value = self.my_input(_('%(propname)s (%(proptype)s): ') % {
1021 'propname': key.capitalize(), 'proptype': name}) 1027 'propname': key.capitalize(), 'proptype': name})
1022 if value: 1028 if value:
1023 props[key] = value 1029 props[key] = value
1024 else: 1030 else:
1025 props = self.props_from_args(args[1:]) 1031 props = self.props_from_args(args[1:])
1749 command, function = functions[0] 1755 command, function = functions[0]
1750 1756
1751 # make sure we have a tracker_home 1757 # make sure we have a tracker_home
1752 while not self.tracker_home: 1758 while not self.tracker_home:
1753 if not self.force: 1759 if not self.force:
1754 self.tracker_home = my_input(_('Enter tracker home: ')).strip() 1760 self.tracker_home = self.my_input(_('Enter tracker home: ')).strip()
1755 else: 1761 else:
1756 self.tracker_home = os.curdir 1762 self.tracker_home = os.curdir
1757 1763
1758 # before we open the db, we may be doing an install or init 1764 # before we open the db, we may be doing an install or init
1759 if command == 'initialise': 1765 if command == 'initialise':
1823 except ImportError: 1829 except ImportError:
1824 print(_('Note: command history and editing not available')) 1830 print(_('Note: command history and editing not available'))
1825 1831
1826 while 1: 1832 while 1:
1827 try: 1833 try:
1828 command = my_input('roundup> ') 1834 command = self.my_input('roundup> ')
1829 except EOFError: 1835 except EOFError:
1830 print(_('exit...')) 1836 print(_('exit...'))
1831 break 1837 break
1832 if not command: continue # noqa: E701 1838 if not command: continue # noqa: E701
1833 try: 1839 try:
1838 if args[0] in ('quit', 'exit'): break # noqa: E701 1844 if args[0] in ('quit', 'exit'): break # noqa: E701
1839 self.run_command(args) 1845 self.run_command(args)
1840 1846
1841 # exit.. check for transactions 1847 # exit.. check for transactions
1842 if self.db and self.db_uncommitted: 1848 if self.db and self.db_uncommitted:
1843 commit = my_input(_('There are unsaved changes. Commit them (y/N)? ')) 1849 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? '))
1844 if commit and commit[0].lower() == 'y': 1850 if commit and commit[0].lower() == 'y':
1845 self.db.commit() 1851 self.db.commit()
1846 return 0 1852 return 0
1847 1853
1848 def main(self): 1854 def main(self):

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