f
This commit is contained in:
@@ -738,7 +738,40 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
def _update_config_value(root: Path, key: str, value: str) -> bool:
|
||||
db_path = root / "medios.db"
|
||||
config_path = root / "config.conf"
|
||||
|
||||
# Try database first
|
||||
if db_path.exists():
|
||||
try:
|
||||
import sqlite3
|
||||
import json
|
||||
with sqlite3.connect(str(db_path)) as conn:
|
||||
# We want to set store.hydrusnetwork.hydrus.<key>
|
||||
cur = conn.cursor()
|
||||
# Check if hydrusnetwork store exists
|
||||
cur.execute("SELECT 1 FROM config WHERE category='store' AND subtype='hydrusnetwork'")
|
||||
if cur.fetchone():
|
||||
cur.execute(
|
||||
"INSERT OR REPLACE INTO config (category, subtype, item_name, key, value) VALUES (?, ?, ?, ?, ?)",
|
||||
('store', 'hydrusnetwork', 'hydrus', key, value)
|
||||
)
|
||||
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', key, value)
|
||||
)
|
||||
conn.commit()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error updating database config: {e}")
|
||||
|
||||
# Fallback to config.conf
|
||||
if not config_path.exists():
|
||||
fallback = root / "config.conf.remove"
|
||||
if fallback.exists():
|
||||
@@ -759,7 +792,7 @@ def main() -> int:
|
||||
config_path.write_text(new_content, encoding="utf-8")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error updating config: {e}")
|
||||
print(f"Error updating legacy config: {e}")
|
||||
return False
|
||||
|
||||
def _interactive_menu() -> str | int:
|
||||
@@ -1512,7 +1545,10 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
|
||||
"if not defined MM_NO_UPDATE (\n"
|
||||
" if exist \"!REPO!\\.git\" (\n"
|
||||
" set \"AUTO_UPDATE=true\"\n"
|
||||
" if exist \"!REPO!\\config.conf\" (\n"
|
||||
" if exist \"!REPO!\\medios.db\" (\n"
|
||||
" \"sqlite3\" \"!REPO!\\medios.db\" \"SELECT value FROM config WHERE key='auto_update' AND category='global'\" | findstr /i /r \"false no off 0\" >nul 2>&1\n"
|
||||
" if !errorlevel! == 0 set \"AUTO_UPDATE=false\"\n"
|
||||
" ) else if exist \"!REPO!\\config.conf\" (\n"
|
||||
" findstr /i /r \"auto_update.*=.*false auto_update.*=.*no auto_update.*=.*off auto_update.*=.*0\" \"!REPO!\\config.conf\" >nul 2>&1\n"
|
||||
" if !errorlevel! == 0 set \"AUTO_UPDATE=false\"\n"
|
||||
" )\n"
|
||||
|
||||
@@ -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