Skip to content

Commit

Permalink
little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Dec 19, 2024
1 parent 4738935 commit 2adce82
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/antares_web_installer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from antares_web_installer.shortcuts import create_shortcut, get_desktop

# List of files and directories to exclude during installation
EXCLUDED_ROOT_RESOURCES = {
COMMON_EXCLUDED_RESOURCES = {
Path("config.yaml"),
Path("archives"),
Path("internal_studies"),
Expand All @@ -32,6 +32,11 @@
Path("local_workspace"),
}

POSIX_EXCLUDED_FILES = COMMON_EXCLUDED_RESOURCES | {"AntaresWebInstallerCLI"}
WINDOWS_EXCLUDED_FILES = COMMON_EXCLUDED_RESOURCES | {"AntaresWebInstaller.exe"}
EXCLUDED_ROOT_RESOURCES = POSIX_EXCLUDED_FILES if os.name == "posix" else WINDOWS_EXCLUDED_FILES


SERVER_NAMES = {"posix": "AntaresWebServer", "nt": "AntaresWebServer.exe"}
SHORTCUT_NAMES = {"posix": "AntaresWebServer.desktop", "nt": "AntaresWebServer.lnk"}

Expand Down Expand Up @@ -197,20 +202,19 @@ def copy_files(self):
initial_value = self.progress

for index, elt_path in enumerate(dirs_to_copy):
if not elt_path.name.lower().startswith("antareswebinstaller"):
logger.info(f"Copying '{elt_path}'")
try:
if elt_path.is_file():
copy2(elt_path, self.target_dir)
else:
# copy new directory
copytree(elt_path, self.target_dir.joinpath(elt_path.name), dirs_exist_ok=True)
# handle permission errors
except PermissionError as e: # pragma: no cover
relpath = elt_path.relative_to(self.source_dir).as_posix()
raise InstallError(f"Error: Cannot write '{relpath}' in {self.target_dir}: {e}")

self.update_progress(initial_value + (index + 1) * 100 / src_dir_content_length)
logger.info(f"Copying '{elt_path}'")
try:
if elt_path.is_file():
copy2(elt_path, self.target_dir)
else:
# copy new directory
copytree(elt_path, self.target_dir.joinpath(elt_path.name), dirs_exist_ok=True)
# handle permission errors
except PermissionError as e: # pragma: no cover
relpath = elt_path.relative_to(self.source_dir).as_posix()
raise InstallError(f"Error: Cannot write '{relpath}' in {self.target_dir}: {e}")

self.update_progress(initial_value + (index + 1) * 100 / src_dir_content_length)
logger.info("File copy completed.")

def check_version(self) -> str:
Expand Down

0 comments on commit 2adce82

Please sign in to comment.