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,44 +3,78 @@ from pathlib import Path
|
||||
import PyInstaller.__main__
|
||||
import typer
|
||||
from rich import print
|
||||
from rich.progress import Progress
|
||||
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
@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:
|
||||
|
||||
print("Building with PyInstaller")
|
||||
PyInstaller.__main__.run([
|
||||
"anon_gui.spec"
|
||||
])
|
||||
|
||||
if test:
|
||||
print("Building Windows test one-file bundle with PyInstaller")
|
||||
# On Windows use ';' as add-data separator (src;dest)
|
||||
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:
|
||||
print("Copying file")
|
||||
source = Path(r"C:\Users\krugerro\Desktop\uploader\dist\anon_gui.exe" )
|
||||
dest =Path(r"T:\rad-tools\uploader" )
|
||||
# Windows-only default destination used previously in the repo
|
||||
default_dest = Path(r"\\ict\Go\RCH\Shared\Dragon-Xray\rad-tools\uploader\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
|
||||
while True:
|
||||
if n > 5:
|
||||
break
|
||||
artifact = candidates[0]
|
||||
|
||||
s = n if n > 0 else ""
|
||||
filename = Path(f"cris_tools{s}.exe")
|
||||
dest_path = Path(dest) if dest else default_dest
|
||||
dest_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
print(f"Destination: {filename}")
|
||||
try:
|
||||
shutil.copy(source, dest / filename)
|
||||
break
|
||||
|
||||
except PermissionError:
|
||||
n = n + 1
|
||||
if artifact.is_file():
|
||||
target = dest_path / artifact.name
|
||||
print(f"Copying {artifact} -> {target}")
|
||||
shutil.copy2(artifact, target)
|
||||
else:
|
||||
target = dest_path / artifact.name
|
||||
print(f"Copying directory {artifact} -> {target}")
|
||||
if target.exists():
|
||||
shutil.rmtree(target)
|
||||
shutil.copytree(artifact, target)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user