Mercurial > hg > ltpdarepo
changeset 125:ab38e8a0eb8d
Minor tweaks to the admin command line interface.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Fri, 14 Oct 2011 10:34:33 +0200 |
parents | bb2d213cdd7e |
children | 18b94c01d497 |
files | src/ltpdarepo/admin.py |
diffstat | 1 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/admin.py Wed Oct 12 20:26:18 2011 +0200 +++ b/src/ltpdarepo/admin.py Fri Oct 14 10:34:33 2011 +0200 @@ -1,9 +1,9 @@ +import sys import argparse import logging import warnings from contextlib import contextmanager -from pprint import pprint from string import lower import MySQLdb as mysql @@ -34,7 +34,7 @@ class verbosity(argparse.Action): def __call__(self, *args, **kwargs): # increse logging level - logger = logging.getLogger('ltdarepo') + logger = logging.getLogger('ltpdarepo') logger.setLevel(logger.level - 10) @@ -64,10 +64,14 @@ return self.parser.parse_args(*args) def dispatch(self): - args = self.parser.parse_args() - command = args.command - del args.command - command(**vars(args)) + args = vars(self.parser.parse_args()) + command = args.pop('command') + try: + command(**args) + except Exception: + import traceback + sys.stderr.write(traceback.format_exc()) + sys.exit(1) def __iter__(self): return iter(sorted(self.commands.choices.keys())) @@ -84,7 +88,7 @@ from .upgrade import upgrade cmd = commands.add(upgrade) -cmd.add_argument('--from', type=float, dest='fromrev', metavar='REV') +cmd.add_argument('--from', type=float, dest='force', metavar='REV') def useradd(username, password=None, **kwargs): @@ -166,7 +170,7 @@ from collections import defaultdict privs = defaultdict(lambda: {'select': False, 'insert': False, 'update': False, 'delete': False}) - + curs.execute('''SELECT DISTINCT Db, Select_priv, Insert_priv, Update_priv, Delete_priv FROM mysql.db WHERE User=%s''', username) for row in curs.fetchall(): @@ -179,6 +183,7 @@ return privs[database] return privs + def _privileges(username): privs = privileges(username) if privs: @@ -353,7 +358,7 @@ warnings.filterwarnings('ignore', module='MySQLdb') # dispatch command line - return commands.dispatch() + commands.dispatch() if __name__ == '__main__':