From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from <gentoo-commits+bounces-316434-garchives=archives.gentoo.org@lists.gentoo.org>) id 1Pomi3-0006Kn-Q2 for garchives@archives.gentoo.org; Mon, 14 Feb 2011 00:54:36 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3063AE09B4; Mon, 14 Feb 2011 00:54:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D2601E09B4 for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 00:54:13 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 178CC1B4085 for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 00:54:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 820B08006E for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 00:54:12 +0000 (UTC) From: "Brian Dolbec" <brian.dolbec@gmail.com> To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" <brian.dolbec@gmail.com> Message-ID: <6a85b05289ae2bb9f5da1748985322e83d064f60.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:overlord_merge commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/debug.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 6a85b05289ae2bb9f5da1748985322e83d064f60 Date: Mon, 14 Feb 2011 00:54:12 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 2709adddd9f7e93f60edda5008a915ec commit: 6a85b05289ae2bb9f5da1748985322e83d064f60 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> AuthorDate: Sun Feb 13 09:31:54 2011 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Sun Feb 13 09:31:54 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D6a85b052 simplify debug.py to subclass the simplified Message class --- layman/debug.py | 151 ++++++++-----------------------------------------= ----- 1 files changed, 23 insertions(+), 128 deletions(-) diff --git a/layman/debug.py b/layman/debug.py index 7c42974..d7af5aa 100644 --- a/layman/debug.py +++ b/layman/debug.py @@ -18,8 +18,10 @@ import sys, inspect, types =20 from optparse import OptionGroup =20 -from layman.constants import codes +from layman.constants import (codes, DEBUG_LEVEL, DEBUG_VERBOSITY, + INFO_LEVEL, WARN_LEVEL, OFF) =20 +from output import Message =20 ########################################################################= ######### ## @@ -27,7 +29,7 @@ from layman.constants import codes ## ########################################################################= ######### =20 -class Message: +class DebugMessage(Message): #FIXME: Think about some simple doctests before you modify this clas= s the # next time. =20 @@ -35,10 +37,10 @@ class Message: out =3D sys.stdout, err =3D sys.stderr, dbg =3D sys.stderr, - debugging_level =3D 4, - debugging_verbosity =3D 2, - info_level =3D 4, - warn_level =3D 4, + debugging_level =3D DEBUG_LEVEL, + debugging_verbosity =3D DEBUG_VERBOSITY, + info_level =3D INFO_LEVEL, + warn_level =3D WARN_LEVEL, col =3D True, mth =3D None, obj =3D None, @@ -94,6 +96,14 @@ class Message: =20 self.has_error =3D False =20 + Message.__init__(self, + out =3D self.std_out, + err =3D self.error_out, + info_level =3D self.info_level, + warn_level =3D self.warn_level, + col =3D self.col + ) + =20 ####################################################################= ######## # Add command line options @@ -170,9 +180,9 @@ class Message: =20 if (options.__dict__.has_key('debug') and options.__dict__['debug']): - self.debug_on() + self.set_debug_level(DEBUG_LEVEL) else: - self.debug_off() + self.set_debug_level(OFF) return =20 if (options.__dict__.has_key('debug_class_vars') @@ -183,9 +193,9 @@ class Message: =20 if (options.__dict__.has_key('debug_nocolor') and options.__dict__['debug_nocolor']): - self.color_off() + self.set_colorize(False) else: - self.color_on() + self.set_colorize(True) =20 if (options.__dict__.has_key('debug_level') and options.__dict__['debug_level']): @@ -242,46 +252,12 @@ class Message: if variables: self.debug_var =3D variables =20 - def maybe_color (self, col, text): - if self.use_color: - return codes[col] + text + codes['reset'] - return text - - def set_info_level(self, info_level =3D 4): - self.info_lev =3D info_level - - def info_off(self): - self.set_info_level(0) - - def info_on(self, info_level =3D 4): - self.set_info_level(info_level) - - def set_warn_level(self, warn_level =3D 4): - self.warn_lev =3D warn_level - - def warn_off(self): - self.set_warn_level(0) - - def warn_on(self, warn_level =3D 4): - self.set_warn_level(warn_level) - - def set_debug_level(self, debugging_level =3D 4): + def set_debug_level(self, debugging_level =3D DEBUG_LEVEL): self.debug_lev =3D debugging_level =20 - def set_debug_verbosity(self, debugging_verbosity =3D 2): + def set_debug_verbosity(self, debugging_verbosity =3D DEBUG_VERBOSIT= Y): self.debug_vrb =3D debugging_verbosity =20 - def debug_off(self): - self.set_debug_level(0) - - def debug_on(self): - self.set_debug_level() - - def color_off(self): - self.use_color =3D False - - def color_on(self): - self.use_color =3D True =20 def class_variables_off(self): self.show_class_variables =3D False @@ -292,88 +268,7 @@ class Message: ####################################################################= ######### ## Output Functions =20 - def notice (self, note): - print >> self.std_out, note - - def info (self, info, level =3D 4): - - #print "info =3D", info - - if type(info) not in types.StringTypes: - info =3D str(info) - - if level > self.info_lev: - return - - for i in info.split('\n'): - print >> self.std_out, self.maybe_color('green', '* ') + i - - def status (self, message, status, info =3D 'ignored'): - - if type(message) not in types.StringTypes: - message =3D str(message) - - lines =3D message.split('\n') - - if not lines: - return - - for i in lines[0:-1]: - print >> self.std_out, self.maybe_color('green', '* ') + i - - i =3D lines[-1] - - if len(i) > 58: - i =3D i[0:57] - - if status =3D=3D 1: - result =3D '[' + self.maybe_color('green', 'ok') + ']' - elif status =3D=3D 0: - result =3D '[' + self.maybe_color('red', 'failed') + ']' - else: - result =3D '[' + self.maybe_color('yellow', info) + ']' - - print >> self.std_out, self.maybe_color('green', '* ') + i + ' = ' + '.' * (58 - len(i)) \ - + ' ' + result - - def warn (self, warn, level =3D 4): - - #print "DEBUG.warn()" - - if type(warn) not in types.StringTypes: - warn =3D str(warn) - - if level > self.warn_lev: - return - - for i in warn.split('\n'): - print >> self.std_out, self.maybe_color('yellow', '* ') + i - - def error (self, error): - - if type(error) not in types.StringTypes: - error =3D str(error) - - for i in error.split('\n'): - # NOTE: Forced flushing ensures that stdout and stderr - # stay in nice order. This is a workaround for calls like - # "layman -L |& less". - sys.stdout.flush() - print >> self.error_out, self.maybe_color('red', '* ') + i - self.error_out.flush() - self.has_error =3D True - - def die (self, error): - - if type(error) not in types.StringTypes: - error =3D str(error) - - for i in error.split('\n'): - self.error(self.maybe_color('red', 'Fatal error: ') + i) - self.error(self.maybe_color('red', 'Fatal error(s) - aborting')) - sys.exit(1) - - def debug (self, message, level =3D 4): + def debug (self, message, level =3D DEBUG_LEVEL): ''' This is a generic debugging method. ''' From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from <gentoo-commits+bounces-316515-garchives=archives.gentoo.org@lists.gentoo.org>) id 1PorXa-0005E6-7b for garchives@archives.gentoo.org; Mon, 14 Feb 2011 06:04:11 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 820D6E09E7; Mon, 14 Feb 2011 06:00:34 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 3DD49E09CB for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 06:00:34 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CE7EE1B423B for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 06:00:33 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 4486280074 for <gentoo-commits@lists.gentoo.org>; Mon, 14 Feb 2011 06:00:33 +0000 (UTC) From: "Brian Dolbec" <brian.dolbec@gmail.com> To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" <brian.dolbec@gmail.com> Message-ID: <6a85b05289ae2bb9f5da1748985322e83d064f60.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/debug.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 6a85b05289ae2bb9f5da1748985322e83d064f60 Date: Mon, 14 Feb 2011 06:00:33 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 6a75af8fcc36cc3f24ab7d8fa29245ae Message-ID: <20110214060033.Ugx24U4-ob2aN3Vv1aNYQpgnVTTTbEc3JpfXbncFgfE@z> commit: 6a85b05289ae2bb9f5da1748985322e83d064f60 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> AuthorDate: Sun Feb 13 09:31:54 2011 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Sun Feb 13 09:31:54 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D6a85b052 simplify debug.py to subclass the simplified Message class --- layman/debug.py | 151 ++++++++-----------------------------------------= ----- 1 files changed, 23 insertions(+), 128 deletions(-) diff --git a/layman/debug.py b/layman/debug.py index 7c42974..d7af5aa 100644 --- a/layman/debug.py +++ b/layman/debug.py @@ -18,8 +18,10 @@ import sys, inspect, types =20 from optparse import OptionGroup =20 -from layman.constants import codes +from layman.constants import (codes, DEBUG_LEVEL, DEBUG_VERBOSITY, + INFO_LEVEL, WARN_LEVEL, OFF) =20 +from output import Message =20 ########################################################################= ######### ## @@ -27,7 +29,7 @@ from layman.constants import codes ## ########################################################################= ######### =20 -class Message: +class DebugMessage(Message): #FIXME: Think about some simple doctests before you modify this clas= s the # next time. =20 @@ -35,10 +37,10 @@ class Message: out =3D sys.stdout, err =3D sys.stderr, dbg =3D sys.stderr, - debugging_level =3D 4, - debugging_verbosity =3D 2, - info_level =3D 4, - warn_level =3D 4, + debugging_level =3D DEBUG_LEVEL, + debugging_verbosity =3D DEBUG_VERBOSITY, + info_level =3D INFO_LEVEL, + warn_level =3D WARN_LEVEL, col =3D True, mth =3D None, obj =3D None, @@ -94,6 +96,14 @@ class Message: =20 self.has_error =3D False =20 + Message.__init__(self, + out =3D self.std_out, + err =3D self.error_out, + info_level =3D self.info_level, + warn_level =3D self.warn_level, + col =3D self.col + ) + =20 ####################################################################= ######## # Add command line options @@ -170,9 +180,9 @@ class Message: =20 if (options.__dict__.has_key('debug') and options.__dict__['debug']): - self.debug_on() + self.set_debug_level(DEBUG_LEVEL) else: - self.debug_off() + self.set_debug_level(OFF) return =20 if (options.__dict__.has_key('debug_class_vars') @@ -183,9 +193,9 @@ class Message: =20 if (options.__dict__.has_key('debug_nocolor') and options.__dict__['debug_nocolor']): - self.color_off() + self.set_colorize(False) else: - self.color_on() + self.set_colorize(True) =20 if (options.__dict__.has_key('debug_level') and options.__dict__['debug_level']): @@ -242,46 +252,12 @@ class Message: if variables: self.debug_var =3D variables =20 - def maybe_color (self, col, text): - if self.use_color: - return codes[col] + text + codes['reset'] - return text - - def set_info_level(self, info_level =3D 4): - self.info_lev =3D info_level - - def info_off(self): - self.set_info_level(0) - - def info_on(self, info_level =3D 4): - self.set_info_level(info_level) - - def set_warn_level(self, warn_level =3D 4): - self.warn_lev =3D warn_level - - def warn_off(self): - self.set_warn_level(0) - - def warn_on(self, warn_level =3D 4): - self.set_warn_level(warn_level) - - def set_debug_level(self, debugging_level =3D 4): + def set_debug_level(self, debugging_level =3D DEBUG_LEVEL): self.debug_lev =3D debugging_level =20 - def set_debug_verbosity(self, debugging_verbosity =3D 2): + def set_debug_verbosity(self, debugging_verbosity =3D DEBUG_VERBOSIT= Y): self.debug_vrb =3D debugging_verbosity =20 - def debug_off(self): - self.set_debug_level(0) - - def debug_on(self): - self.set_debug_level() - - def color_off(self): - self.use_color =3D False - - def color_on(self): - self.use_color =3D True =20 def class_variables_off(self): self.show_class_variables =3D False @@ -292,88 +268,7 @@ class Message: ####################################################################= ######### ## Output Functions =20 - def notice (self, note): - print >> self.std_out, note - - def info (self, info, level =3D 4): - - #print "info =3D", info - - if type(info) not in types.StringTypes: - info =3D str(info) - - if level > self.info_lev: - return - - for i in info.split('\n'): - print >> self.std_out, self.maybe_color('green', '* ') + i - - def status (self, message, status, info =3D 'ignored'): - - if type(message) not in types.StringTypes: - message =3D str(message) - - lines =3D message.split('\n') - - if not lines: - return - - for i in lines[0:-1]: - print >> self.std_out, self.maybe_color('green', '* ') + i - - i =3D lines[-1] - - if len(i) > 58: - i =3D i[0:57] - - if status =3D=3D 1: - result =3D '[' + self.maybe_color('green', 'ok') + ']' - elif status =3D=3D 0: - result =3D '[' + self.maybe_color('red', 'failed') + ']' - else: - result =3D '[' + self.maybe_color('yellow', info) + ']' - - print >> self.std_out, self.maybe_color('green', '* ') + i + ' = ' + '.' * (58 - len(i)) \ - + ' ' + result - - def warn (self, warn, level =3D 4): - - #print "DEBUG.warn()" - - if type(warn) not in types.StringTypes: - warn =3D str(warn) - - if level > self.warn_lev: - return - - for i in warn.split('\n'): - print >> self.std_out, self.maybe_color('yellow', '* ') + i - - def error (self, error): - - if type(error) not in types.StringTypes: - error =3D str(error) - - for i in error.split('\n'): - # NOTE: Forced flushing ensures that stdout and stderr - # stay in nice order. This is a workaround for calls like - # "layman -L |& less". - sys.stdout.flush() - print >> self.error_out, self.maybe_color('red', '* ') + i - self.error_out.flush() - self.has_error =3D True - - def die (self, error): - - if type(error) not in types.StringTypes: - error =3D str(error) - - for i in error.split('\n'): - self.error(self.maybe_color('red', 'Fatal error: ') + i) - self.error(self.maybe_color('red', 'Fatal error(s) - aborting')) - sys.exit(1) - - def debug (self, message, level =3D 4): + def debug (self, message, level =3D DEBUG_LEVEL): ''' This is a generic debugging method. '''