diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-06-23 13:06:01 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-15 12:28:52 +0200 |
commit | 005a3823b340efd6702d821bd723ee861cd4d10b (patch) | |
tree | 04c3f087b22acd07d7ef9babd9c846047d00c892 | |
parent | d710dbb05ec386ae5f72d332cb48de77cb80da6b (diff) | |
download | nbb-005a3823b340efd6702d821bd723ee861cd4d10b.tar.gz nbb-005a3823b340efd6702d821bd723ee861cd4d10b.tar.xz nbb-005a3823b340efd6702d821bd723ee861cd4d10b.zip |
Improve command line exception handling
-rw-r--r-- | src/nbb.in | 2 | ||||
-rw-r--r-- | src/nbblib/commands.py | 4 | ||||
-rw-r--r-- | src/nbblib/main.py | 22 |
3 files changed, 20 insertions, 8 deletions
@@ -39,7 +39,7 @@ if __name__ == '__main__': sys.stderr.write("nbb: Fatal: Could not load nbblib.\n") sys.exit(3) import nbblib.main - nbblib.main.main(sys.argv) + nbblib.main.cmdmain(sys.argv) # vim: syntax=python # Local Variables: diff --git a/src/nbblib/commands.py b/src/nbblib/commands.py index 45e3a61..a257be2 100644 --- a/src/nbblib/commands.py +++ b/src/nbblib/commands.py @@ -26,10 +26,12 @@ def adjust_doc(doc): class CommandLineError(Exception): - def __init__(self, message, *args): + def __init__(self, message, *args, **kwargs): super(CommandLineError, self).__init__() if args: self.msg = message % args + elif kwargs: + self.msg = message % kwargs else: self.msg = message def __str__(self): diff --git a/src/nbblib/main.py b/src/nbblib/main.py index 1792792..a1a16e3 100644 --- a/src/nbblib/main.py +++ b/src/nbblib/main.py @@ -21,15 +21,16 @@ Features: DONE: * VCS config support ('git config', etc.) * Build system support: automake/autoconf + * Merge stuff from Eclipse to src/own/nbb and vice versa. TODO: (Large list) - * Merge stuff from Eclipse to src/own/nbb and vice versa. - * Build system support: cmake, scons, ... + * BS support: cmake, scons, ... + * VCS support: SVN, darcs, hg, ... * Fine-tune init, configure, build, install commands with knowledge gained with git-amb, especially the command interdependencies. * Out-of-source builds for systems which require in-source-tree builds: - cp -rl foo.src foo.build ? - * implement *-sh and *-run commands + "cp -rl foo.src foo.build"? + * Implement *-sh and *-run commands. * General removal of redundancy in Python code. * Make sure the if cmp ... mv .. rm in make rules are correct and useful. * More declarative syntax elements in the Python code. @@ -214,8 +215,8 @@ def main(argv): context.prog = argv[0] if len(argv) < 2: - print "Fatal: %(prog)s requires some arguments" % context - return 2 + raise CommandLineError("%(prog)s requires some arguments", + prog=context.prog) i = 1 while i<len(argv): @@ -248,3 +249,12 @@ def main(argv): cmd = argv[i] cmdargs = argv[i+1:] nbb = NBB_Command(cmd, cmdargs, context=context) + + +def cmdmain(argv): + try: + main(argv) + except CommandLineError, e: + print e + sys.exit(2) + |