From 2761c8fcf281e25379e1c77b6a592b0da00089ce Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Tue, 18 Oct 2011 19:31:11 +0200 Subject: [PATCH] fix loading of parameters from config files as a corolary, invalid option are no more loaded --- bin/is | 11 +++++------ installsystems/config.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bin/is b/bin/is index c7ca3b5..f233ced 100755 --- a/bin/is +++ b/bin/is @@ -38,7 +38,6 @@ def load_repositories(args): if args.repo_path is not None: repoman.register(RepositoryConfig(istools.smd5sum(args.repo_path)[:8], path=args.repo_path)) - # load repo configs from config for repoconf in RepoConfigFile(args.repo_config).repos: repoman.register(repoconf) @@ -302,9 +301,9 @@ p_main.add_argument("-V", "--version", action="version", help="show installsystems version") # exclusive group on debug/quiet ex_group = p_main.add_mutually_exclusive_group() -ex_group.add_argument("-d", "--debug", action="store_true", +ex_group.add_argument("-d", "--debug", action="store_true", default=None, help="active debug mode") -ex_group.add_argument("-q", "--quiet", action="store_true", +ex_group.add_argument("-q", "--quiet", action="store_true", default=None, help="active quiet mode") # common options p_main.add_argument("-c", "--config", default="installsystems", @@ -317,11 +316,11 @@ p_main.add_argument("-r", "--repo-path", default=None, help="repository path") p_main.add_argument("-C", "--cache", default=None, help="path of the repository cache") -p_main.add_argument("--no-cache", action="store_true", default=False, +p_main.add_argument("--no-cache", action="store_true", default=None, help="not use persistent db caching") -p_main.add_argument("--no-color", action="store_true", default=False, +p_main.add_argument("--no-color", action="store_true", default=None, help="dot not display colored output") -p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=3, +p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=None, help="download timeout (default 3)") # create a subparsers for each command diff --git a/installsystems/config.py b/installsystems/config.py index 3f2a38a..78fd510 100644 --- a/installsystems/config.py +++ b/installsystems/config.py @@ -84,7 +84,21 @@ class MainConfigFile(ConfigFile): if not hasattr(namespace, option): setattr(namespace, option, value) elif getattr(namespace, option) == None: - setattr(namespace, option, value) + # we need to handle boolean differently + if option in ("debug", "quiet", "no_cache", "no_color"): + setattr(namespace, option, value.lower() not in ("false", "no", "0")) + # we need to handle integer differently + elif option in ("timeout"): + try: + n = int(value) + except ValueError: + raise Exception("Invalid %s: Not a number" % option) + setattr(namespace, option, n) + # we can handle string more carefuly + elif option in ("cache", "repo_filter", "repo_config"): + setattr(namespace, option, value) + else: + warn("Invalid option %s in %s, skipped" % (option, self.path)) def _cache_paths(self): ''' -- GitLab