f
This commit is contained in:
@@ -144,23 +144,63 @@ def run_git_pull(git: str, dest: Path) -> None:
|
||||
|
||||
|
||||
def update_medios_config(hydrus_path: Path) -> bool:
|
||||
"""Attempt to update config.conf in the Medios-Macina root with the hydrus path.
|
||||
"""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.
|
||||
"""
|
||||
# Scripts is in <root>/scripts, so parent is root.
|
||||
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)) 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)
|
||||
|
||||
# Fallback to config.conf
|
||||
if not config_path.exists():
|
||||
logging.debug("MM config.conf not found at %s; skipping auto-link.", config_path)
|
||||
logging.debug("MM config.conf not found at %s; skipping legacy auto-link.", config_path)
|
||||
return False
|
||||
|
||||
try:
|
||||
content = config_path.read_text(encoding="utf-8")
|
||||
key = "gitclone"
|
||||
value = str(hydrus_path.resolve())
|
||||
value = hydrus_abs_path
|
||||
|
||||
# Pattern to replace existing gitclone in the hydrusnetwork section
|
||||
pattern = rf'^(\s*{re.escape(key)}\s*=\s*)(.*)$'
|
||||
@@ -178,6 +218,9 @@ def update_medios_config(hydrus_path: Path) -> bool:
|
||||
logging.info("✅ Linked Hydrus installation in Medios-Macina config (gitclone=\"%s\")", value)
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error("Failed to update config.conf: %s", e)
|
||||
return False
|
||||
return False
|
||||
logging.debug("Failed to update MM config: %s", e)
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user