From 214dcdfe1299aaea697773099d664a015caecdf1 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Fri, 1 Jul 2011 11:30:07 +0200 Subject: [PATCH] fix config loading issue caused by argparse append --- bin/is | 25 +++++++++++++++---------- installsystems/config.py | 8 ++++---- installsystems/repository.py | 1 - 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bin/is b/bin/is index 3c51d26..5e95d0c 100755 --- a/bin/is +++ b/bin/is @@ -23,13 +23,19 @@ def load_repositories(args): ''' Load repository on arg line ''' - # load repo configs repos = [] - for r_config in args.repo_config: - repos += RepoConfigFile(r_config).repos - # filtering on repository name if present - if args.repo_filter is not None: - repos = filter(lambda x: x.name == args.repo_filter, repos) + # load repo configs + if args.repo_path is not None: + # from command line + repos = [ RepositoryConfig(None, path=args.repo_path) ] + else: + # from config + repos += RepoConfigFile(args.repo_config).repos + # filtering on repository name if present + if args.repo_filter is not None: + repos = filter(lambda x: x.name == args.repo_filter, repos) + # print selected repositories + debug("Loaded repositories: %s" % [ x.name for x in repos ]) return repos def c_init_image(args): @@ -173,13 +179,12 @@ ex_group.add_argument('-q', "--quiet", action="store_true", # common options p_main.add_argument("-c", "--config", default="installsystems", help="config file path") +p_main.add_argument("-R", "--repo-config", default="repository", + help="repository config file path") p_main.add_argument("-f", "--repo-filter", default=None, help="select repository by name in config files") -p_main.add_argument("-r", "--repo-path", action="append", default=[], +p_main.add_argument("-r", "--repo-path", default=None, help="repository path") -p_main.add_argument("-R", "--repo-config", action="append", - default=["repository"], - help="repository config (can be specified more than one time)") p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=None, help="download timeout") # create a subparsers for each command diff --git a/installsystems/config.py b/installsystems/config.py index 81431e5..4e55e5e 100644 --- a/installsystems/config.py +++ b/installsystems/config.py @@ -64,7 +64,7 @@ class MainConfigFile(ConfigFile): if self.path is None: debug("No main config file to load") return - debug("Loading config file: %s" % self.path) + debug("Loading main config file: %s" % self.path) try: cp = RawConfigParser() cp.read(self.path) @@ -72,7 +72,7 @@ class MainConfigFile(ConfigFile): if cp.has_section(self.prefix): self._config = dict(cp.items(self.prefix)) except Exception as e: - raise Exception("Unable load file %s: %s" % (self.path, e)) + raise Exception("Unable load main config file %s: %s" % (self.path, e)) def merge(self, namespace): ''' @@ -141,7 +141,7 @@ class RepoConfigFile(ConfigFile): if self.path is None: return # loading config file if exists - debug("Loading config file: %s" % self.path) + debug("Loading repository config file: %s" % self.path) try: cp = RawConfigParser() cp.read(self.path) @@ -153,7 +153,7 @@ class RepoConfigFile(ConfigFile): # get all options in repo self._repos.append(RepositoryConfig(rep, **dict(cp.items(rep)))) except Exception as e: - raise Exception("Unable load file %s: %s" % (self.path, e)) + raise Exception("Unable to load repository file %s: %s" % (self.path, e)) @property def repos(self): diff --git a/installsystems/repository.py b/installsystems/repository.py index 0eaf5fb..1322e8f 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -417,7 +417,6 @@ class RepositoryManager(object): if not os.path.exists(filedest): open(filedest, "wb") # get remote last value - print config.lastpath rlast = int(istools.uopen(config.lastpath).read().strip()) # get local last value llast = int(os.stat(filedest).st_mtime) -- GitLab