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 1QkVxf-0004YT-NW for garchives@archives.gentoo.org; Sat, 23 Jul 2011 06:45:19 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C88CA21C0B7; Sat, 23 Jul 2011 06:45:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 8A18421C090 for ; Sat, 23 Jul 2011 06:45:07 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9AE4F1B4024 for ; Sat, 23 Jul 2011 06:45:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 8A8098004A for ; Sat, 23 Jul 2011 06:45:05 +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: <76631892e26c1f08d3a00232e58f454acda09fef.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/argsparser.py layman/config.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 76631892e26c1f08d3a00232e58f454acda09fef Date: Sat, 23 Jul 2011 06:45:05 +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: f80e3a849fe4716874dca738ee6b809f commit: 76631892e26c1f08d3a00232e58f454acda09fef Author: dol-sen gmail com> AuthorDate: Sat Jul 23 06:40:41 2011 +0000 Commit: Brian Dolbec gmail com> CommitDate: Sat Jul 23 06:40:41 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D76631892 fix existing tests. add tests for new classes. rename T/F_options to loww= ercase due to ConfigParser making it lowercase, creating a dupe. --- layman/argsparser.py | 33 ++++++++++++++++++++------------- layman/config.py | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/layman/argsparser.py b/layman/argsparser.py index aa31149..dee5d43 100644 --- a/layman/argsparser.py +++ b/layman/argsparser.py @@ -51,20 +51,19 @@ class ArgsParser(BareConfig): def __init__(self, args=3DNone, stdout=3DNone, stdin=3DNone, stderr=3D= None): ''' Creates and describes all possible polymeraZe options and create= s - a debugging object. + a Message object. =20 >>> import os.path >>> here =3D os.path.dirname(os.path.realpath(__file__)) >>> sys.argv.append('--config') >>> sys.argv.append(here + '/../etc/layman.cfg') + >>> sys.argv.append('--overlay_defs') + >>> sys.argv.append('') >>> a =3D ArgsParser() >>> a['overlays'] '\\nhttp://www.gentoo.org/proj/en/overlays/repositories.xml' >>> sorted(a.keys()) - ['bzr_command', 'cache', 'config', 'cvs_command', 'darcs_command= ', - 'git_command', 'local_list', 'make_conf', 'mercurial_command', - 'nocheck', 'overlays', 'proxy', 'quietness', 'rsync_command', 's= torage', - 'svn_command', 'tar_command', 'umask', 'width'] + ['bzr_addopts', 'bzr_command', 'bzr_postsync', 'bzr_syncopts', '= cache', 'config', 'configdir', 'cvs_addopts', 'cvs_command', 'cvs_postsyn= c', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', '= darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_p= ostsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsyn= c', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'merc= urial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'o= verlay_defs', 'overlays', 'proxy', 'quietness', 'rsync_command', 'rsync_p= ostsync', 'rsync_syncopts', 'storage', 'svn_addopts', 'svn_command', 'svn= _postsync', 'svn_syncopts', 't/f_options', 'tar_command', 'tar_postsync',= 'umask', 'width'] ''' =20 BareConfig.__init__(self, stdout=3Dstdout, stderr=3Dstderr, stdi= n=3Dstdin) @@ -159,6 +158,12 @@ class ArgsParser(BareConfig): help =3D 'Path to the config file [default: ' \ + self.defaults['config'] + '].') =20 + group.add_option('-O', + '--overlay_defs', + action =3D 'store', + help =3D 'Path to aditional overlay.xml files [= default: '\ + + self.defaults['overlay_defs'] + '].') + group.add_option('-o', '--overlays', action =3D 'append', @@ -235,7 +240,7 @@ class ArgsParser(BareConfig): (self.options, remain_args) =3D self.parser.parse_args(args) # remain_args starts with something like "bin/layman" ... if len(remain_args) > 1: - self.parser.error("Unhandled parameters: %s" + self.parser.error("ArgsParser(): Unhandled parameters: %s" % ', '.join(('"%s"' % e) for e in remain_args[1:])) =20 # handle debugging @@ -244,14 +249,16 @@ class ArgsParser(BareConfig): if self.options.__dict__['nocolor']: self.output.set_colorize(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'= ] - - #self.output.debug('Got config file at ' + self.defaults['co= nfig'], 8) + # Set only alternate config settings from the options + if self.options.__dict__['config'] is not None: + self.defaults['config'] =3D self.options.__dict__['config'] + self.output.debug('Got config file at ' + self.defaults['con= fig'], 8) + if self.options.__dict__['overlay_defs'] is not None: + self.defaults['overlay_defs'] =3D self.options.__dict__['ove= rlay_defs'] + self.output.debug('Got overlay_defs location at ' + self.def= aults['overlay_defs'], 8) =20 # Now parse the config file - self.read_config(self._defaults) + self.read_config(self.defaults) =20 # handle quietness if self.options.__dict__['quiet']: @@ -284,7 +291,7 @@ class ArgsParser(BareConfig): self.output.debug('Retrieving option', 8) =20 if self.config.has_option('MAIN', key): - if key in self._defaults['T/F_options']: + if key in self._defaults['t/f_options']: return self.t_f_check(self.config.get('MAIN', key)) return self.config.get('MAIN', key) =20 diff --git a/layman/config.py b/layman/config.py index 609b81e..644a63a 100644 --- a/layman/config.py +++ b/layman/config.py @@ -68,14 +68,16 @@ class BareConfig(object): =20 >>> a =3D BareConfig() >>> a['overlays'] - '\\nhttp://www.gentoo.org/proj/en/overlays/repositories.xml' + 'http://www.gentoo.org/proj/en/overlays/repositories.xml' >>> sorted(a.keys()) - ['bzr_command', 'cache', 'config', 'cvs_command', 'darcs_command= ', - 'git_command', 'local_list', 'make_conf', 'mercurial_command', - 'nocheck', 'overlays', 'proxy', 'quietness', 'rsync_command', 's= torage', - 'svn_command', 'tar_command', 'umask', 'width', ...] + ['bzr_addopts', 'bzr_command', 'bzr_postsync', 'bzr_syncopts', '= cache', 'config', 'configdir', 'cvs_addopts', 'cvs_command', 'cvs_postsyn= c', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', '= darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_p= ostsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsyn= c', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'merc= urial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'n= ocolor', 'output', 'overlay_defs', 'overlays', 'proxy', 'quiet', 'quietne= ss', 'rsync_command', 'rsync_postsync', 'rsync_syncopts', 'stderr', 'stdi= n', 'stdout', 'storage', 'svn_addopts', 'svn_command', 'svn_postsync', 's= vn_syncopts', 't/f_options', 'tar_command', 'tar_postsync', 'umask', 'ver= bose', 'width'] + >>> a.get_option('nocheck') + True ''' - self._defaults =3D {'config' : '/etc/layman/layman.cfg', + + self._defaults =3D { + 'configdir': '/etc/layman', + 'config' : '%(configdir)s/layman.cfg', 'storage' : '/var/lib/layman', 'cache' : '%(storage)s/cache', 'local_list': '%(storage)s/overlays.xml', @@ -85,7 +87,7 @@ class BareConfig(object): 'umask' : '0022', 'overlays' : 'http://www.gentoo.org/proj/en/overlays/repositories= .xml', - 'overlay_defs': '/etc/layman/overlays', + 'overlay_defs': '%(configdir)s/overlays', 'bzr_command': '/usr/bin/bzr', 'cvs_command': '/usr/bin/cvs', 'darcs_command': '/usr/bin/darcs', @@ -95,7 +97,7 @@ class BareConfig(object): 'rsync_command': '/usr/bin/rsync', 'svn_command': '/usr/bin/svn', 'tar_command': '/bin/tar', - 'T/F_options': ['nocheck'], + 't/f_options': ['nocheck'], 'bzr_addopts' : '', 'bzr_syncopts' : '', 'cvs_addopts' : '', @@ -207,10 +209,12 @@ class BareConfig(object): and not self._options[key] is None): return self._options[key] if self.config and self.config.has_option('MAIN', key): - if key in self._defaults['T/F_options']: - return t_f_check(self.config.get('MAIN', key)) + if key in self._defaults['t/f_options']: + return self.t_f_check(self.config.get('MAIN', key)) return self.config.get('MAIN', key) self._options['output'].debug('Retrieving BareConfig default', 8= ) + if key in self._defaults['t/f_options']: + return self.t_f_check(self._defaults[key]) if key in self._defaults: if '%(storage)s' in self._defaults[key]: return self._defaults[key] %{'storage': self._defaults['= storage']} @@ -235,6 +239,16 @@ class OptionConfig(BareConfig): """ @param options: dictionary of {'option': value, ...} @rtype OptionConfig class instance. + + >>> options =3D {"overlays": ["http://www.gentoo-overlays.org/re= positories.xml"]} + >>> new_defaults =3D {"configdir": "/etc/test-dir"} + >>> a =3D OptionConfig(options=3Doptions, defaults=3Dnew_default= s) + >>> a['overlays'] + 'http://www.gentoo-overlays.org/repositories.xml' + >>> a["configdir"] + '/etc/test-dir' + >>> sorted(a.keys()) + ['bzr_addopts', 'bzr_command', 'bzr_postsync', 'bzr_syncopts', '= cache', 'config', 'configdir', 'cvs_addopts', 'cvs_command', 'cvs_postsyn= c', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', '= darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_p= ostsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsyn= c', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'merc= urial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'n= ocolor', 'output', 'overlay_defs', 'overlays', 'proxy', 'quiet', 'quietne= ss', 'rsync_command', 'rsync_postsync', 'rsync_syncopts', 'stderr', 'stdi= n', 'stdout', 'storage', 'svn_addopts', 'svn_command', 'svn_postsync', 's= vn_syncopts', 't/f_options', 'tar_command', 'tar_postsync', 'umask', 'ver= bose', 'width'] """ BareConfig.__init__(self) =20 @@ -268,3 +282,13 @@ class OptionConfig(BareConfig): if new_defaults is not None: self._defaults.update(new_defaults) return + +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +# +# Testing +# +#-----------------------------------------------------------------------= -------- + +if __name__ =3D=3D '__main__': + import doctest + doctest.testmod(sys.modules[__name__])