update hydrus_web_gui.py
This commit is contained in:
+163
-5
@@ -116,6 +116,7 @@ def run(cmd: list[str], quiet: bool = False, debug: bool = False, cwd: Optional[
|
||||
|
||||
REPO_URL = "https://code.glowers.club/goyimnose/Medios-Macina.git"
|
||||
HYDRUS_REPO_URL = "https://github.com/hydrusnetwork/hydrus.git"
|
||||
HYDRUS_WEB_GUI_REPO_URL = "https://code.glowers.club/goyimnose/api-HydrusNetwork.git"
|
||||
HYDRUS_INSTALLER_SCRIPT_URLS = (
|
||||
"https://code.glowers.club/goyimnose/Medios-Macina/raw/branch/main/scripts/hydrusnetwork.py",
|
||||
)
|
||||
@@ -510,6 +511,39 @@ def main() -> int:
|
||||
action="store_true",
|
||||
help="Verify that the 'mm' command was installed correctly",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--install-hydrus-web-gui",
|
||||
action="store_true",
|
||||
help="Clone/update api-HydrusNetwork, install npm dependencies, and prepare the Hydrus web GUI",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--hydrus-web-gui-root",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Root directory where the Hydrus web GUI should be installed (default: the Medios repo root)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--hydrus-web-gui-dest-name",
|
||||
type=str,
|
||||
default="api-HydrusNetwork",
|
||||
help="Folder name for the Hydrus web GUI checkout (default: api-HydrusNetwork)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--install-hydrus-web-gui-service",
|
||||
action="store_true",
|
||||
help="Register the Hydrus web GUI to start automatically using systemd on Linux or Task Scheduler on Windows",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--setup-hydrus-web-gui-mpv-handler",
|
||||
action="store_true",
|
||||
help="Run the Hydrus web GUI's mpv-handler setup helper after installation (Windows/Linux)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--hydrus-web-gui-service-name",
|
||||
type=str,
|
||||
default="hydrus-web-gui",
|
||||
help="Service name used for the Hydrus web GUI auto-start registration",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--uninstall",
|
||||
action="store_true",
|
||||
@@ -523,6 +557,9 @@ def main() -> int:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.install_hydrus_web_gui_service or args.setup_hydrus_web_gui_mpv_handler:
|
||||
args.install_hydrus_web_gui = True
|
||||
|
||||
# Ensure repo_root is always the project root, not the current working directory
|
||||
# This prevents issues when bootstrap.py is run from different directories
|
||||
try:
|
||||
@@ -841,13 +878,19 @@ def main() -> int:
|
||||
print("\n")
|
||||
|
||||
# Define menu options
|
||||
service_option = (
|
||||
"5) Install Hydrus System Service (Auto-update + Headless)"
|
||||
if installed
|
||||
else "4) Install Hydrus System Service (Auto-update + Headless)"
|
||||
)
|
||||
options = [
|
||||
"1) Reinstall" if installed else "1) Install",
|
||||
"2) Extras > HydrusNetwork"
|
||||
"2) Extras > HydrusNetwork",
|
||||
"3) Extras > Hydrus Web GUI",
|
||||
]
|
||||
if installed:
|
||||
options.append("3) Uninstall")
|
||||
options.append("4) Install Hydrus System Service (Auto-update + Headless)")
|
||||
options.append("4) Uninstall")
|
||||
options.append(service_option)
|
||||
options.append("q) Quit")
|
||||
|
||||
# Center the block of options by finding the longest one
|
||||
@@ -869,11 +912,14 @@ def main() -> int:
|
||||
|
||||
if choice in ("2", "extras", "hydrus"):
|
||||
return "extras_hydrus"
|
||||
|
||||
if choice in ("3", "web", "webgui", "gui"):
|
||||
return "extras_hydrus_web_gui"
|
||||
|
||||
if installed and choice in ("3", "uninstall"):
|
||||
if installed and choice in ("4", "uninstall"):
|
||||
return "uninstall"
|
||||
|
||||
if choice == "4":
|
||||
if (installed and choice == "5") or (not installed and choice == "4"):
|
||||
return "install_service"
|
||||
|
||||
if choice in ("q", "quit", "exit"):
|
||||
@@ -904,6 +950,40 @@ def main() -> int:
|
||||
print("\nHydrus installation cancelled.")
|
||||
return None
|
||||
|
||||
def _prompt_hydrus_web_gui_location() -> tuple[Path, str, bool, bool] | None:
|
||||
"""Ask the user for the Hydrus web GUI installation settings."""
|
||||
default_root = repo_root if repo_root else Path.home()
|
||||
default_dest_name = "api-HydrusNetwork"
|
||||
print("\n[Hydrus Web GUI Installation]")
|
||||
print("Install the api-HydrusNetwork web UI and optionally register it to auto-start.")
|
||||
try:
|
||||
root_input = input(f"Root directory [{default_root}]: ").strip()
|
||||
if root_input:
|
||||
if len(root_input) == 2 and root_input[1] == ":" and root_input[0].isalpha():
|
||||
root_input += "\\"
|
||||
root_path = Path(os.path.expandvars(os.path.expanduser(root_input))).resolve()
|
||||
else:
|
||||
root_path = default_root
|
||||
|
||||
dest_input = input(f"Folder name [{default_dest_name}]: ").strip()
|
||||
dest_name = dest_input or default_dest_name
|
||||
|
||||
service_default = "Y"
|
||||
service_input = input(
|
||||
"Install auto-start service with systemd/Task Scheduler? [Y/n]: "
|
||||
).strip().lower()
|
||||
install_service = service_input not in {"n", "no"}
|
||||
|
||||
setup_mpv_input = input(
|
||||
"Run mpv-handler setup after install? [y/N]: "
|
||||
).strip().lower()
|
||||
setup_mpv_handler = setup_mpv_input in {"y", "yes"}
|
||||
|
||||
return root_path, dest_name, install_service, setup_mpv_handler
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print("\nHydrus web GUI installation cancelled.")
|
||||
return None
|
||||
|
||||
def _clone_repo(url: str, dest: Path, depth: int = 1) -> bool:
|
||||
"""Helper to clone a repository."""
|
||||
try:
|
||||
@@ -935,6 +1015,45 @@ def main() -> int:
|
||||
print("Error: Failed to download Hydrus installer script", file=sys.stderr)
|
||||
return False
|
||||
|
||||
def _run_hydrus_web_gui_installer(
|
||||
install_root: Path,
|
||||
install_dest: str,
|
||||
*,
|
||||
install_service: bool = False,
|
||||
setup_mpv_handler: bool = False,
|
||||
) -> bool:
|
||||
web_gui_script = script_dir / "hydrus_web_gui.py"
|
||||
if not web_gui_script.exists():
|
||||
print(f"Error: {web_gui_script} not found.", file=sys.stderr)
|
||||
return False
|
||||
|
||||
cmd = [
|
||||
sys.executable,
|
||||
str(web_gui_script),
|
||||
"--root",
|
||||
str(install_root),
|
||||
"--dest-name",
|
||||
install_dest,
|
||||
"--repo",
|
||||
HYDRUS_WEB_GUI_REPO_URL,
|
||||
]
|
||||
if install_service:
|
||||
cmd.extend([
|
||||
"--install-service",
|
||||
"--service-name",
|
||||
args.hydrus_web_gui_service_name,
|
||||
])
|
||||
if setup_mpv_handler:
|
||||
cmd.append("--setup-mpv-handler")
|
||||
if args.debug:
|
||||
cmd.append("--debug")
|
||||
|
||||
try:
|
||||
subprocess.check_call(cmd, stdin=sys.stdin)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
def _ensure_repo_available() -> bool:
|
||||
"""Prompt for a clone location when running outside the repository."""
|
||||
nonlocal repo_root, script_dir, is_in_repo
|
||||
@@ -1255,6 +1374,27 @@ def main() -> int:
|
||||
sys.stdout.flush()
|
||||
sys.stdin.readline()
|
||||
continue
|
||||
elif sel == "extras_hydrus_web_gui":
|
||||
if not _ensure_repo_available():
|
||||
return 1
|
||||
web_gui_location = _prompt_hydrus_web_gui_location()
|
||||
if web_gui_location is None:
|
||||
continue
|
||||
install_root, install_dest, install_service, setup_mpv_handler = web_gui_location
|
||||
ok = _run_hydrus_web_gui_installer(
|
||||
install_root,
|
||||
install_dest,
|
||||
install_service=install_service,
|
||||
setup_mpv_handler=setup_mpv_handler,
|
||||
)
|
||||
if ok:
|
||||
print("\nHydrus web GUI installation finished.")
|
||||
else:
|
||||
print("\nHydrus web GUI installation failed.")
|
||||
sys.stdout.write("Press Enter to return to menu...")
|
||||
sys.stdout.flush()
|
||||
sys.stdin.readline()
|
||||
continue
|
||||
elif sel == "install_service":
|
||||
# Direct path input for the target repository
|
||||
print("\n[ SYSTEM SERVICE INSTALLATION ]")
|
||||
@@ -1371,6 +1511,8 @@ def main() -> int:
|
||||
total_steps += 1
|
||||
if not getattr(args, "no_deno", False):
|
||||
total_steps += 1
|
||||
if args.install_hydrus_web_gui:
|
||||
total_steps += 1
|
||||
|
||||
pb = ProgressBar(total_steps, quiet=args.quiet or args.debug)
|
||||
|
||||
@@ -1590,6 +1732,22 @@ def main() -> int:
|
||||
if not _check_deno_installed():
|
||||
_install_deno(args.deno_version)
|
||||
|
||||
hydrus_web_gui_root = (
|
||||
Path(os.path.expandvars(os.path.expanduser(args.hydrus_web_gui_root))).resolve()
|
||||
if args.hydrus_web_gui_root
|
||||
else repo_root
|
||||
)
|
||||
if args.install_hydrus_web_gui:
|
||||
pb.update("Installing Hydrus web GUI...")
|
||||
ok = _run_hydrus_web_gui_installer(
|
||||
hydrus_web_gui_root,
|
||||
args.hydrus_web_gui_dest_name,
|
||||
install_service=args.install_hydrus_web_gui_service,
|
||||
setup_mpv_handler=args.setup_hydrus_web_gui_mpv_handler,
|
||||
)
|
||||
if not ok:
|
||||
return 1
|
||||
|
||||
# 10. Finalizing setup
|
||||
pb.update("Writing launcher scripts...")
|
||||
def _write_launchers() -> None:
|
||||
|
||||
Reference in New Issue
Block a user