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 ) id 1PorUr-0004U8-I4 for garchives@archives.gentoo.org; Mon, 14 Feb 2011 06:01:17 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E4799E08B8; Mon, 14 Feb 2011 06:00:24 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id A3DC6E08DF for ; Mon, 14 Feb 2011 06:00:24 +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 987CF1B4094 for ; Mon, 14 Feb 2011 06:00:23 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CFD6C8006A for ; Mon, 14 Feb 2011 06:00:22 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <3b6f983f8d764e974c38ae4b4eccbfd63553ff2d.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/config.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 3b6f983f8d764e974c38ae4b4eccbfd63553ff2d Date: Mon, 14 Feb 2011 06:00:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 8134942162ceb2d2de1b57818da568e7 commit: 3b6f983f8d764e974c38ae4b4eccbfd63553ff2d Author: Brian Dolbec gmail com> AuthorDate: Wed Jul 7 00:17:34 2010 +0000 Commit: Brian Dolbec gmail com> CommitDate: Fri Feb 11 10:46:03 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D3b6f983f add new __init__ input parameters, output (replaces OUT import), stdout, = stdin, stderr. These are then added to the config dictionary for all oth= er modules to use. This creates a single point to assign them and makes = it possible to re-assign them from the defaults in the case of API consum= ers. --- layman/config.py | 50 ++++++++++++++++++++++++++++++++----------------= -- 1 files changed, 32 insertions(+), 18 deletions(-) diff --git a/layman/config.py b/layman/config.py index 750364a..5b84c17 100644 --- a/layman/config.py +++ b/layman/config.py @@ -46,7 +46,7 @@ _USAGE =3D """ class Config(object): '''Handles the configuration.''' =20 - def __init__(self, args=3DNone): + def __init__(self, args=3DNone, output=3DNone, stdout=3DNone, stdin=3D= None, stderr=3DNone): ''' Creates and describes all possible polymeraZe options and create= s a debugging object. @@ -64,6 +64,11 @@ class Config(object): if args =3D=3D None: args =3D sys.argv =20 + self.stdout =3D stdout if stdout else sys.stdout + self.stderr =3D stderr if stderr else sys.stderr + self.stdin =3D stdin if stdin else sys.stdin + self.output =3D output if output else OUT + self.defaults =3D {'config' : '/etc/layman/layman.cfg', 'storage' : '/var/lib/layman', 'cache' : '%(storage)s/cache', @@ -233,7 +238,7 @@ class Config(object): #---------------------------------------------------------------= -- # Debug Options =20 - OUT.cli_opts(self.parser) + self.output.cli_opts(self.parser) =20 # Parse the command line first since we need to get the config # file option. @@ -246,16 +251,25 @@ class Config(object): self.parser.error("Unhandled parameters: %s" % ', '.join(('"= %s"' % e) for e in remain_args[1:])) =20 # handle debugging - OUT.cli_handle(self.options) + self.output.cli_handle(self.options) + + # add output to the options + self.options.__dict__['output'] =3D self.output + + # add the std in/out/err to the options + self.options.__dict__['stdout'] =3D self.stdout + self.options.__dict__['stdin'] =3D self.stdin + self.options.__dict__['stderr'] =3D self.stderr + =20 =20 if self.options.__dict__['nocolor']: - OUT.color_off() + self.output.color_off() =20 # Fetch only an alternate config setting from the options if not self.options.__dict__['config'] is None: self.defaults['config'] =3D self.options.__dict__['config'] =20 - OUT.debug('Got config file at ' + self.defaults['config'], 8= ) + self.output.debug('Got config file at ' + self.defaults['con= fig'], 8) =20 # Now parse the config file self.config =3D ConfigParser.ConfigParser(self.defaults) @@ -263,14 +277,14 @@ class Config(object): =20 # handle quietness if self['quiet']: - OUT.set_info_level(1) - OUT.set_warn_level(1) + self.output.set_info_level(1) + self.output.set_warn_level(1) self.defaults['quietness'] =3D 0 elif 'quietness' in self.keys(): - OUT.set_info_level(int(self['quietness'])) - OUT.set_warn_level(int(self['quietness'])) + self.output.set_info_level(int(self['quietness'])) + self.output.set_warn_level(int(self['quietness'])) =20 - OUT.debug('Reading config file at ' + self.defaults['config'], 8= ) + self.output.debug('Reading config file at ' + self.defaults['con= fig'], 8) =20 self.config.read(self.defaults['config']) =20 @@ -286,13 +300,13 @@ class Config(object): if overlays: return overlays =20 - OUT.debug('Retrieving option', 8) + self.output.debug('Retrieving option', 8) =20 if (key in self.options.__dict__.keys() and not self.options.__dict__[key] is None): return self.options.__dict__[key] =20 - OUT.debug('Retrieving option', 8) + self.output.debug('Retrieving option', 8) =20 if self.config.has_option('MAIN', key): if key =3D=3D 'nocheck': @@ -302,34 +316,34 @@ class Config(object): return False return self.config.get('MAIN', key) =20 - OUT.debug('Retrieving option', 8) + self.output.debug('Retrieving option', 8) =20 if key in self.defaults.keys(): return self.defaults[key] =20 - OUT.debug('Retrieving option', 8) + self.output.debug('Retrieving option', 8) =20 return None =20 def keys(self): '''Special handler for the configuration keys.''' =20 - OUT.debug('Retrieving keys', 8) + self.output.debug('Retrieving keys', 8) =20 keys =3D [i for i in self.options.__dict__.keys() if not self.options.__dict__[i] is None] =20 - OUT.debug('Retrieving keys', 8) + self.output.debug('Retrieving keys', 8) =20 keys +=3D [name for name, _ in self.config.items('MAIN') if not name in keys] =20 - OUT.debug('Retrieving keys', 8) + self.output.debug('Retrieving keys', 8) =20 keys +=3D [i for i in self.defaults.keys() if not i in keys] =20 - OUT.debug('Retrieving keys', 8) + self.output.debug('Retrieving keys', 8) =20 return keys =20