Skip to content

Commit

Permalink
feat(2.18): adapt to new directory layout (#8)
Browse files Browse the repository at this point in the history
- adapt copy to new directory layout 
- have an explicit error when installing from versions older than 2.18
- remove browser opening, antares itself now does it
- increase again waiting time to 2 min, for slow machines

Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl authored Nov 25, 2024
1 parent 118c9c5 commit e652a74
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 25 deletions.
34 changes: 10 additions & 24 deletions src/antares_web_installer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
import textwrap
import time
import webbrowser
from difflib import SequenceMatcher
from pathlib import Path
from shutil import copy2, copytree
Expand All @@ -22,7 +21,7 @@
from antares_web_installer.shortcuts import create_shortcut, get_desktop

# List of files and directories to exclude during installation
COMMON_EXCLUDED_FILES = {"config.prod.yaml", "config.yaml", "examples", "logs", "matrices", "tmp", "*.zip"}
COMMON_EXCLUDED_FILES = {"config.yaml", "archives", "internal_studies", "studies", "logs", "matrices", "tmp", "*.zip"}
POSIX_EXCLUDED_FILES = COMMON_EXCLUDED_FILES | {"AntaresWebWorker"}
WINDOWS_EXCLUDED_FILES = COMMON_EXCLUDED_FILES | {"AntaresWebWorker.exe"}
EXCLUDED_FILES = POSIX_EXCLUDED_FILES if os.name == "posix" else WINDOWS_EXCLUDED_FILES
Expand All @@ -33,7 +32,7 @@
SERVER_ADDRESS = "http://127.0.0.1:8080"
HEALTHCHECK_ADDRESS = f"{SERVER_ADDRESS}/api/health"

MAX_SERVER_START_TIME = 60
MAX_SERVER_START_TIME = 120


class InstallError(Exception):
Expand Down Expand Up @@ -64,7 +63,7 @@ def __post_init__(self):
if self.shortcut:
self.nb_steps += 1
if self.launch:
self.nb_steps += 2
self.nb_steps += 1
self.current_step = 0
self.progress = 0

Expand All @@ -80,14 +79,8 @@ def run(self) -> None:
self.current_step += 1

if self.launch:
try:
self.start_server()
except InstallError as e:
raise e
else:
self.current_step += 1
self.open_browser()
self.current_step += 1
self.start_server()
self.current_step += 1

def update_progress(self, progress: float):
self.progress = (progress / self.nb_steps) + (self.current_step / self.nb_steps) * 100
Expand Down Expand Up @@ -146,6 +139,11 @@ def install_files(self):
# check app version
old_version = self.check_version()
logger.info(f"Old application version : {old_version}.")
version_info = tuple(map(int, old_version.split(".")))
if version_info < (2, 18):
raise InstallError(
f"Trying to update from version {old_version}: updating from version older than 2.18 is not supported, please select a new installation directory."
)
self.update_progress(25)

# update config file
Expand Down Expand Up @@ -308,16 +306,4 @@ def start_server(self):
nb_attempts += 1
else:
raise InstallError("Server didn't start in time, please check server logs.")

def open_browser(self):
"""
Open server URL in default user's browser
"""
logger.debug("In open browser method.")
try:
webbrowser.open(url=SERVER_ADDRESS, new=2)
except webbrowser.Error as e:
raise InstallError(f"Could not open browser at '{SERVER_ADDRESS}': {e}") from e
else:
logger.info("Browser was successfully opened.")
self.update_progress(100)
2 changes: 1 addition & 1 deletion tests/integration/server_mock/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Define the server configuration
HOST = "127.0.0.1"
PORT = 8080
VERSION = "2.14.4"
VERSION = "2.18.0"


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source
1 change: 1 addition & 0 deletions tests/test_app/copy_files/source_files/studies/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
1 change: 1 addition & 0 deletions tests/test_app/copy_files/target_files/studies/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target

0 comments on commit e652a74

Please sign in to comment.