Skip to content

Commit

Permalink
feat: scripts and directory for tests created,
Browse files Browse the repository at this point in the history
  • Loading branch information
maugde committed May 28, 2024
1 parent 520067c commit fd66c05
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 57 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ coverage.xml
cover/

# test data
tests/samples/results/posix/
tests/samples/results/nt/
tests/samples/results/not_installed/*

# Translations
*.mo
Expand Down
8 changes: 8 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ where `<TARGET_DIR>` is the directory where you want to install the Antares Web

Note that you can specify an existing directory, in which case the installer will update the existing installation.

You optionally can decide whether to create shortcuts on desktop during installation with '-s' and launch server at the
end of the installation with '-l'.

Get all options with `--help` :
```shell
python ..\tests\results\nt\AntaresWeb\AntaresWebServer.py --help
```

## Graphical version (GUI)

Double-click on the `AntaresWebInstallerGUI.exe` file and follow the instructions.
1 change: 0 additions & 1 deletion src/antares_web_installer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
DEBUG = True
3 changes: 1 addition & 2 deletions src/antares_web_installer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Main entrypoint for the CLI application.
"""
import sys

from cli import install_cli
from antares_web_installer.cli import install_cli


def main():
Expand Down
29 changes: 7 additions & 22 deletions src/antares_web_installer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pathlib import Path
from pyshortcuts import make_shortcut

from config import update_config
from antares_web_installer.config import update_config

# List of files and directories to exclude during installation
COMMON_EXCLUDED_FILES = {"config.prod.yaml", "config.yaml", "examples", "logs", "matrices", "tmp"}
Expand All @@ -24,7 +24,6 @@ class InstallError(Exception):
"""
Exception that handles installation error
"""

pass


Expand All @@ -34,8 +33,6 @@ class App:
target_dir: Path
app_name: str = "AntaresWebInstaller"
os_name: str = os.name
window_width: int = 640
window_height: int = 480
shortcut: bool = False
launch: bool = False

Expand Down Expand Up @@ -85,10 +82,6 @@ def install_files(self):
# copy all files from package
copytree(self.source_dir, self.target_dir)

# if previous steps were successfully completed, change OLD_ANTARES_VERSION environment variable
# debug data
os.environ['ANTARES_VERSION'] = "2.15"

def copy_files(self):
"""
Copy all files from self.src_dir to self.target_dir
Expand Down Expand Up @@ -124,9 +117,9 @@ def check_version(self) -> str:
"""
Execute command to get the current version of the server.
"""
script_path = self.target_dir.joinpath("AntaresWeb/AntaresWebServer.py")
script_path = self.target_dir.joinpath("AntaresWeb/AntaresWebServer.py") # FIXME
if script_path.exists():
args = [sys.executable, str(script_path), "--version"]
args = ["python", str(script_path), "--version"] # FIXME
else:
exe_path = self.target_dir.joinpath("AntaresWeb/AntaresWebServer.exe")
# check user's os
Expand All @@ -148,26 +141,18 @@ def create_icons(self):
"""
Create a local server icon and a browser icon on desktop and
"""
# get Desktop path whether it is a UNIX or Windows os
# if self.os_name == "nt":
# print("Desktop path of windows")
# desktop_path = Path(f"{os.environ['USERPROFILE']}\Desktop")
# else:
# print("Desktop path of ubuntu")
# desktop_path = Path(f"/home/{os.getlogin()}/")

# using pyshortcuts
print("Create shortcuts ...")

# test if it already exists
make_shortcut(script=str(f"{self.target_dir.joinpath('AntaresWeb/AntaresWebServer.py')} --version"),
make_shortcut(script=str(f"{self.target_dir.joinpath('AntaresWeb/AntaresWebServer.py')} run"),
name='Antares Web Server',
icon='../../docs/assets/antares-web-installer-icon.ico',)
icon='../../docs/assets/antares-web-installer-icon.ico',) # TODO: edit comment and script

def start_server(self):
"""
Launch the local server as a background task
"""
args_server = ["fastapi", "run", str(self.target_dir.joinpath("AntaresWeb/AntaresWebServer.py"))]
task = subprocess.Popen(args=args_server, shell=True)
args_server = [f"{self.target_dir.joinpath('AntaresWeb/AntaresWebServer.py')}", "run"]
subprocess.Popen(args=args_server, shell=True)
webbrowser.open(url="http://localhost:8000/", new=2)
7 changes: 1 addition & 6 deletions src/antares_web_installer/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import click
import psutil

from pathlib import Path
import tkinter as tk
from app import App
from antares_web_installer.app import App

if os.name == "posix":
TARGET_DIR = "/opt/antares-web/"
Expand Down Expand Up @@ -59,7 +57,4 @@ def install_cli(src_dir: str, target_dir: str, **kwargs) -> None:
app = App(source_dir=src_dir, target_dir=target_dir, **kwargs)
app.run()

# window = Window()
# window.mainloop()

print("Done.")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __post_init__(self):
side = ttk.Frame(self.body, style='BodyFrame.TFrame')
side.pack(side=tk.LEFT)

self.side_img = tk.PhotoImage(file="../../docs/assets/galaxy-side-1-ratio.png")
self.side_img = tk.PhotoImage(file="../../../docs/assets/galaxy-side-1-ratio.png")
side_content = ttk.Label(side, image=self.side_img, borderwidth=2, relief="sunken")
side_content.pack(side=tk.LEFT, expand=False)

Expand Down
Empty file.
Empty file.
Empty file.
Empty file removed tests/results/nt/logs/.placeholder
Empty file.
Empty file.
Empty file removed tests/results/nt/tmp/.placeholder
Empty file.
16 changes: 5 additions & 11 deletions tests/samples/nt/AntaresWeb/AntaresWebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@
This script simulates the behavior of an application and return its current version.
Support script for Windows systems
"""
import os
import click
import subprocess

from pathlib import Path
import uvicorn
from fastapi import FastAPI

ANTARES_VERSION = os.environ.get("ANTARES_VERSION", "2.14")

# Server part
app = FastAPI()


@app.get("/")
def index():
return {"response": f"Antares web server version : {ANTARES_VERSION}"}
return {"response": f"Successfully running"}


# commands part
@click.group()
@click.version_option(version=ANTARES_VERSION, message="%(version)s")
@click.version_option(version="2.15", message="%(version)s")
def cli():
pass

Expand All @@ -33,11 +28,10 @@ def run():
Launch Antares web server for testing only.
Must be in background ?
"""
# test/samples must be replaced by dynamically defined directory
script_path = Path().resolve().joinpath("tests/samples/nt/AntaresWeb/AntaresWebServer.py")
subprocess.run(["fastapi", "dev", script_path], shell=True)
uvicorn.run("AntaresWebServer:app", host="127.0.0.1", port=8000, log_level="info")


# entry point
if __name__ == "__main__":
cli()

16 changes: 4 additions & 12 deletions tests/samples/posix/AntaresWeb/AntaresWebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@
This script simulates the behavior of an application and return its current version.
Support script for UNIX system
"""
import os
import click
import subprocess

from pathlib import Path
import uvicorn
from fastapi import FastAPI

ANTARES_VERSION = os.environ.get("ANTARES_VERSION", "2.14")

# Server part
app = FastAPI()


@app.get("/")
def index():
return {"response": f"Antares web server version : {ANTARES_VERSION}"}
return {"response": f"Successfully running"}


# commands part
@click.group()
@click.version_option(version=ANTARES_VERSION, message="%(version)s")
@click.version_option(version="2.15", message="%(version)s")
def cli():
pass

Expand All @@ -31,11 +26,8 @@ def cli():
def run():
"""
Launch Antares web server for testing only.
Must be in background ?
"""
# test/samples must be replaced by dynamically defined directory
script_path = Path().resolve().joinpath("tests/samples/posix/AntaresWeb/AntaresWebServer.py")
subprocess.run(["fastapi", "dev", script_path], shell=True)
uvicorn.run("AntaresWebServer:app", host="127.0.0.1", port=8000, log_level="info")


# entry point
Expand Down

0 comments on commit fd66c05

Please sign in to comment.