# HG changeset patch # User Daniele Nicolodi # Date 1309193866 -7200 # Node ID 1b37af4b842cc53884f6fa7c96a49ebb643fb80f # Parent d45fa969ebf92a255275260f49aaa5a90fa3e433 Fix help display in command line tool and add minimal documentation. diff -r d45fa969ebf9 -r 1b37af4b842c src/ltpdarepo/admin.py --- a/src/ltpdarepo/admin.py Mon Jun 27 17:14:47 2011 +0200 +++ b/src/ltpdarepo/admin.py Mon Jun 27 18:57:46 2011 +0200 @@ -39,29 +39,31 @@ class Commands(object): def __init__(self): - self.params = argparse.ArgumentParser() - self.commands = self.params.add_subparsers(title='commands', - description='') - self.params.add_argument('-v', '--verbose', action=verbosity, - nargs=0, dest=argparse.SUPPRESS, - help='increase verbosity') + self.parser = argparse.ArgumentParser(add_help=False) + self.commands = self.parser.add_subparsers(metavar='command') + options = self.parser.add_argument_group('options') + options.add_argument('-v', '--verbose', action=verbosity, + nargs=0, dest=argparse.SUPPRESS, + help='increase verbosity') def add_argument(self, *args, **kwargs): - return self.params.add_argument(*args, **kwargs) + return self.parser.add_argument(*args, **kwargs) def add(self, func, name=None): name = name or func.__name__ - parser = self.commands.add_parser(name, help=func.__doc__, - description=func.__doc__, + desc = func.__doc__ or ' ' + parser = self.commands.add_parser(name, + help=desc.splitlines()[0], + description=desc, add_help=False) parser.set_defaults(command=func) return parser def parse(self, *args): - return self.params.parse_args(*args) + return self.parser.parse_args(*args) def dispatch(self): - args = self.params.parse_args() + args = self.parser.parse_args() command = args.command del args.command command(**vars(args)) @@ -83,7 +85,10 @@ cmd = commands.add(upgrade) cmd.add_argument('--from', type=float, dest='fromrev', metavar='REV') + def useradd(username, password=None, **kwargs): + """create user account""" + with interact(app): user = User.load(username) if user is not None: @@ -100,6 +105,8 @@ def userdel(username): + """delete user account""" + with interact(app): user = User.load(username) if user is None: @@ -111,6 +118,8 @@ def passwd(username, password): + """change password for a given user""" + with interact(app): user = User.load(username) if user is None: @@ -123,6 +132,8 @@ def grant(username, database, privs): + """grant permissions to given user for a specific database""" + conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD) curs = conn.cursor() @@ -144,6 +155,8 @@ def privileges(username): + """show privileges for given user""" + conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD) curs = conn.cursor() @@ -163,6 +176,8 @@ def createdb(database, name='', description=''): + """create database""" + with interact(app): db = Database.load(database) if db is not None: @@ -177,6 +192,8 @@ def dropdb(database): + """delete database""" + with interact(app): db = Database.load(database) if db is None: @@ -288,13 +305,16 @@ return print "LTPDA Repository administration tool" + print commands.parser.format_usage().strip() print "" print "commands:" - print "" for cmd in commands: doc = commands[cmd].description or ' ' print " %-15s %s" % (cmd, doc.splitlines()[0]) print "" + print "options:" + print " %-15s %s" % ("-v, --verbose", "increase verbosity. may be specified multiple times") + print "" cmd = commands.add(help) cmd.add_argument('name', nargs='?', help='command', metavar='NAME') @@ -426,4 +446,3 @@ odio ac est consequat nec posuere nisi scelerisque. Vivamus in sapien eu lacus consequat tempor. Proin in purus purus. Curabitur et velit vitae risus viverra fringilla vitae at nunc.""" - diff -r d45fa969ebf9 -r 1b37af4b842c src/ltpdarepo/install.py --- a/src/ltpdarepo/install.py Mon Jun 27 17:14:47 2011 +0200 +++ b/src/ltpdarepo/install.py Mon Jun 27 18:57:46 2011 +0200 @@ -4,6 +4,8 @@ def install(): + """create LTDA repository database tables""" + conn = db.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD) curs = conn.cursor() # curs.execute('DROP DATABASE IF EXISTS `%s`' % DATABASE) diff -r d45fa969ebf9 -r 1b37af4b842c src/ltpdarepo/upgrade.py --- a/src/ltpdarepo/upgrade.py Mon Jun 27 17:14:47 2011 +0200 +++ b/src/ltpdarepo/upgrade.py Mon Jun 27 18:57:46 2011 +0200 @@ -18,6 +18,8 @@ def upgrade(fromrev=None): + """run database schema upgrade steps""" + conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD) curs = conn.cursor() logger = logging.getLogger(__name__)