From 9da82dba13151e3f7cb975c696a125adfe87434f Mon Sep 17 00:00:00 2001 From: Henning Schild Date: Fri, 5 Jan 2018 16:00:27 +0100 Subject: [PATCH] config: call Repo.factory only in one place This patch simplifies the code a bit and does not change any semantics. Signed-off-by: Henning Schild --- kas/config.py | 9 +++++---- kas/repos.py | 16 ++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/kas/config.py b/kas/config.py index 5e8cdd6..710879d 100644 --- a/kas/config.py +++ b/kas/config.py @@ -189,6 +189,7 @@ class Config: name = repo_config_dict[repo].get('name', repo) refspec = repo_config_dict[repo].get('refspec', None) path = repo_config_dict[repo].get('path', None) + dis_ops = False if url is None: # No git operation on repository @@ -199,12 +200,12 @@ class Config: name) url = path - rep = Repo.factory(url=url, path=path, layers=layers) - rep.disable_operations() + dis_ops = True else: path = path or os.path.join(self.kas_work_dir, name) - rep = Repo.factory(url=url, path=path, refspec=refspec, - layers=layers) + + rep = Repo.factory(url=url, path=path, refspec=refspec, + layers=layers, disable_operations=dis_ops) repo_dict[repo] = rep return repo_dict diff --git a/kas/repos.py b/kas/repos.py index 02910f7..ea6b263 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -38,19 +38,14 @@ class Repo: Represents a repository in the kas configuration. """ - def __init__(self, url, path, refspec, layers): + def __init__(self, url, path, refspec, layers, disable_operations): + # pylint: disable=too-many-arguments self.url = url self.path = path self.refspec = refspec self._layers = layers self.name = os.path.basename(self.path) - self.operations_disabled = False - - def disable_operations(self): - """ - Disabled all version control operation for this repository. - """ - self.operations_disabled = True + self.operations_disabled = disable_operations def __getattr__(self, item): if item == 'layers': @@ -74,11 +69,12 @@ class Repo: self.path, self._layers) @staticmethod - def factory(url, path, refspec=None, layers=None): + def factory(url, path, refspec, layers, disable_operations): """ Return an instance Repo depending on params. """ - return GitRepo(url, path, refspec, layers) + # pylint: disable=too-many-arguments + return GitRepo(url, path, refspec, layers, disable_operations) @staticmethod def get_root_path(path, environ):