This commit is contained in:
2026-01-23 15:02:19 -08:00
parent 523d9f839c
commit 797b5fee40
3 changed files with 58 additions and 42 deletions

View File

@@ -159,56 +159,62 @@ def run_git_pull(git: str, dest: Path) -> None:
subprocess.run([git, "-C", str(dest), "pull"], check=True)
def _sanitize_store_name(name: str) -> str:
clean = "".join(ch for ch in name if ch.isalnum() or ch in {"-", "_"})
return clean or "hydrus"
def update_medios_config(hydrus_path: Path) -> bool:
"""Attempt to update Medios-Macina root configuration with the hydrus path.
This helps link the newly installed Hydrus instance with the main project.
We check for medios.db first, then fall back to config.conf.
We look for an existing hydrusnetwork backend entry and attach the gitclone
path to that backend. This avoids hard-coded store names such as "hydrus" or
"hn-local" so users can pick their own alias.
"""
script_dir = Path(__file__).resolve().parent
root = script_dir.parent
db_path = root / "medios.db"
config_path = root / "config.conf"
hydrus_abs_path = str(hydrus_path.resolve())
# Try database first
if db_path.exists():
try:
import sqlite3
import json
with sqlite3.connect(str(db_path), timeout=30.0) as conn:
conn.row_factory = sqlite3.Row
cur = conn.cursor()
# We want to set store.hydrusnetwork.hydrus.gitclone
# First check if hydrusnetwork store exists
cur.execute("SELECT 1 FROM config WHERE category='store' AND subtype='hydrusnetwork'")
if cur.fetchone():
# Update or insert gitclone for the hydrus subtype
# Note: we assume the name is 'hydrus' or 'hn-local' or something.
# Usually it's 'hydrus' if newly created.
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'gitclone', hydrus_abs_path)
)
else:
# Create the section
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'name', 'hydrus')
)
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', 'hydrus', 'gitclone', hydrus_abs_path)
)
conn.commit()
logging.info("✅ Linked Hydrus installation in medios.db (gitclone=\"%s\")", hydrus_abs_path)
return True
except Exception as e:
logging.error("Failed to update medios.db: %s", e)
if not db_path.exists():
return False
return False
try:
import sqlite3
with sqlite3.connect(str(db_path), timeout=30.0) as conn:
conn.row_factory = sqlite3.Row
cur = conn.cursor()
cur.execute(
"SELECT DISTINCT item_name FROM config WHERE category='store' AND subtype='hydrusnetwork'"
)
rows = [row[0] for row in cur.fetchall() if row[0]]
if not rows:
store_name = _sanitize_store_name(hydrus_path.name)
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', store_name, 'name', store_name)
)
rows = [store_name]
for name in rows:
cur.execute(
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
('store', 'hydrusnetwork', name, 'gitclone', hydrus_abs_path)
)
conn.commit()
logging.info(
"✅ Linked Hydrus installation in medios.db for [%s] (gitclone=\"%s\")",
rows,
hydrus_abs_path,
)
return True
except Exception as e:
logging.error("Failed to update medios.db: %s", e)
return False
def download_and_extract_zip(