2022-05-04 15:02:55 +02:00
|
|
|
import os.path
|
|
|
|
from repo_cloner.lib.dir_not_found_error import DirNotFoundError
|
2022-06-26 01:24:40 +02:00
|
|
|
from repo_cloner.lib.config_file_not_found_error import ConfigFileNotFoundError
|
2022-05-04 15:02:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RepoDirStructure():
|
|
|
|
_base_dir: str = ""
|
|
|
|
_conf_dir: str = ""
|
|
|
|
_cache_dir: str = ""
|
|
|
|
_repos_dir: str = ""
|
|
|
|
|
|
|
|
def __init__(self, base_dir: str):
|
|
|
|
self._base_dir = base_dir
|
|
|
|
self._conf_dir = os.path.join(self._base_dir, "config")
|
|
|
|
self._cache_dir = os.path.join(self._base_dir, "cache")
|
|
|
|
self._repos_dir = os.path.join(self._base_dir, "repos")
|
|
|
|
|
|
|
|
@property
|
2022-06-26 01:24:40 +02:00
|
|
|
def __config_filename(self) -> str:
|
|
|
|
return os.path.join(self.conf_dir, "cloner.cfg")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def base_dir_exists(self) -> bool:
|
2022-05-04 15:02:55 +02:00
|
|
|
if not os.path.isdir(self._base_dir):
|
|
|
|
raise DirNotFoundError(self._base_dir)
|
2022-06-26 00:05:36 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
2022-06-26 01:24:40 +02:00
|
|
|
def conf_dir_exists(self) -> bool:
|
2022-05-04 15:02:55 +02:00
|
|
|
if not os.path.isdir(self._conf_dir):
|
|
|
|
raise DirNotFoundError(self._conf_dir)
|
2022-06-26 00:05:36 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
2022-06-26 01:24:40 +02:00
|
|
|
def cache_dir_exists(self) -> bool:
|
2022-05-04 15:02:55 +02:00
|
|
|
if not os.path.isdir(self._cache_dir):
|
|
|
|
raise DirNotFoundError(self._cache_dir)
|
2022-06-26 00:05:36 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
2022-06-26 01:24:40 +02:00
|
|
|
def repos_dir_exists(self) -> bool:
|
2022-05-04 15:02:55 +02:00
|
|
|
if not os.path.isdir(self._repos_dir):
|
|
|
|
raise DirNotFoundError(self._repos_dir)
|
|
|
|
return True
|
|
|
|
|
2022-06-26 00:05:36 +02:00
|
|
|
@property
|
|
|
|
def dirs_exist(self) -> bool:
|
|
|
|
return all(
|
|
|
|
[
|
|
|
|
self.base_dir_exists,
|
|
|
|
self.conf_dir_exists,
|
|
|
|
self.cache_dir_exists,
|
|
|
|
self.repos_dir_exists,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-05-04 15:02:55 +02:00
|
|
|
@property
|
|
|
|
def base_dir(self) -> str:
|
|
|
|
return self._base_dir
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cache_dir(self) -> str:
|
|
|
|
return self._cache_dir
|
|
|
|
|
|
|
|
@property
|
|
|
|
def conf_dir(self) -> str:
|
|
|
|
return self._conf_dir
|
|
|
|
|
|
|
|
@property
|
|
|
|
def repos_dir(self) -> str:
|
|
|
|
return self._repos_dir
|
2022-06-26 01:24:40 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_config(self) -> bool:
|
|
|
|
if not os.path.exists(self.__config_filename):
|
|
|
|
raise ConfigFileNotFoundError(self.__config_filename)
|
|
|
|
return True
|