enhance build script and logging: add destination option to build command, log output to uploader.log, and improve artifact handling
This commit is contained in:
+3
-1
@@ -13,4 +13,6 @@ test/*
|
|||||||
|
|
||||||
*.build
|
*.build
|
||||||
|
|
||||||
C:/* # Windows paths on linux
|
C:/* # Windows paths on linux
|
||||||
|
|
||||||
|
uploader.log
|
||||||
@@ -3,44 +3,78 @@ from pathlib import Path
|
|||||||
import PyInstaller.__main__
|
import PyInstaller.__main__
|
||||||
import typer
|
import typer
|
||||||
from rich import print
|
from rich import print
|
||||||
from rich.progress import Progress
|
|
||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def build(build: bool = True, copy: bool = True, test: bool = False):
|
def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | None = None):
|
||||||
|
"""Windows-focused build script.
|
||||||
|
|
||||||
|
- `--test` creates a one-file test binary in `dist\test`.
|
||||||
|
- `--copy` (default) copies the artifact to the shared network path used previously.
|
||||||
|
"""
|
||||||
|
|
||||||
|
project_root = Path(__file__).resolve().parent
|
||||||
|
|
||||||
if build:
|
if build:
|
||||||
|
if test:
|
||||||
print("Building with PyInstaller")
|
print("Building Windows test one-file bundle with PyInstaller")
|
||||||
PyInstaller.__main__.run([
|
# On Windows use ';' as add-data separator (src;dest)
|
||||||
"anon_gui.spec"
|
PyInstaller.__main__.run([
|
||||||
])
|
str(project_root / "nice.py"),
|
||||||
|
"--onefile",
|
||||||
|
"--name",
|
||||||
|
"anon_gui_test",
|
||||||
|
"--distpath",
|
||||||
|
str(project_root / "dist" / "test"),
|
||||||
|
"--workpath",
|
||||||
|
str(project_root / "build" / "test"),
|
||||||
|
"--specpath",
|
||||||
|
str(project_root / "build" / "specs"),
|
||||||
|
"--add-data",
|
||||||
|
"icon;icon",
|
||||||
|
"--hidden-import",
|
||||||
|
"bs4",
|
||||||
|
"--hidden-import",
|
||||||
|
"requests",
|
||||||
|
"--hidden-import",
|
||||||
|
"nicegui",
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
print("Building using spec: nice_uploader.spec")
|
||||||
|
PyInstaller.__main__.run([str(project_root / "nice_uploader.spec")])
|
||||||
|
|
||||||
if copy:
|
if copy:
|
||||||
print("Copying file")
|
# Windows-only default destination used previously in the repo
|
||||||
source = Path(r"C:\Users\krugerro\Desktop\uploader\dist\anon_gui.exe" )
|
default_dest = Path(r"\\ict\Go\RCH\Shared\Dragon-Xray\rad-tools\uploader\Uploader")
|
||||||
dest =Path(r"T:\rad-tools\uploader" )
|
|
||||||
|
|
||||||
|
artifact_dir = project_root / "dist" / ("test" if test else "")
|
||||||
|
if not artifact_dir.exists():
|
||||||
|
artifact_dir = project_root / "dist"
|
||||||
|
|
||||||
|
# Look for a matching artifact
|
||||||
|
candidates = list(artifact_dir.glob("Uploader*")) + list(artifact_dir.glob("*.exe"))
|
||||||
|
if not candidates:
|
||||||
|
print(f"No build artifact found in {artifact_dir}, skipping copy")
|
||||||
|
return
|
||||||
|
|
||||||
n = 0
|
artifact = candidates[0]
|
||||||
while True:
|
|
||||||
if n > 5:
|
|
||||||
break
|
|
||||||
|
|
||||||
s = n if n > 0 else ""
|
dest_path = Path(dest) if dest else default_dest
|
||||||
filename = Path(f"cris_tools{s}.exe")
|
dest_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
print(f"Destination: {filename}")
|
if artifact.is_file():
|
||||||
try:
|
target = dest_path / artifact.name
|
||||||
shutil.copy(source, dest / filename)
|
print(f"Copying {artifact} -> {target}")
|
||||||
break
|
shutil.copy2(artifact, target)
|
||||||
|
else:
|
||||||
except PermissionError:
|
target = dest_path / artifact.name
|
||||||
n = n + 1
|
print(f"Copying directory {artifact} -> {target}")
|
||||||
|
if target.exists():
|
||||||
|
shutil.rmtree(target)
|
||||||
|
shutil.copytree(artifact, target)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ DELETE_FILES_ON_UPLOAD = True
|
|||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
logging.getLogger('niceGUI').setLevel(logging.INFO)
|
logging.getLogger('niceGUI').setLevel(logging.INFO)
|
||||||
|
logger.add("uploader.log", rotation="10 MB")
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
BASE_SITE_URL = "http://localhost:8000"
|
BASE_SITE_URL = "http://localhost:8000"
|
||||||
@@ -542,6 +543,7 @@ def login() -> Optional[RedirectResponse]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
@ui.page("/")
|
@ui.page("/")
|
||||||
def main_page():
|
def main_page():
|
||||||
async def watch_for_shutdown():
|
async def watch_for_shutdown():
|
||||||
@@ -683,6 +685,7 @@ def main_page():
|
|||||||
ui.button("About", on_click=about_dialog.open).props("outline color=white")
|
ui.button("About", on_click=about_dialog.open).props("outline color=white")
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
def launch_app(
|
def launch_app(
|
||||||
work_dir: Path = typer.Option(WORK_DIR, help="Working directory"),
|
work_dir: Path = typer.Option(WORK_DIR, help="Working directory"),
|
||||||
nng: bool = typer.Option(True, help="Use nng"),
|
nng: bool = typer.Option(True, help="Use nng"),
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ loguru
|
|||||||
dicom2jpg
|
dicom2jpg
|
||||||
pyinstaller
|
pyinstaller
|
||||||
nicegui
|
nicegui
|
||||||
|
pywebview
|
||||||
|
|||||||
Reference in New Issue
Block a user