summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordol-sen <brian.dolbec@gmail.com>2011-07-22 23:40:41 -0700
committerdol-sen <brian.dolbec@gmail.com>2011-07-22 23:40:41 -0700
commit76631892e26c1f08d3a00232e58f454acda09fef (patch)
tree5f0d8046e1072fa97bf2dc6f1cef23c611bec1ff
parentadd overlay_defs option to layman.cfg (diff)
downloadlayman-76631892e26c1f08d3a00232e58f454acda09fef.tar.gz
layman-76631892e26c1f08d3a00232e58f454acda09fef.tar.bz2
layman-76631892e26c1f08d3a00232e58f454acda09fef.zip
fix existing tests. add tests for new classes. rename T/F_options to lowwercase due to ConfigParser making it lowercase, creating a dupe.
-rw-r--r--layman/argsparser.py33
-rw-r--r--layman/config.py44
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=None, stdout=None, stdin=None, stderr=None):
'''
Creates and describes all possible polymeraZe options and creates
- a debugging object.
+ a Message object.
>>> import os.path
>>> here = 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 = 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', 'storage',
- 'svn_command', 'tar_command', 'umask', 'width']
+ ['bzr_addopts', 'bzr_command', 'bzr_postsync', 'bzr_syncopts', 'cache', 'config', 'configdir', 'cvs_addopts', 'cvs_command', 'cvs_postsync', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', 'darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_postsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsync', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'mercurial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'overlay_defs', 'overlays', 'proxy', 'quietness', 'rsync_command', 'rsync_postsync', 'rsync_syncopts', 'storage', 'svn_addopts', 'svn_command', 'svn_postsync', 'svn_syncopts', 't/f_options', 'tar_command', 'tar_postsync', 'umask', 'width']
'''
BareConfig.__init__(self, stdout=stdout, stderr=stderr, stdin=stdin)
@@ -159,6 +158,12 @@ class ArgsParser(BareConfig):
help = 'Path to the config file [default: ' \
+ self.defaults['config'] + '].')
+ group.add_option('-O',
+ '--overlay_defs',
+ action = 'store',
+ help = 'Path to aditional overlay.xml files [default: '\
+ + self.defaults['overlay_defs'] + '].')
+
group.add_option('-o',
'--overlays',
action = 'append',
@@ -235,7 +240,7 @@ class ArgsParser(BareConfig):
(self.options, remain_args) = 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:]))
# handle debugging
@@ -244,14 +249,16 @@ class ArgsParser(BareConfig):
if self.options.__dict__['nocolor']:
self.output.set_colorize(OFF)
- # Fetch only an alternate config setting from the options
- #if not self.options.__dict__['config'] is None:
- # self._defaults['config'] = self.options.__dict__['config']
-
- #self.output.debug('Got config file at ' + self.defaults['config'], 8)
+ # Set only alternate config settings from the options
+ if self.options.__dict__['config'] is not None:
+ self.defaults['config'] = self.options.__dict__['config']
+ self.output.debug('Got config file at ' + self.defaults['config'], 8)
+ if self.options.__dict__['overlay_defs'] is not None:
+ self.defaults['overlay_defs'] = self.options.__dict__['overlay_defs']
+ self.output.debug('Got overlay_defs location at ' + self.defaults['overlay_defs'], 8)
# Now parse the config file
- self.read_config(self._defaults)
+ self.read_config(self.defaults)
# handle quietness
if self.options.__dict__['quiet']:
@@ -284,7 +291,7 @@ class ArgsParser(BareConfig):
self.output.debug('Retrieving option', 8)
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)
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):
>>> a = 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', 'storage',
- 'svn_command', 'tar_command', 'umask', 'width', ...]
+ ['bzr_addopts', 'bzr_command', 'bzr_postsync', 'bzr_syncopts', 'cache', 'config', 'configdir', 'cvs_addopts', 'cvs_command', 'cvs_postsync', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', 'darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_postsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsync', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'mercurial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'nocolor', 'output', 'overlay_defs', 'overlays', 'proxy', 'quiet', 'quietness', 'rsync_command', 'rsync_postsync', 'rsync_syncopts', 'stderr', 'stdin', 'stdout', 'storage', 'svn_addopts', 'svn_command', 'svn_postsync', 'svn_syncopts', 't/f_options', 'tar_command', 'tar_postsync', 'umask', 'verbose', 'width']
+ >>> a.get_option('nocheck')
+ True
'''
- self._defaults = {'config' : '/etc/layman/layman.cfg',
+
+ self._defaults = {
+ '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 = {"overlays": ["http://www.gentoo-overlays.org/repositories.xml"]}
+ >>> new_defaults = {"configdir": "/etc/test-dir"}
+ >>> a = OptionConfig(options=options, defaults=new_defaults)
+ >>> 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_postsync', 'cvs_syncopts', 'darcs_addopts', 'darcs_command', 'darcs_postsync', 'darcs_syncopts', 'g-common_command', 'g-common_generateopts', 'g-common_postsync', 'g-common_syncopts', 'git_addopts', 'git_command', 'git_postsync', 'git_syncopts', 'local_list', 'make_conf', 'mercurial_addopts', 'mercurial_command', 'mercurial_postsync', 'mercurial_syncopts', 'nocheck', 'nocolor', 'output', 'overlay_defs', 'overlays', 'proxy', 'quiet', 'quietness', 'rsync_command', 'rsync_postsync', 'rsync_syncopts', 'stderr', 'stdin', 'stdout', 'storage', 'svn_addopts', 'svn_command', 'svn_postsync', 'svn_syncopts', 't/f_options', 'tar_command', 'tar_postsync', 'umask', 'verbose', 'width']
"""
BareConfig.__init__(self)
@@ -268,3 +282,13 @@ class OptionConfig(BareConfig):
if new_defaults is not None:
self._defaults.update(new_defaults)
return
+
+#===============================================================================
+#
+# Testing
+#
+#-------------------------------------------------------------------------------
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod(sys.modules[__name__])