diff options
author | dol-sen <brian.dolbec@gmail.com> | 2011-08-06 11:24:51 -0700 |
---|---|---|
committer | dol-sen <brian.dolbec@gmail.com> | 2011-08-06 11:24:51 -0700 |
commit | 53db3cb076054b41e5479299526c67f7cd4d0871 (patch) | |
tree | 16ca5008e7eda32db57b894b4a1e619af0ffeb4e /layman | |
parent | 6bfa7e9204b4af2ee0fc816c87ea2bffcce61ccb (diff) | |
download | layman-53db3cb076054b41e5479299526c67f7cd4d0871.tar.gz layman-53db3cb076054b41e5479299526c67f7cd4d0871.tar.bz2 layman-53db3cb076054b41e5479299526c67f7cd4d0871.zip |
add --debug-level to cli options and code Message.debug()
Diffstat (limited to 'layman')
-rw-r--r-- | layman/argsparser.py | 17 | ||||
-rw-r--r-- | layman/output.py | 12 |
2 files changed, 27 insertions, 2 deletions
diff --git a/layman/argsparser.py b/layman/argsparser.py index dee5d43..fd255d7 100644 --- a/layman/argsparser.py +++ b/layman/argsparser.py @@ -224,6 +224,14 @@ class ArgsParser(BareConfig): 'ssue a warning if description or contact information' ' are missing.') + group.add_option('--debug-level', + action = 'store', + type = 'int', + help = 'A value between 0 and 10. 0 means no debugging ' + 'messages will be selected, 10 selects all debugging me' + 'ssages. Default is "4".') + + self.parser.add_option_group(group) #----------------------------------------------------------------- @@ -246,6 +254,15 @@ class ArgsParser(BareConfig): # handle debugging #self.output.cli_handle(self.options) + if (self.options.__dict__.has_key('debug_level') and + self.options.__dict__['debug_level']): + dbglvl = int(self.options.__dict__['debug_level']) + if dbglvl < 0: + dbglvl = 0 + if dbglvl > 10: + dbglvl = 10 + self.output.set_debug_level(dbglvl) + if self.options.__dict__['nocolor']: self.output.set_colorize(OFF) diff --git a/layman/output.py b/layman/output.py index 06161ca..6751b59 100644 --- a/layman/output.py +++ b/layman/output.py @@ -110,7 +110,14 @@ class Message(MessageBase): """empty debug function, does nothing, declared here for compatibility with DebugMessage """ - pass + if type(info) not in types.StringTypes: + info = str(info) + + if level > self.debug_lev: + return + + for i in info.split('\n'): + print(self.color_func('yellow', 'DEBUG: ') + i, file=self.std_out) def notice (self, note): @@ -180,8 +187,9 @@ class Message(MessageBase): # stay in nice order. This is a workaround for calls like # "layman -L |& less". sys.stdout.flush() - print(self.color_func('red', '* ') + i, file=self.std_out) self.error_out.flush() + print(self.color_func('red', '* ') + i, file=self.std_out) + sys.stdout.flush() self.do_error_callback(error) |