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 1QF2TQ-0003Ve-5k for garchives@archives.gentoo.org; Wed, 27 Apr 2011 11:00:00 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 676831C057; Wed, 27 Apr 2011 10:58:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2806C1C057 for ; Wed, 27 Apr 2011 10:58:42 +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 B49111B408A for ; Wed, 27 Apr 2011 10:58:42 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 02B8B80510 for ; Wed, 27 Apr 2011 10:58:42 +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: 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: fcadf2247b0982bc0449e65116bd7fd9a76bd789 Date: Wed, 27 Apr 2011 10:58:42 +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: b07777d07aa80d5f84dc49bc35aa3838 commit: fcadf2247b0982bc0449e65116bd7fd9a76bd789 Author: Brian Dolbec gmail com> AuthorDate: Thu Feb 24 06:14:18 2011 +0000 Commit: Brian Dolbec gmail com> CommitDate: Sun Mar 27 02:39:13 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3Dfcadf224 add a new OptionConfig subclass. improve some debug messages. --- layman/config.py | 43 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 39 insertions(+), 4 deletions(-) diff --git a/layman/config.py b/layman/config.py index 58e222a..cda6fce 100644 --- a/layman/config.py +++ b/layman/config.py @@ -123,12 +123,15 @@ class BareConfig(object): def keys(self): '''Special handler for the configuration keys. ''' - self._options['output'].debug('Retrieving BareConfig options', 8= ) + self._options['output'].debug( + 'Retrieving %s options' % self.__class__.__name__, 8) keys =3D [i for i in self._options] - self._options['output'].debug('Retrieving BareConfig defaults', = 8) + self._options['output'].debug( + 'Retrieving %s defaults' % self.__class__.__name__, 8) keys +=3D [i for i in self._defaults if not i in keys] - self._options['output'].debug('Retrieving BareConfig done...', 8= ) + self._options['output'].debug( + 'Retrieving %s done...' % self.__class__.__name__, 8) return keys =20 =20 @@ -166,7 +169,7 @@ class BareConfig(object): =20 def _get_(self, key): self._options['output'].debug( - 'Retrieving BareConfig option: %s' % key, 8) + 'Retrieving %s option: %s' % (self.__class__.__name__, key),= 8) if key =3D=3D 'overlays': overlays =3D '' if (key in self._options @@ -197,3 +200,35 @@ class BareConfig(object): """ return option.lower() in ['yes', 'true', 'y', 't'] =20 + +class OptionConfig(BareConfig): + """This subclasses BareCongig adding functions to make overriding + defaults and/or setting up options much easier via a dictionary + """ + + def __init__(self, options=3DNone): + """ + @param options: dictionary of {'option': value, ...} + @rtype OptionConfig class instance. + """ + BareConfig.__init__(self) + + self.update(options) + + return self + + def update(self, options): + """update the options with new values passed in via options + + @param options + """ + if options is not None: + keys =3D sorted(options) + if 'quiet' in keys: + self.set_option('quiet', options['quiet']) + options.pop('quiet') + if 'quietness' in keys and not options['quiet']: + self._set_quietness(options['quietness']) + options.pop('quietness') + self._options.update(options) + return