From 6a85296836d27560f20f621a72e798062e89512d Mon Sep 17 00:00:00 2001 From: Henning Schild Date: Fri, 5 Jan 2018 16:00:29 +0100 Subject: [PATCH] repos: move more of the complexity from config to Repo.factory This commit just moved some code around, to a place where it seems to fit better. Signed-off-by: Henning Schild --- kas/config.py | 31 +------------------------------ kas/repos.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/kas/config.py b/kas/config.py index a199532..f9917e6 100644 --- a/kas/config.py +++ b/kas/config.py @@ -177,38 +177,9 @@ class Config: repo_config_dict = self._config.get('repos', {}) repo_dict = {} for repo in repo_config_dict: - repo_config_dict[repo] = repo_config_dict[repo] or {} - layers_dict = repo_config_dict[repo].get('layers', {}) - layers = list(filter(lambda x, laydict=layers_dict: - str(laydict[x]).lower() not in - ['disabled', 'excluded', 'n', 'no', '0', - 'false'], - layers_dict)) - url = repo_config_dict[repo].get('url', None) - name = repo_config_dict[repo].get('name', repo) - typ = repo_config_dict[repo].get('type', 'git') - refspec = repo_config_dict[repo].get('refspec', None) - path = repo_config_dict[repo].get('path', None) - dis_ops = False + repo_dict[repo] = Repo.factory(repo, repo_config_dict[repo], self) - if url is None: - # No git operation on repository - if path is None: - path = Repo.get_root_path(os.path.dirname(self.filename), - self.environ) - logging.info('Using %s as root for repository %s', path, - name) - - url = path - dis_ops = True - else: - path = path or os.path.join(self.kas_work_dir, name) - - rep = Repo.factory(url=url, path=path, typ=typ, - refspec=refspec, layers=layers, - disable_operations=dis_ops) - repo_dict[repo] = rep return repo_dict def get_bitbake_targets(self): diff --git a/kas/repos.py b/kas/repos.py index 052b770..f82fca2 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -69,11 +69,35 @@ class Repo: self.path, self._layers) @staticmethod - def factory(url, path, typ, refspec, layers, disable_operations): + def factory(name, repo_config, config): """ Return an instance Repo depending on params. """ - # pylint: disable=too-many-arguments + layers_dict = repo_config.get('layers', {}) + layers = list(filter(lambda x, laydict=layers_dict: + str(laydict[x]).lower() not in + ['disabled', 'excluded', 'n', 'no', '0', 'false'], + layers_dict)) + url = repo_config.get('url', None) + name = repo_config.get('name', name) + typ = repo_config.get('type', 'git') + refspec = repo_config.get('refspec', None) + path = repo_config.get('path', None) + disable_operations = False + + if url is None: + # No git operation on repository + if path is None: + path = Repo.get_root_path(os.path.dirname(config.filename), + config.environ) + logging.info('Using %s as root for repository %s', path, + name) + + url = path + disable_operations = True + else: + path = path or os.path.join(config.kas_work_dir, name) + if typ == 'git': return GitRepo(url, path, refspec, layers, disable_operations) raise NotImplementedError('Repo typ "%s" not supported.' % typ)