This commit is contained in:
2026-01-21 23:21:47 -08:00
parent d4f3cf90ec
commit 38a5ac89fc

View File

@@ -774,6 +774,61 @@ def main() -> int:
# Non-interactive, fall back to delegating to platform helper
return "delegate"
def _ensure_repo_available() -> bool:
"""Prompt for a clone location when running outside the repository."""
nonlocal repo_root, script_dir, is_in_repo
if is_in_repo:
return True
if not shutil.which("git"):
print("\nError: 'git' was not found on your PATH.", file=sys.stderr)
print("Please install Git (https://git-scm.com/) and try again.", file=sys.stderr)
return False
try:
if script_path is not None:
default_install = repo_root
else:
default_install = Path.cwd() / "Medios-Macina"
print("\n[WEB INSTALLER MODE]")
print("Where would you like to install Medios-Macina?")
install_dir_raw = input(f"Installation directory [{default_install}]: ").strip()
if not install_dir_raw:
install_path = default_install
else:
install_path = Path(install_dir_raw).resolve()
except (EOFError, KeyboardInterrupt):
return False
if not install_path.exists():
print(f"Creating directory: {install_path}")
install_path.mkdir(parents=True, exist_ok=True)
if _is_valid_mm_repo(install_path):
if not args.quiet:
print(f"Using existing repository in {install_path}.")
repo_root = install_path
else:
print(f"Cloning Medios-Macina into {install_path} (depth 1)...")
print(f"Source: {REPO_URL}")
try:
subprocess.check_call(["git", "clone", "--depth", "1", REPO_URL, str(install_path)])
repo_root = install_path
except Exception as e:
print(f"Error: Failed to clone repository: {e}", file=sys.stderr)
return False
os.chdir(str(repo_root))
if not args.quiet:
print(f"\nSuccessfully set up repository at {repo_root}")
print("Resuming bootstrap...\n")
script_dir = repo_root / "scripts"
is_in_repo = True
return True
# If the user passed --uninstall explicitly, perform non-interactive uninstall and exit
if args.uninstall:
return _do_uninstall()
@@ -926,66 +981,14 @@ def main() -> int:
if (sys.stdin.isatty() or sys.stdout.isatty() or script_path is None) and not args.quiet:
sel = _interactive_menu()
if sel == "install":
# If running via pipe/standalone or not in a repo, ask for installation path
if script_path is None or not is_in_repo:
if not shutil.which("git"):
print("\nError: 'git' was not found on your PATH.", file=sys.stderr)
print("Please install Git (https://git-scm.com/) and try again.", file=sys.stderr)
return 1
try:
# Force a prompt to choose the folder
if is_in_repo:
default_install = repo_root
else:
default_install = Path.cwd() / "Medios-Macina"
print(f"\n[WEB INSTALLER MODE]")
print(f"Where would you like to install Medios-Macina?")
install_dir_raw = input(f"Installation directory [{default_install}]: ").strip()
if not install_dir_raw:
install_path = default_install
else:
install_path = Path(install_dir_raw).resolve()
except (EOFError, KeyboardInterrupt):
return 1
if not install_path.exists():
print(f"Creating directory: {install_path}")
install_path.mkdir(parents=True, exist_ok=True)
# Check if it already has a repo (user might have chosen an existing folder)
if _is_valid_mm_repo(install_path):
if not args.quiet:
print(f"Using existing repository in {install_path}.")
repo_root = install_path
else:
print(f"Cloning Medios-Macina into {install_path} (depth 1)...")
print(f"Source: {REPO_URL}")
try:
subprocess.check_call(["git", "clone", "--depth", "1", REPO_URL, str(install_path)])
repo_root = install_path
except Exception as e:
print(f"Error: Failed to clone repository: {e}", file=sys.stderr)
return 1
# Change directory to the newly established repo root
os.chdir(str(repo_root))
if not args.quiet:
print(f"\nSuccessfully set up repository at {repo_root}")
print("Resuming bootstrap...\n")
# Re-initialize script_dir for the rest of the script
# as if we started inside the repo scripts folder.
script_dir = repo_root / "scripts"
is_in_repo = True
# user chose to install/reinstall; set defaults and continue
if not _ensure_repo_available():
return 1
args.skip_deps = False
args.install_editable = True
args.no_playwright = False
elif sel == "extras_hydrus":
# Special case: run the hydrusnetwork.py script and then exit
if not _ensure_repo_available():
return 1
hydrus_script = repo_root / "scripts" / "hydrusnetwork.py"
if hydrus_script.exists():
try: