d
This commit is contained in:
@@ -876,15 +876,6 @@ def main() -> int:
|
|||||||
if hydrus_script.exists():
|
if hydrus_script.exists():
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([sys.executable, str(hydrus_script)])
|
subprocess.check_call([sys.executable, str(hydrus_script)])
|
||||||
|
|
||||||
# New: Prompt for location as requested
|
|
||||||
print("\n" + "="*40)
|
|
||||||
print(" HYDRUS CONFIGURATION")
|
|
||||||
print("="*40)
|
|
||||||
location = input("\nEnter the absolute path to your Hydrus git clone\n(to link it with Medios-Macina config): ").strip()
|
|
||||||
if location:
|
|
||||||
if _update_config_value(repo_root, "gitclone", location):
|
|
||||||
print(f"✅ Updated config.conf with gitclone=\"{location}\"")
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print("\nHydrusNetwork setup exited with an error.")
|
print("\nHydrusNetwork setup exited with an error.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import tempfile
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import zipfile
|
import zipfile
|
||||||
import shlex
|
import shlex
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
@@ -143,6 +144,45 @@ def run_git_pull(git: str, dest: Path) -> None:
|
|||||||
subprocess.run([git, "-C", str(dest), "pull"], check=True)
|
subprocess.run([git, "-C", str(dest), "pull"], check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def update_medios_config(hydrus_path: Path) -> bool:
|
||||||
|
"""Attempt to update config.conf in the Medios-Macina root with the hydrus path.
|
||||||
|
|
||||||
|
This helps link the newly installed Hydrus instance with the main project.
|
||||||
|
"""
|
||||||
|
# Scripts is in <root>/scripts, so parent is root.
|
||||||
|
script_dir = Path(__file__).resolve().parent
|
||||||
|
root = script_dir.parent
|
||||||
|
config_path = root / "config.conf"
|
||||||
|
|
||||||
|
if not config_path.exists():
|
||||||
|
logging.debug("MM config.conf not found at %s; skipping auto-link.", config_path)
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
content = config_path.read_text(encoding="utf-8")
|
||||||
|
key = "gitclone"
|
||||||
|
value = str(hydrus_path.resolve())
|
||||||
|
|
||||||
|
# Pattern to replace existing gitclone in the hydrusnetwork section
|
||||||
|
pattern = rf'^(\s*{re.escape(key)}\s*=\s*)(.*)$'
|
||||||
|
if re.search(pattern, content, flags=re.MULTILINE):
|
||||||
|
new_content = re.sub(pattern, rf'\1"{value}"', content, flags=re.MULTILINE)
|
||||||
|
else:
|
||||||
|
section_pattern = r'\[store=hydrusnetwork\]'
|
||||||
|
if re.search(section_pattern, content):
|
||||||
|
new_content = re.sub(section_pattern, f'[store=hydrusnetwork]\n{key}="{value}"', content, count=1)
|
||||||
|
else:
|
||||||
|
new_content = content + f'\n\n[store=hydrusnetwork]\nname="hydrus"\n{key}="{value}"'
|
||||||
|
|
||||||
|
if new_content != content:
|
||||||
|
config_path.write_text(new_content, encoding="utf-8")
|
||||||
|
logging.info("✅ Linked Hydrus installation in Medios-Macina config (gitclone=\"%s\")", value)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.debug("Failed to update MM config: %s", e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def download_and_extract_zip(
|
def download_and_extract_zip(
|
||||||
repo_url: str,
|
repo_url: str,
|
||||||
dest: Path,
|
dest: Path,
|
||||||
@@ -690,12 +730,20 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Perform a full clone (no --depth passed to git clone)"
|
help="Perform a full clone (no --depth passed to git clone)"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
group_obtain = parser.add_mutually_exclusive_group()
|
||||||
|
group_obtain.add_argument(
|
||||||
"--git",
|
"--git",
|
||||||
|
dest="git",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help=
|
help="Use git clone (shallow by default) to allow updates. This is the default.",
|
||||||
"Use git clone instead of fetching repository ZIP (opt-in). Default: fetch ZIP (smaller).",
|
|
||||||
)
|
)
|
||||||
|
group_obtain.add_argument(
|
||||||
|
"--no-git",
|
||||||
|
dest="git",
|
||||||
|
action="store_false",
|
||||||
|
help="Use ZIP download instead of git clone (no git pull support).",
|
||||||
|
)
|
||||||
|
parser.set_defaults(git=True)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-fallback",
|
"--no-fallback",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -857,6 +905,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|||||||
try:
|
try:
|
||||||
run_git_pull(git, dest)
|
run_git_pull(git, dest)
|
||||||
logging.info("Updated repository in %s", dest)
|
logging.info("Updated repository in %s", dest)
|
||||||
|
update_medios_config(dest)
|
||||||
return 0
|
return 0
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
logging.error("git pull failed: %s", e)
|
logging.error("git pull failed: %s", e)
|
||||||
@@ -975,14 +1024,14 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|||||||
"python-dateutil": "dateutil",
|
"python-dateutil": "dateutil",
|
||||||
"beautifulsoup4": "bs4",
|
"beautifulsoup4": "bs4",
|
||||||
"pillow-heif": "pillow_heif",
|
"pillow-heif": "pillow_heif",
|
||||||
"pillow-jxl-plugin": "pillow_jxl_plugin",
|
"pillow-jxl-plugin": "pillow_jxl",
|
||||||
"pyopenssl": "OpenSSL",
|
"pyopenssl": "OpenSSL",
|
||||||
"pysocks": "socks",
|
"pysocks": "socks",
|
||||||
"service-identity": "service_identity",
|
"service-identity": "service_identity",
|
||||||
"show-in-file-manager": "show_in_file_manager",
|
|
||||||
"opencv-python-headless": "cv2",
|
"opencv-python-headless": "cv2",
|
||||||
"mpv": "mpv",
|
"pyyside6": "PySide6",
|
||||||
"pyside6": "PySide6",
|
"pyside6-essentials": "PySide6",
|
||||||
|
"pyside6-addons": "PySide6",
|
||||||
}
|
}
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
mod = import_map.get(pkg, pkg)
|
mod = import_map.get(pkg, pkg)
|
||||||
@@ -1176,6 +1225,10 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|||||||
logging.error("Failed to obtain repository (ZIP): %s", exc)
|
logging.error("Failed to obtain repository (ZIP): %s", exc)
|
||||||
return 7
|
return 7
|
||||||
|
|
||||||
|
# Auto-link to Medios-Macina if possible
|
||||||
|
if obtained:
|
||||||
|
update_medios_config(dest)
|
||||||
|
|
||||||
# Post-obtain setup: create repository-local venv (unless disabled)
|
# Post-obtain setup: create repository-local venv (unless disabled)
|
||||||
if not getattr(args, "no_venv", False):
|
if not getattr(args, "no_venv", False):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user