cloner.detector_enabled

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-08-03 07:02:49 +02:00
parent ff1e90982a
commit 52c3d03e2f
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
2 changed files with 15 additions and 1 deletions

View File

@ -15,6 +15,7 @@ class Cloner:
_dirs: RepoDirStructure = None _dirs: RepoDirStructure = None
_config: ClonerConfig = None _config: ClonerConfig = None
_interval_file: str = "last-check-time" _interval_file: str = "last-check-time"
__detector_cfg = "detector.cfg"
__submodule_cache: str = None __submodule_cache: str = None
_repo: RepoTool = None _repo: RepoTool = None
_repo_url: str = "" _repo_url: str = ""
@ -202,3 +203,7 @@ class Cloner:
scan_depth_limit = None scan_depth_limit = None
# another levels are handled internally as non-recursive clones and discovers by repo-tool # 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) 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))

View File

@ -61,7 +61,7 @@ class MockDirStruct:
def __init__(self, tmp: Path): def __init__(self, tmp: Path):
self.config = MockConfig() self.config = MockConfig()
self.cache_dir = tmp.joinpath("cache") 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.repos_dir = tmp.joinpath("repos")
self.raise_cache_exists = False self.raise_cache_exists = False
@ -457,3 +457,12 @@ def test_clone_recursive(tmp_path, path_repo_base, caplog):
assert cloner.clone() assert cloner.clone()
patch_clone_recursive.assert_called_with( patch_clone_recursive.assert_called_with(
'https://repo', tmp_path.joinpath('cache', 'submodules').as_posix(), scan_depth = None) '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