From 8990dad4eb192d342545589c66555faae88e8301 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Thu, 18 Feb 2010 05:12:43 +0100 Subject: Resolve Actions class, allow custom sys.argv for Config class --- bin/layman | 11 ++++------- layman/action.py | 10 +++++----- layman/config.py | 6 ++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bin/layman b/bin/layman index 3080c05..b85f4fa 100755 --- a/bin/layman +++ b/bin/layman @@ -6,10 +6,12 @@ # # Copyright: # (c) 2005 Gunnar Wrobel +# (c) 2009 Sebastian Pipping # Distributed under the terms of the GNU General Public License v2 # # Author(s): # Gunnar Wrobel +# Sebastian Pipping # __version__ = "$Id$" @@ -21,7 +23,7 @@ __version__ = "$Id$" #------------------------------------------------------------------------------- from layman.config import Config -from layman.action import Actions +from layman.action import main #=============================================================================== # @@ -29,9 +31,4 @@ from layman.action import Actions # #------------------------------------------------------------------------------- -def main(): - - Actions(Config()) - -if __name__ == "__main__": - main() +main(Config()) diff --git a/layman/action.py b/layman/action.py index 0fe023c..b8a9c27 100644 --- a/layman/action.py +++ b/layman/action.py @@ -499,11 +499,11 @@ class ListLocal: #=============================================================================== # -# Class Actions +# MAIN # #------------------------------------------------------------------------------- -class Actions: +def main(config): '''Dispatches to the actions the user selected. ''' # Given in order of precedence @@ -516,7 +516,7 @@ class Actions: ('list', List), ('list_local', ListLocal),] - def __init__(self, config): + if True: # A hack to save diff with indentation changes only # Make fetching the overlay list a default action if not 'nofetch' in config.keys(): @@ -539,7 +539,7 @@ class Actions: OUT.die('Failed setting to umask "' + umask + '"!\nError was: ' + str(error)) - for i in self.actions: + for i in actions: OUT.debug('Checking for action', 7) @@ -553,7 +553,7 @@ class Actions: sys.exit(0) else: sys.exit(1) - + #=============================================================================== # # Testing diff --git a/layman/config.py b/layman/config.py index bbafba3..0a48c5d 100644 --- a/layman/config.py +++ b/layman/config.py @@ -47,7 +47,7 @@ layman (-l|-L|-S)""" class Config(object): '''Handles the configuration.''' - def __init__(self): + def __init__(self, args=None): ''' Creates and describes all possible polymeraZe options and creates a debugging object. @@ -62,6 +62,8 @@ class Config(object): >>> 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'] ''' + if args == None: + args = sys.argv self.defaults = {'config' : '/etc/layman/layman.cfg', 'storage' : '/var/lib/layman', @@ -236,7 +238,7 @@ class Config(object): # Parse the command line first since we need to get the config # file option. - self.options = self.parser.parse_args()[0] + self.options = self.parser.parse_args(args)[0] # handle debugging OUT.cli_handle(self.options) -- cgit v1.2.3-1-g7c22