From 52c3d03e2f2f52c8a1dcb482dc56e725e85b112e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Val=C3=AD=C4=8Dek?= Date: Wed, 3 Aug 2022 07:02:49 +0200 Subject: [PATCH] cloner.detector_enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Václav Valíček --- repo_cloner/lib/cloner.py | 5 +++++ tests/lib/test_cloner.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/repo_cloner/lib/cloner.py b/repo_cloner/lib/cloner.py index e28ab2a..d9bc8bf 100644 --- a/repo_cloner/lib/cloner.py +++ b/repo_cloner/lib/cloner.py @@ -15,6 +15,7 @@ class Cloner: _dirs: RepoDirStructure = None _config: ClonerConfig = None _interval_file: str = "last-check-time" + __detector_cfg = "detector.cfg" __submodule_cache: str = None _repo: RepoTool = None _repo_url: str = "" @@ -202,3 +203,7 @@ class Cloner: scan_depth_limit = None # another levels are handled internally as non-recursive clones and discovers by repo-tool return self._repo.clone_recursive(url, self.__submodule_cache, scan_depth = scan_depth_limit) + + @property + def detector_enabled(self) -> bool: + return os.path.exists(os.path.join(self._dirs.conf_dir, self.__detector_cfg)) diff --git a/tests/lib/test_cloner.py b/tests/lib/test_cloner.py index 7691856..b4613d1 100644 --- a/tests/lib/test_cloner.py +++ b/tests/lib/test_cloner.py @@ -61,7 +61,7 @@ class MockDirStruct: def __init__(self, tmp: Path): self.config = MockConfig() self.cache_dir = tmp.joinpath("cache") - self.config_dir = tmp.joinpath("config") + self.conf_dir = tmp.joinpath("config") self.repos_dir = tmp.joinpath("repos") self.raise_cache_exists = False @@ -457,3 +457,12 @@ def test_clone_recursive(tmp_path, path_repo_base, caplog): assert cloner.clone() patch_clone_recursive.assert_called_with( 'https://repo', tmp_path.joinpath('cache', 'submodules').as_posix(), scan_depth = None) + +def test_detector_enabled(cloner_dir_with_config): + ds = MockDirStruct(cloner_dir_with_config) + ds.config.cloner_repo_url = "http://mock" + cl = Cloner(ds) + assert not cl.detector_enabled + Path(cloner_dir_with_config).joinpath("config", "detector.cfg").touch() + assert cl.detector_enabled +