comparison roundup/admin.py @ 5230:62a88d69ac52

Add new command updateconfig to admin command. This acts like genconfig but loads the current tracker's config.ini rather than a new default config.
author John Rouillard <rouilj@ieee.org>
date Tue, 11 Apr 2017 21:51:28 -0400
parents cb61b7935fec
children 462b0f76fce8
comparison
equal deleted inserted replaced
5229:cb61b7935fec 5230:62a88d69ac52
24 import csv, getopt, getpass, os, re, shutil, sys, UserDict, operator 24 import csv, getopt, getpass, os, re, shutil, sys, UserDict, operator
25 25
26 from roundup import date, hyperdb, roundupdb, init, password, token 26 from roundup import date, hyperdb, roundupdb, init, password, token
27 from roundup import __version__ as roundup_version 27 from roundup import __version__ as roundup_version
28 import roundup.instance 28 import roundup.instance
29 from roundup.configuration import CoreConfig 29 from roundup.configuration import CoreConfig, NoConfigError
30 from roundup.i18n import _ 30 from roundup.i18n import _
31 from roundup.exceptions import UsageError 31 from roundup.exceptions import UsageError
32 32
33 class CommandDict(UserDict.UserDict): 33 class CommandDict(UserDict.UserDict):
34 """Simple dictionary that lets us do lookups using partial keys. 34 """Simple dictionary that lets us do lookups using partial keys.
468 argument = raw_input('%s [%s]: ' % (prompt, default)) 468 argument = raw_input('%s [%s]: ' % (prompt, default))
469 if not argument: 469 if not argument:
470 return default 470 return default
471 return argument 471 return argument
472 472
473 def do_genconfig(self, args): 473 def do_genconfig(self, args, update=False):
474 ''"""Usage: genconfig <filename> 474 ''"""Usage: genconfig <filename>
475 Generate a new tracker config file (ini style) with default values 475 Generate a new tracker config file (ini style) with default values
476 in <filename>. 476 in <filename>.
477 """ 477 """
478 if len(args) < 1: 478 if len(args) < 1:
479 raise UsageError(_('Not enough arguments supplied')) 479 raise UsageError(_('Not enough arguments supplied'))
480 config = CoreConfig() 480 if update:
481 # load current config for writing
482 config = CoreConfig(self.tracker_home)
483 else:
484 # generate default config
485 config = CoreConfig()
481 config.save(args[0]) 486 config.save(args[0])
487
488 def do_updateconfig(self, args):
489 ''"""Usage: updateconfig <filename>
490 Generate an updated tracker config file (ini style) in
491 <filename>. Use current settings from existing roundup
492 tracker in tracker home.
493 """
494 self.do_genconfig(args, update=True)
482 495
483 def do_initialise(self, tracker_home, args): 496 def do_initialise(self, tracker_home, args):
484 ''"""Usage: initialise [adminpw] 497 ''"""Usage: initialise [adminpw]
485 Initialise a new Roundup tracker. 498 Initialise a new Roundup tracker.
486 499
1486 tracker = roundup.instance.open(self.tracker_home) 1499 tracker = roundup.instance.open(self.tracker_home)
1487 except ValueError, message: 1500 except ValueError, message:
1488 self.tracker_home = '' 1501 self.tracker_home = ''
1489 print _("Error: Couldn't open tracker: %(message)s")%locals() 1502 print _("Error: Couldn't open tracker: %(message)s")%locals()
1490 return 1 1503 return 1
1504 except NoConfigError, message:
1505 self.tracker_home = ''
1506 print _("Error: Couldn't open tracker: %(message)s")%locals()
1507 return 1
1491 1508
1492 # only open the database once! 1509 # only open the database once!
1493 if not self.db: 1510 if not self.db:
1494 self.db = tracker.open('admin') 1511 self.db = tracker.open('admin')
1495 1512

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