From 9c82b58544b114c1816351dfa3bc6d276712bb8c Mon Sep 17 00:00:00 2001 From: Nose Date: Fri, 10 Jul 2026 21:49:57 -0700 Subject: [PATCH] update shim --- scripts/bootstrap.py | 88 ++++++-------------------------------------- 1 file changed, 12 insertions(+), 76 deletions(-) diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 7a0afc7..efd3f55 100644 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -1890,89 +1890,25 @@ if (Test-Path (Join-Path $repo 'CLI.py')) { if not (repo / "scripts").exists(): print(f"WARNING: scripts folder not found at {repo}/scripts - mm command may not work", file=sys.stderr) - # Write mm.bat (batch shim works in all shells, bypasses PowerShell execution policy) + # Keep the batch shim deliberately small: cmd.exe parses every + # parenthesized block before executing it, which makes richer + # update logic brittle when paths or messages contain special + # batch characters. mm_bat = user_bin / "mm.bat" repo_bat_str = str(repo) bat_text = ( "@echo off\n" - "setlocal enabledelayedexpansion\n" + "setlocal\n" f'set "REPO={repo_bat_str}"\n' - "set \"VENV=!REPO!\\.venv\"\n" - "set \"PY=!VENV!\\Scripts\\python.exe\"\n" - "set \"ENTRY=!REPO!\\scripts\\cli_entry.py\"\n" - "set \"REQ=!REPO!\\scripts\\requirements.txt\"\n" + "set \"PY=%REPO%\\.venv\\Scripts\\python.exe\"\n" "\n" - ":: Automatically check for updates if this is a git repository\n" - "if not defined MM_NO_UPDATE (\n" - " if exist \"!REPO!\\.git\" (\n" - " set \"AUTO_UPDATE=true\"\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" - " if \"!AUTO_UPDATE!\" == \"true\" (\n" - " echo Checking for updates...\n" - " echo [mm] Checking repository updates...\n" - " set \"GIT_OUT=%TEMP%\\mm_git_update_!RANDOM!_!RANDOM!.log\"\n" - " git -C \"!REPO!\" pull --ff-only >\"!GIT_OUT!\" 2>&1\n" - " set \"GIT_EXIT=!errorlevel!\"\n" - " set \"REPO_UPDATED=false\"\n" - " set \"SKIP_DEP_UPDATE=false\"\n" - " if \"!GIT_EXIT!\" == \"0\" (\n" - " findstr /i /c:\"Updating\" /c:\"Fast-forward\" \"!GIT_OUT!\" >nul 2>&1\n" - " if !errorlevel! == 0 (\n" - " set \"REPO_UPDATED=true\"\n" - " echo [mm] Repository update found - fast-forward applied.\n" - " ) else (\n" - " echo [mm] Repository already up to date.\n" - " )\n" - " ) else (\n" - " set \"SKIP_DEP_UPDATE=true\"\n" - " echo [mm] Warning: git update check failed; continuing startup.\n" - " type \"!GIT_OUT!\"\n" - " )\n" - " del /q \"!GIT_OUT!\" >nul 2>&1\n" - " if \"!SKIP_DEP_UPDATE!\" == \"true\" (\n" - " echo [mm] Python module update skipped (network/update check unavailable).\n" - " ) else if not defined MM_NO_DEP_UPDATE (\n" - " if exist \"!PY!\" if exist \"!REQ!\" (\n" - " echo [mm] Checking Python module updates...\n" - " set \"PIP_OUT=%TEMP%\\mm_pip_update_!RANDOM!_!RANDOM!.log\"\n" - " \"!PY!\" -m pip install --disable-pip-version-check --upgrade -r \"!REQ!\" >\"!PIP_OUT!\" 2>&1\n" - " if !errorlevel! == 0 (\n" - " findstr /i /c:\"Successfully installed\" \"!PIP_OUT!\" >nul 2>&1\n" - " if !errorlevel! == 0 (\n" - " for /f \"delims=\" %%L in ('findstr /i /c:\"Successfully installed\" \"!PIP_OUT!\"') do set \"PIP_SUM=%%L\"\n" - " if defined PIP_SUM echo [mm] !PIP_SUM!\n" - " ) else (\n" - " echo [mm] Python modules are already up to date.\n" - " )\n" - " ) else (\n" - " echo [mm] Warning: dependency update failed; continuing startup.\n" - " type \"!PIP_OUT!\"\n" - " )\n" - " del /q \"!PIP_OUT!\" >nul 2>&1\n" - " )\n" - " ) else (\n" - " echo [mm] Python module update skipped: MM_NO_DEP_UPDATE=1.\n" - " )\n" - " if \"!REPO_UPDATED!\" == \"true\" (\n" - " echo Medeia-Macina has been updated. Please restart the application to apply changes.\n" - " exit /b 0\n" - " )\n" - " )\n" - " )\n" + "cd /d \"%REPO%\"\n" + "if exist \"%PY%\" (\n" + " \"%PY%\" -m scripts.cli_entry %*\n" + " exit /b %ERRORLEVEL%\n" ")\n" - "\n" - "if exist \"!PY!\" (\n" - " \"!PY!\" \"!ENTRY!\" %*\n" - " exit /b !ERRORLEVEL!\n" - ")\n" - "python \"!ENTRY!\" %*\n" - "exit /b !ERRORLEVEL!\n" + "python -m scripts.cli_entry %*\n" + "exit /b %ERRORLEVEL%\n" ) if mm_bat.exists(): bak = mm_bat.with_suffix(f".bak{int(time.time())}")