Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

tools: manage.py install names a missing bash or Gradle wrapper instead of a traceback

Jernej Pangersic274d13b89f6d
diff --git a/tests/test_manage_install_missing_tools.py b/tests/test_manage_install_missing_tools.py
new file mode 100644
index 000000000..cde68a17b
--- /dev/null
+++ b/tests/test_manage_install_missing_tools.py
@@ -0,0 +1,62 @@
+"""install names a missing bash or gradlew and what to do about it, instead of a FileNotFoundError traceback."""
+import contextlib
+import io
+import os
+import sys
+import unittest
+from pathlib import Path
+from unittest import mock
+
+ROOT = Path(__file__).resolve().parent.parent
+sys.path.insert(0, str(ROOT / "tools"))
+import manage # noqa: E402
+
+
+class MissingToolTest(unittest.TestCase):
+ def install(self, name, error, platform=sys.platform, item=None):
+ out, err = io.StringIO(), io.StringIO()
+ patches = [
+ mock.patch.object(sys, "platform", platform),
+ mock.patch.object(manage.subprocess, "run", side_effect=error),
+ mock.patch.object(manage, "tv", side_effect=AssertionError("TV was asked")),
+ mock.patch.object(manage, "tv_python", side_effect=AssertionError("push was started")),
+ ]
+ if item:
+ patches.append(mock.patch.object(manage, "find", return_value=item))
+ with contextlib.ExitStack() as stack:
+ for p in patches:
+ stack.enter_context(p)
+ stack.enter_context(contextlib.redirect_stdout(out))
+ stack.enter_context(contextlib.redirect_stderr(err))
+ status = manage.main(["install", name])
+ return status, err.getvalue()
+
+ def test_missing_bash_is_named_with_what_to_install(self):
+ item = {"kind": "add-on", "id": "custom", "script": "install.sh"}
+ for platform, hint in (("win32", "Git for Windows"), ("linux", "package manager")):
+ with self.subTest(platform=platform):
+ status, err = self.install("custom", FileNotFoundError(2, "No such file or directory"),
+ platform, item)
+ self.assertEqual(status, 1, err)
+ self.assertIn("cannot start bash", err)
+ self.assertIn("No such file or directory", err)
+ self.assertIn("install.sh", err)
+ self.assertIn(hint, err)
+ self.assertIn("Nothing was built, pushed or installed.", err)
+ self.assertNotIn("Traceback", err)
+
+ def test_missing_gradlew_is_named_with_where_it_belongs(self):
+ folder = ROOT / "addons" / "jewish-calendar"
+ gradlew = str(folder / "gradlew.bat") if os.name == "nt" else "./gradlew"
+ for error in (FileNotFoundError(2, "No such file or directory"), PermissionError(13, "Permission denied")):
+ with self.subTest(error=type(error).__name__):
+ status, err = self.install("jewish-calendar", error)
+ self.assertEqual(status, 1, err)
+ self.assertIn(f"cannot start {gradlew}", err)
+ self.assertIn(error.strerror, err)
+ self.assertIn("addons/jewish-calendar", err)
+ self.assertIn("Nothing was built, pushed or installed.", err)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/manage.py b/tools/manage.py
index 77216caf2..851b98559 100644
--- a/tools/manage.py
+++ b/tools/manage.py
@@ -28,7 +28,8 @@ of your own that exists, and the push it ends with replaces the theme on the TV
wallpapers, so a mistyped path would leave a one-key theme behind.
On Windows, theme install and set use PowerShell (pwsh, or powershell when pwsh is not on PATH), without loading
-profiles or changing execution policy. Add-ons with their own shell installer still need Bash. A theme install
+profiles or changing execution policy. Add-ons with their own shell installer still need Bash; an install whose bash
+or Gradle wrapper cannot start says which and what to install, and exits 1 before anything is built or pushed. A theme install
takes only its name; script arguments belong to add-ons. If set saves the local file but the push fails, it
reports that separately: the TV may have received only part of the theme.
@@ -400,11 +401,23 @@ def push_theme(command):
return 1
+def cannot_start(program, error, fix):
+ """A build or installer that never started: nothing ran, so name the program, why, and what to do."""
+ sys.stderr.write(f"cannot start {program}: {reason(error)}. {fix} Nothing was built, pushed or installed.\n")
+ return 1
+
+
def install_addon(item, extra):
folder = ROOT / "addons" / item["id"]
if item["script"]:
# The creator's own script, as their README says to run it.
- return run(["bash", str(folder / item["script"])] + extra, ROOT)
+ try:
+ return run(["bash", str(folder / item["script"])] + extra, ROOT)
+ except OSError as e:
+ where = ("on Windows, install Git for Windows (it brings Git Bash) or WSL"
+ if sys.platform == "win32" else "install it with your package manager")
+ return cannot_start("bash", e, f"{item['id']}'s installer is {item['script']}, a Bash script: "
+ f"{where}, and put bash on PATH.")
if extra:
sys.stderr.write(f"{item['id']} has no custom installer, so install takes only its name, "
f"not {' '.join(extra)!r}: {USAGE_LINES['install']}. "
@@ -413,7 +426,12 @@ def install_addon(item, extra):
# No script: the steps addons/README.md gives for every add-on.
# Windows resolves a relative program against this process's directory, not cwd, so give the full path.
gradlew = str(folder / "gradlew.bat") if os.name == "nt" else "./gradlew"
- code = run([gradlew, "assembleRelease"], folder)
+ try:
+ code = run([gradlew, "assembleRelease"], folder)
+ except OSError as e:
+ return cannot_start(gradlew, e, f"{item['id']} builds with the Gradle wrapper in addons/{item['id']}/, "
+ f"so restore it from this checkout (git checkout -- addons/{item['id']}) "
+ f"and make sure it is executable.")
if code:
return code
apk = folder / "app" / "build" / "outputs" / "apk" / "release" / "app-release.apk"