Python: basic, package install, error handler for begining
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
1
repo_cloner/__init__.py
Normal file
1
repo_cloner/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
0
repo_cloner/lib/__init__.py
Normal file
0
repo_cloner/lib/__init__.py
Normal file
15
repo_cloner/lib/dir_not_found_error.py
Normal file
15
repo_cloner/lib/dir_not_found_error.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from pathlib import PosixPath
|
||||
|
||||
|
||||
class DirNotFoundError(OSError):
|
||||
|
||||
def __str__(self):
|
||||
if len(self.args) >= 1:
|
||||
path: str = ""
|
||||
if isinstance(self.args[0], PosixPath):
|
||||
path = str(PosixPath(self.args[0]))
|
||||
else:
|
||||
path = str(self.args[0])
|
||||
return f"Directory does not exist / is not a dir: {path}"
|
||||
else:
|
||||
return super.__str__(self)
|
||||
44
repo_cloner/lib/repo_dir_structure.py
Normal file
44
repo_cloner/lib/repo_dir_structure.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os.path
|
||||
from repo_cloner.lib.dir_not_found_error import DirNotFoundError
|
||||
|
||||
|
||||
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
|
||||
def exists(self) -> bool:
|
||||
if not os.path.isdir(self._base_dir):
|
||||
raise DirNotFoundError(self._base_dir)
|
||||
if not os.path.isdir(self._conf_dir):
|
||||
raise DirNotFoundError(self._conf_dir)
|
||||
if not os.path.isdir(self._cache_dir):
|
||||
raise DirNotFoundError(self._cache_dir)
|
||||
if not os.path.isdir(self._repos_dir):
|
||||
raise DirNotFoundError(self._repos_dir)
|
||||
|
||||
return True
|
||||
|
||||
@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
|
||||
21
repo_cloner/process_repository_dir.py
Executable file
21
repo_cloner/process_repository_dir.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
|
||||
from repo_cloner.lib.repo_dir_structure import RepoDirStructure
|
||||
|
||||
|
||||
def main():
|
||||
# parse input arguments
|
||||
parser = argparse.ArgumentParser(description = "repo-cloner entering script")
|
||||
parser.add_argument('--base-dir', help = 'path to directory containing whole cloner structure', required = True,
|
||||
default = None, type = str)
|
||||
args = parser.parse_args()
|
||||
|
||||
dirs = RepoDirStructure(args.base_dir)
|
||||
print(dirs)
|
||||
dirs.exists
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user