Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/layman:master commit in: layman/
Date: Wed, 27 Apr 2011 11:00:00
Message-Id: fcadf2247b0982bc0449e65116bd7fd9a76bd789.dol-sen@gentoo
1 commit: fcadf2247b0982bc0449e65116bd7fd9a76bd789
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Thu Feb 24 06:14:18 2011 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Sun Mar 27 02:39:13 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=fcadf224
7
8 add a new OptionConfig subclass.
9 improve some debug messages.
10
11 ---
12 layman/config.py | 43 +++++++++++++++++++++++++++++++++++++++----
13 1 files changed, 39 insertions(+), 4 deletions(-)
14
15 diff --git a/layman/config.py b/layman/config.py
16 index 58e222a..cda6fce 100644
17 --- a/layman/config.py
18 +++ b/layman/config.py
19 @@ -123,12 +123,15 @@ class BareConfig(object):
20 def keys(self):
21 '''Special handler for the configuration keys.
22 '''
23 - self._options['output'].debug('Retrieving BareConfig options', 8)
24 + self._options['output'].debug(
25 + 'Retrieving %s options' % self.__class__.__name__, 8)
26 keys = [i for i in self._options]
27 - self._options['output'].debug('Retrieving BareConfig defaults', 8)
28 + self._options['output'].debug(
29 + 'Retrieving %s defaults' % self.__class__.__name__, 8)
30 keys += [i for i in self._defaults
31 if not i in keys]
32 - self._options['output'].debug('Retrieving BareConfig done...', 8)
33 + self._options['output'].debug(
34 + 'Retrieving %s done...' % self.__class__.__name__, 8)
35 return keys
36
37
38 @@ -166,7 +169,7 @@ class BareConfig(object):
39
40 def _get_(self, key):
41 self._options['output'].debug(
42 - 'Retrieving BareConfig option: %s' % key, 8)
43 + 'Retrieving %s option: %s' % (self.__class__.__name__, key), 8)
44 if key == 'overlays':
45 overlays = ''
46 if (key in self._options
47 @@ -197,3 +200,35 @@ class BareConfig(object):
48 """
49 return option.lower() in ['yes', 'true', 'y', 't']
50
51 +
52 +class OptionConfig(BareConfig):
53 + """This subclasses BareCongig adding functions to make overriding
54 + defaults and/or setting up options much easier via a dictionary
55 + """
56 +
57 + def __init__(self, options=None):
58 + """
59 + @param options: dictionary of {'option': value, ...}
60 + @rtype OptionConfig class instance.
61 + """
62 + BareConfig.__init__(self)
63 +
64 + self.update(options)
65 +
66 + return self
67 +
68 + def update(self, options):
69 + """update the options with new values passed in via options
70 +
71 + @param options
72 + """
73 + if options is not None:
74 + keys = sorted(options)
75 + if 'quiet' in keys:
76 + self.set_option('quiet', options['quiet'])
77 + options.pop('quiet')
78 + if 'quietness' in keys and not options['quiet']:
79 + self._set_quietness(options['quietness'])
80 + options.pop('quietness')
81 + self._options.update(options)
82 + return