diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-01 19:02:50 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-15 12:28:55 +0200 |
commit | d9f1378c02972772e9a8d67bb5c9bcb50033c5f7 (patch) | |
tree | 252c19272a43fbdd8ffe6d136b17c00f6fa13481 | |
parent | 5aecfefa9ad76b851268410525979cc982fd1b17 (diff) | |
download | nbb-d9f1378c02972772e9a8d67bb5c9bcb50033c5f7.tar.gz nbb-d9f1378c02972772e9a8d67bb5c9bcb50033c5f7.tar.xz nbb-d9f1378c02972772e9a8d67bb5c9bcb50033c5f7.zip |
Make loglevel settable via cmdline option
-rw-r--r-- | src/nbb.in | 45 | ||||
-rw-r--r-- | src/nbblib/main.py | 25 |
2 files changed, 53 insertions, 17 deletions
@@ -16,23 +16,33 @@ if sys.version_info < (2,4): import logging # since python 2.3 -# funcName: Since python 2.5 -# format="%(filename)s:%(lineno)d:%(funcName)s:" -logging.basicConfig(format = "%(levelname)s: %(message)s", - # level = logging.DEBUG, - level = logging.WARNING, - stream = sys.stderr) -if False: - logging.debug("xxx debug") - logging.info("xxx info") - logging.warning("xxx warn") - logging.error("xxx error") -if __name__ == '__main__': +def logmain(argv): + # funcName: Since python 2.5 + # format="%(filename)s:%(lineno)d:%(funcName)s:" + logformat = "%(levelname)s: %(message)s" + loglevel = logging.WARNING + for i in range(len(argv)): + if argv[i] in ('--debug', ): + loglevel = logging.DEBUG + elif argv[i] in ('--info', ): + loglevel = logging.INFO + logging.basicConfig(format = logformat, + level = loglevel, + stream = sys.stderr) + if False: + logging.debug("xxx debug") + logging.info("xxx info") + logging.warning("xxx warn") + logging.error("xxx error") + + +def nbbmain(argv): + logmain(argv[1:]) pkgpythondir = "@pkgpythondir@" lib_found = False - #print "pkgpythondir", pkgpythondir - #print "sys.path", sys.path + logging.debug("pkgpythondir %s", pkgpythondir) + logging.debug("sys.path %s", sys.path) sys.stdout.flush() orig_path = sys.path for cond, path in [ @@ -58,9 +68,16 @@ if __name__ == '__main__': logging.error("nbb: Fatal: Could not import nbblib.") logging.shutdown() sys.exit(3) + logging.info("Using nbblib loaded from %s, python prefix %s", + os.path.split(sys.modules['nbblib'].__file__)[0], sys.prefix) import nbblib.main nbblib.main.cmdmain(sys.argv) + +if __name__ == '__main__': + nbbmain(sys.argv) + + # vim: syntax=python # Local Variables: # mode: python diff --git a/src/nbblib/main.py b/src/nbblib/main.py index cf5ec52..3800665 100644 --- a/src/nbblib/main.py +++ b/src/nbblib/main.py @@ -173,14 +173,29 @@ class Context(object): vcs = VCSProperty() bs = BSProperty() dry_run = DryRunProperty() - verbose = BoolProperty() vcssystems = Property() buildsystems = Property() + def __init__(self): + super(Context, self).__init__() + for k in dir(self): + a = getattr(self, k) + if isinstance(a, Property): + logging.debug("setting property_name for %s", k) + a.property_name = k + def __getitem__(self, key): """emulate a dict() for the purpose of "%(prog)s" % context""" return getattr(self, key) + def __str__(self): + kk = [x for x in dir(self) if (x.find('__') < 0) and (x.find('--') < 0)] + kk.sort() + lll = ( (k, getattr(self,k)) for k in kk ) + return "%s(%s)" % (self.__class__.__name__, + ", ".join(("%s=%s" % (a,repr(c)) + for a,c in lll))) + def main(argv): context = Context() @@ -218,10 +233,13 @@ def main(argv): context.vcs = argv[i] elif argv[i][:6] == '--vcs=': context.vcs = argv[i][6:] - elif argv[i] in ('--verbose', ): - context.verbose = True + elif argv[i] in ('--info', '--debug'): + pass # acted on in previous stage + else: + raise commands.CommandLineError('Unknown global option %s' % repr(argv[i])) # print "", i, argv[i] i = i + 1 + logging.info("Context: %s", context) cmd = argv[i] cmdargs = argv[i+1:] nbb = commands.NBB_Command(cmd, cmdargs, context=context) @@ -250,3 +268,4 @@ def cmdmain(argv): __all__ = ['cmdmain', 'main'] + |