f
This commit is contained in:
@@ -81,6 +81,9 @@ def run(cmd: list[str], quiet: bool = False, debug: bool = False, cwd: Optional[
|
||||
subprocess.check_call(cmd, cwd=str(cwd) if cwd else None)
|
||||
|
||||
|
||||
REPO_URL = "https://code.glowers.club/goyimnose/Medios-Macina.git"
|
||||
|
||||
|
||||
class ProgressBar:
|
||||
def __init__(self, total: int, quiet: bool = False):
|
||||
self.total = total
|
||||
@@ -475,9 +478,87 @@ def main() -> int:
|
||||
|
||||
# Ensure repo_root is always the project root, not the current working directory
|
||||
# This prevents issues when bootstrap.py is run from different directories
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
repo_root = script_dir.parent
|
||||
try:
|
||||
script_path = Path(__file__).resolve()
|
||||
script_dir = script_path.parent
|
||||
repo_root = script_dir.parent
|
||||
except NameError:
|
||||
# Running via pipe/eval, __file__ is not defined
|
||||
script_path = None
|
||||
script_dir = Path.cwd()
|
||||
repo_root = Path.cwd()
|
||||
|
||||
# DETECT REPOSITORY
|
||||
# Check if we are already inside a valid Medios-Macina repo
|
||||
def _is_valid_mm_repo(p: Path) -> bool:
|
||||
return (p / "CLI.py").exists() and (p / "scripts").exists()
|
||||
|
||||
is_in_repo = _is_valid_mm_repo(repo_root)
|
||||
|
||||
# If not in the parent of the script, check the current working directory
|
||||
if not is_in_repo and _is_valid_mm_repo(Path.cwd()):
|
||||
repo_root = Path.cwd()
|
||||
script_dir = repo_root / "scripts"
|
||||
is_in_repo = True
|
||||
|
||||
# STANDALONE INSTALLER MODE
|
||||
# If the script is run from a location that doesn't look like a Medios-Macina repo,
|
||||
# or if we're in a completely empty directory, offer to clone the repo.
|
||||
if not is_in_repo:
|
||||
if not args.quiet:
|
||||
print("\n" + "=" * 60)
|
||||
print(" MEDEOS-MACINA STANDALONE INSTALLER")
|
||||
print("=" * 60)
|
||||
print("No existing Medeos-Macina repository found at this location.")
|
||||
if script_path:
|
||||
print(f"Current script location: {script_path}")
|
||||
|
||||
# Check for git
|
||||
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:
|
||||
# Ask for installation folder
|
||||
default_install = Path.cwd() / "Medios-Macina"
|
||||
print(f"\nWhere would you like to install Medeos-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:
|
||||
print("Non-interactive session: cannot proceed with clone.", file=sys.stderr)
|
||||
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):
|
||||
print(f"Found existing repository in {install_path}.")
|
||||
repo_root = install_path
|
||||
else:
|
||||
print(f"Cloning Medeos-Macina into {install_path}...")
|
||||
print(f"Source: {REPO_URL}")
|
||||
try:
|
||||
subprocess.check_call(["git", "clone", 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))
|
||||
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"
|
||||
|
||||
if not args.quiet:
|
||||
print(f"Bootstrap script location: {script_dir}")
|
||||
print(f"Detected project root: {repo_root}")
|
||||
|
||||
@@ -30,7 +30,7 @@ import urllib.request
|
||||
import zipfile
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional, Sequence, Tuple
|
||||
|
||||
import logging
|
||||
|
||||
@@ -308,7 +308,11 @@ def find_project_venv(root: Path) -> Optional[Path]:
|
||||
return None
|
||||
|
||||
|
||||
def maybe_reexec_under_project_venv(root: Path, disable: bool = False) -> None:
|
||||
def maybe_reexec_under_project_venv(
|
||||
root: Path,
|
||||
disable: bool = False,
|
||||
extra_argv: Sequence[str] | None = None,
|
||||
) -> None:
|
||||
"""If a project venv exists and we are not already running under it, re-exec
|
||||
the current script using that venv's python interpreter.
|
||||
|
||||
@@ -344,9 +348,12 @@ def maybe_reexec_under_project_venv(root: Path, disable: bool = False) -> None:
|
||||
script_path = Path(sys.argv[0]).resolve()
|
||||
except Exception:
|
||||
script_path = None
|
||||
args = [str(py),
|
||||
str(script_path) if script_path is not None else sys.argv[0]
|
||||
] + sys.argv[1:]
|
||||
args = [
|
||||
str(py),
|
||||
str(script_path) if script_path is not None else sys.argv[0]
|
||||
] + sys.argv[1:]
|
||||
if extra_argv:
|
||||
args += list(extra_argv)
|
||||
logging.debug("Exec args: %s", args)
|
||||
os.execvpe(str(py), args, env)
|
||||
except Exception as exc:
|
||||
@@ -852,6 +859,11 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
action="store_true",
|
||||
help="Do not attempt to re-exec the script under a project venv (if present)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--use-project-venv",
|
||||
action="store_true",
|
||||
help="Force using the project venv even when running interactively",
|
||||
)
|
||||
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose logging")
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
@@ -861,6 +873,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
|
||||
# Interactive setup for root and name if not provided and in a TTY
|
||||
# We check sys.argv directly to see if the flags were explicitly passed.
|
||||
interactive_setup = False
|
||||
if sys.stdin.isatty() and not any(arg in sys.argv for arg in ["--root", "-r", "--dest-name", "-d"]):
|
||||
print("\nHydrusNetwork Setup")
|
||||
print("--------------------")
|
||||
@@ -870,6 +883,9 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
try:
|
||||
root_input = input(f"Enter root directory for Hydrus installation [default: {default_root}]: ").strip()
|
||||
if root_input:
|
||||
# If they typed "C:" or similar, assume they want the root "C:\"
|
||||
if len(root_input) == 2 and root_input[1] == ":" and root_input[0].isalpha():
|
||||
root_input += "\\"
|
||||
args.root = root_input
|
||||
else:
|
||||
args.root = str(default_root)
|
||||
@@ -881,6 +897,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print("\nSetup cancelled.")
|
||||
return 0
|
||||
interactive_setup = True
|
||||
|
||||
# Expand variables like $HOME or %USERPROFILE% and ~
|
||||
args.root = os.path.expandvars(args.root)
|
||||
@@ -889,7 +906,25 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
venv_py = None
|
||||
# Re-exec under project venv by default when present (opt-out with --no-project-venv)
|
||||
try:
|
||||
maybe_reexec_under_project_venv(root, disable=bool(args.no_project_venv))
|
||||
# If we are already running in a venv-like environment, we might skip re-exec.
|
||||
# However, we only re-exec if the target root is the same as the project root.
|
||||
disable_reexec = bool(args.no_project_venv)
|
||||
|
||||
# Don't re-exec when running interactively unless explicitly requested.
|
||||
if interactive_setup and not args.use_project_venv:
|
||||
disable_reexec = True
|
||||
|
||||
current_repo_root = Path(__file__).resolve().parent.parent
|
||||
# Only re-exec if the target root folder matches the folder where THIS script lives.
|
||||
# This prevents picking up Medios-Macina's .venv when installing Hydrus to a separate drive/folder.
|
||||
if root != current_repo_root and not args.use_project_venv:
|
||||
disable_reexec = True
|
||||
|
||||
maybe_reexec_under_project_venv(
|
||||
root,
|
||||
disable=disable_reexec,
|
||||
extra_argv=["--root", args.root, "--dest-name", args.dest_name],
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1036,8 +1071,10 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
"pyopenssl": "OpenSSL",
|
||||
"pysocks": "socks",
|
||||
"service-identity": "service_identity",
|
||||
"show-in-file-manager": "showinfm",
|
||||
"opencv-python-headless": "cv2",
|
||||
"pyyside6": "PySide6",
|
||||
"mpv": "mpv",
|
||||
"pyside6": "PySide6",
|
||||
"pyside6-essentials": "PySide6",
|
||||
"pyside6-addons": "PySide6",
|
||||
}
|
||||
@@ -1345,14 +1382,16 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
"python-dateutil": "dateutil",
|
||||
"beautifulsoup4": "bs4",
|
||||
"pillow-heif": "pillow_heif",
|
||||
"pillow-jxl-plugin": "pillow_jxl_plugin",
|
||||
"pillow-jxl-plugin": "pillow_jxl",
|
||||
"pyopenssl": "OpenSSL",
|
||||
"pysocks": "socks",
|
||||
"service-identity": "service_identity",
|
||||
"show-in-file-manager": "show_in_file_manager",
|
||||
"show-in-file-manager": "showinfm",
|
||||
"opencv-python-headless": "cv2",
|
||||
"mpv": "mpv",
|
||||
"pyside6": "PySide6",
|
||||
"pyside6-essentials": "PySide6",
|
||||
"pyside6-addons": "PySide6",
|
||||
}
|
||||
for pkg in pkgs:
|
||||
try:
|
||||
@@ -1463,8 +1502,18 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
|
||||
run_client_script = None
|
||||
if client_found:
|
||||
# Prefer run_client helper located in the cloned repo; if missing, fall back to top-level scripts folder helper.
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
helper_src = script_dir / "run_client.py"
|
||||
helper_dest = dest / "run_client.py"
|
||||
if helper_src.exists() and not helper_dest.exists():
|
||||
try:
|
||||
shutil.copy2(helper_src, helper_dest)
|
||||
if os.name != "nt":
|
||||
helper_dest.chmod(helper_dest.stat().st_mode | 0o111)
|
||||
logging.debug("Copied run_client helper to %s", helper_dest)
|
||||
except Exception as exc: # pragma: no cover - best effort
|
||||
logging.debug("Failed to copy run_client helper: %s", exc)
|
||||
# Prefer run_client helper located in the cloned repo; if missing, fall back to top-level scripts folder helper.
|
||||
helper_candidates = [dest / "run_client.py", script_dir / "run_client.py"]
|
||||
for cand in helper_candidates:
|
||||
if cand.exists():
|
||||
|
||||
@@ -138,11 +138,11 @@ def verify_imports(venv_py: Path, packages: List[str]) -> bool:
|
||||
"python-dateutil": "dateutil",
|
||||
"beautifulsoup4": "bs4",
|
||||
"pillow-heif": "pillow_heif",
|
||||
"pillow-jxl-plugin": "pillow_jxl_plugin",
|
||||
"pillow-jxl-plugin": "pillow_jxl",
|
||||
"pyopenssl": "OpenSSL",
|
||||
"pysocks": "socks",
|
||||
"service-identity": "service_identity",
|
||||
"show-in-file-manager": "show_in_file_manager",
|
||||
"show-in-file-manager": "showinfm",
|
||||
"opencv-python-headless": "cv2",
|
||||
"mpv": "mpv",
|
||||
"pyside6": "PySide6",
|
||||
@@ -642,16 +642,23 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
|
||||
args = p.parse_args(argv)
|
||||
|
||||
workspace_root = Path(__file__).resolve().parent.parent
|
||||
# Determine default repo root: prefer <workspace>/hydrusnetwork when present
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
if (script_dir / "hydrus_client.py").exists():
|
||||
workspace_root = script_dir
|
||||
else:
|
||||
workspace_root = script_dir.parent
|
||||
|
||||
if args.repo_root:
|
||||
repo_root = Path(args.repo_root).expanduser().resolve()
|
||||
else:
|
||||
candidate = workspace_root / "hydrusnetwork"
|
||||
if candidate.exists():
|
||||
repo_root = candidate
|
||||
else:
|
||||
if (workspace_root / "hydrus_client.py").exists():
|
||||
repo_root = workspace_root
|
||||
else:
|
||||
candidate = workspace_root / "hydrusnetwork"
|
||||
if candidate.exists():
|
||||
repo_root = candidate
|
||||
else:
|
||||
repo_root = workspace_root
|
||||
|
||||
venv_py = find_venv_python(repo_root, args.venv, args.venv_name)
|
||||
|
||||
@@ -822,14 +829,15 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
cmd = [str(venv_py), str(client_path)] + client_args
|
||||
|
||||
# Determine headless vs GUI
|
||||
first_run = is_first_run(repo_root)
|
||||
if args.gui:
|
||||
headless = False
|
||||
elif args.headless:
|
||||
headless = True
|
||||
else:
|
||||
headless = not first_run
|
||||
if not args.quiet and first_run:
|
||||
# Default to GUI for the client launcher
|
||||
headless = False
|
||||
|
||||
if not args.quiet and is_first_run(repo_root):
|
||||
print("First run detected: defaulting to GUI unless --headless is specified.")
|
||||
|
||||
env = os.environ.copy()
|
||||
|
||||
Reference in New Issue
Block a user