Skip to content

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

docs: name the Python in every tool command the pages print

xbshenga4dd69bc07a3
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index 685440fd8..2aa224e2d 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -303,7 +303,7 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
answers when it is not a Live TV or input app. `tools/disable.sh` (`disable.ps1`) keeps any listed
app that query names and skips it with "the TV opens its HDMI/AV inputs and channels with it", so
put its line in a list of its own and apply that with `HANDLERS_ALLOW=1` (`$env:HANDLERS_ALLOW`):
- the rest of your list keeps the guard. Run `tools/check.py --fix` on that list with the same
+ the rest of your list keeps the guard. Run `tools/venv/bin/python -I tools/check.py --fix` on that list with the same
switch, or it leaves the app on and exits 1. `disable.ps1` reads the switch once and clears it
from the environment, so one `$env:HANDLERS_ALLOW=1` covers only that one run (#1845); `check.py
--fix` still reads it, and in PowerShell it stays set until the window is closed: run
diff --git a/docs/devices/skyworth-7t861-a23.md b/docs/devices/skyworth-7t861-a23.md
index a6883014e..1403423c1 100644
--- a/docs/devices/skyworth-7t861-a23.md
+++ b/docs/devices/skyworth-7t861-a23.md
@@ -83,9 +83,9 @@ cd launcher
Install the compiled launcher and the companion `coocaa-home-shim` (`com.ccos.tv.homepage`), which bridges Coocaa OS home dispatch to the CleanYourTV activity. The shim is not part of this repository: it is its own project, [coocaa-home-shim](https://github.com/VincentYe123/coocaa-home-shim), whose releases page carries the APK (or build it from source). `tools/tv.py` installs nothing on its own, so an APK goes up with `tools/b64push.py` and the TV's own `pm install` runs it, the way [`examples/skyworth-7s60-a5`](../../examples/skyworth-7s60-a5/README.md) does it on the same OS:
```bash
-TV_HOST=<tv ip> tools/b64push.py launcher/app/build/outputs/apk/release/app-release.apk /data/local/tmp/tvhome.apk
+TV_HOST=<tv ip> tools/venv/bin/python -I tools/b64push.py launcher/app/build/outputs/apk/release/app-release.apk /data/local/tmp/tvhome.apk
TV_HOST=<tv ip> tools/tv.py 'pm install -r /data/local/tmp/tvhome.apk; rm -f /data/local/tmp/tvhome.apk'
-TV_HOST=<tv ip> tools/b64push.py coocaa-home-shim.apk /data/local/tmp/shim.apk
+TV_HOST=<tv ip> tools/venv/bin/python -I tools/b64push.py coocaa-home-shim.apk /data/local/tmp/shim.apk
TV_HOST=<tv ip> tools/tv.py 'pm install -r /data/local/tmp/shim.apk; rm -f /data/local/tmp/shim.apk'
```
diff --git a/docs/devices/tcl-beyondtv4-uk-ar05.md b/docs/devices/tcl-beyondtv4-uk-ar05.md
index a52c006ea..62fe32779 100644
--- a/docs/devices/tcl-beyondtv4-uk-ar05.md
+++ b/docs/devices/tcl-beyondtv4-uk-ar05.md
@@ -30,7 +30,7 @@ The 15 `uk.co.freeview.*` packages and `tv.wuaki.apptv` were already disabled at
never-disable line. Those seven were re-enabled and restricted from running in the background instead:
```bash
- "$PY" -I tools/tv.py 'cmd appops set <package> RUN_ANY_IN_BACKGROUND ignore'
+ tools/venv/bin/python -I tools/tv.py 'cmd appops set <package> RUN_ANY_IN_BACKGROUND ignore'
# undo: cmd appops set <package> RUN_ANY_IN_BACKGROUND allow
```
@@ -41,7 +41,7 @@ The 15 `uk.co.freeview.*` packages and `tv.wuaki.apptv` were already disabled at
`cmd appops set ... RECORD_AUDIO ignore` stopped it. Revoking the permission did (28% to 0.4% of one core):
```bash
- "$PY" -I tools/tv.py 'pm revoke com.google.android.katniss android.permission.RECORD_AUDIO'
+ tools/venv/bin/python -I tools/tv.py 'pm revoke com.google.android.katniss android.permission.RECORD_AUDIO'
# undo: pm grant com.google.android.katniss android.permission.RECORD_AUDIO
```
diff --git a/docs/devices/xiaomi-mitv-mftr0-hyperos3.md b/docs/devices/xiaomi-mitv-mftr0-hyperos3.md
index 0116e2cbf..2d35cca43 100644
--- a/docs/devices/xiaomi-mitv-mftr0-hyperos3.md
+++ b/docs/devices/xiaomi-mitv-mftr0-hyperos3.md
@@ -38,8 +38,8 @@ third-party apps do not hold.
left the TV with `mCurrentFocus=null` and no usable window until PatchWall was re-enabled:
```bash
-"$PY" -I tools/tv.py 'pm enable --user 0 com.mitv.tvhome'
-"$PY" -I tools/tv.py 'cmd package set-home-activity --user 0 com.mitv.tvhome/.MainActivityUserMode'
+tools/venv/bin/python -I tools/tv.py 'pm enable --user 0 com.mitv.tvhome'
+tools/venv/bin/python -I tools/tv.py 'cmd package set-home-activity --user 0 com.mitv.tvhome/.MainActivityUserMode'
```
On HyperOS TV 2 and on other HyperOS TV 3 sets (MiTV-ASTR0, MiTV-MFFU0) the route that worked is the
diff --git a/docs/devices/xiaomi-mitv-mteq0-baymax.md b/docs/devices/xiaomi-mitv-mteq0-baymax.md
index 7a80138db..3ce8440b1 100644
--- a/docs/devices/xiaomi-mitv-mteq0-baymax.md
+++ b/docs/devices/xiaomi-mitv-mteq0-baymax.md
@@ -17,12 +17,12 @@ The same package-name HOME allowlist as the MiTV-AETP0
The opt-in identity worked here as documented for the AETP0:
```bash
-"$PY" -I tools/tv.py 'pm path com.ts.launcher' # must print nothing
+tools/venv/bin/python -I tools/tv.py 'pm path com.ts.launcher' # must print nothing
(cd launcher && ./gradlew assembleRelease -PlauncherApplicationId=com.ts.launcher)
-"$PY" -I tools/b64push.py launcher/app/build/outputs/apk/release/app-release.apk /data/local/tmp/ts.apk
-"$PY" -I tools/tv.py 'pm install -r /data/local/tmp/ts.apk'
-"$PY" -I tools/tv.py 'cmd package set-home-activity --user 0 com.ts.launcher/com.gathin.tvhome.MainActivity'
-"$PY" -I tools/tv.py 'cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME'
+tools/venv/bin/python -I tools/b64push.py launcher/app/build/outputs/apk/release/app-release.apk /data/local/tmp/ts.apk
+tools/venv/bin/python -I tools/tv.py 'pm install -r /data/local/tmp/ts.apk'
+tools/venv/bin/python -I tools/tv.py 'cmd package set-home-activity --user 0 com.ts.launcher/com.gathin.tvhome.MainActivity'
+tools/venv/bin/python -I tools/tv.py 'cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME'
```
`resolve-activity` answered `com.ts.launcher/com.gathin.tvhome.MainActivity`, also with
@@ -85,7 +85,7 @@ this set, so the driver runs with `CN` and never sees 5 GHz networks on channels
on channel 104 was invisible; Xiaomi routers pick CN-legal channels, so they work). Fix:
```bash
-"$PY" -I tools/tv.py 'settings put global service_region VN' # your country code
+tools/venv/bin/python -I tools/tv.py 'settings put global service_region VN' # your country code
# then Wi-Fi off and on (or reboot); dumpsys wifi shows mDriverCountryCode
```
diff --git a/docs/devices/xiaomi-mitv4-ansm0.md b/docs/devices/xiaomi-mitv4-ansm0.md
index 7a3db840c..f9927e041 100644
--- a/docs/devices/xiaomi-mitv4-ansm0.md
+++ b/docs/devices/xiaomi-mitv4-ansm0.md
@@ -104,7 +104,7 @@ production builds`. So the refusal belongs to the generation, not one build.
(and its installer allowlist) stays enabled:
```bash
- "$PY" -I tools/tv.py 'appops set com.xiaomi.mitv.tvpush.tvpushservice POST_NOTIFICATION deny'
+ tools/venv/bin/python -I tools/tv.py 'appops set com.xiaomi.mitv.tvpush.tvpushservice POST_NOTIFICATION deny'
# check: appops get com.xiaomi.mitv.tvpush.tvpushservice undo: ... POST_NOTIFICATION allow
```
diff --git a/docs/workflows/perf-ab.md b/docs/workflows/perf-ab.md
index 6ba6bad0e..393b0b797 100644
--- a/docs/workflows/perf-ab.md
+++ b/docs/workflows/perf-ab.md
@@ -10,10 +10,11 @@ whose check fails, then follows the full method
1. **Before you change anything,** install the base build with `launcher/build-and-install.sh` and run:
```bash
- TV_HOST=<tv ip> tools/venv/bin/python tools/bench.py --out-dir work/bench-before
+ TV_HOST=<tv ip> tools/venv/bin/python -I tools/bench.py --out-dir work/bench-before
```
-2. Make the change, install your build the same way, and run `tools/bench.py --out-dir work/bench-after`.
+2. Make the change, install your build the same way, and run
+ `tools/venv/bin/python -I tools/bench.py --out-dir work/bench-after`.
3. Compare the two `result.json` files. Leave out any field that is `null` in both:
| Field | Fails when the after value is |
diff --git a/docs/workflows/press.md b/docs/workflows/press.md
index 7cfe240ca..f9536468f 100644
--- a/docs/workflows/press.md
+++ b/docs/workflows/press.md
@@ -10,8 +10,8 @@
`tools/readme_featured.py`. Redrawing `docs/featured.png` and `docs/card.jpg` needs Pillow, which the
performance requirements install:
`tools/venv/bin/pip install -r tools/requirements-perf.txt`, then
- `tools/readme_featured.py Fredoka.ttf docs/featured.png` and
- `tools/readme_card.py Fredoka.ttf docs/card.jpg`. Fredoka is the variable TTF from Google Fonts and its
+ `tools/venv/bin/python -I tools/readme_featured.py Fredoka.ttf docs/featured.png` and
+ `tools/venv/bin/python -I tools/readme_card.py Fredoka.ttf docs/card.jpg`. Fredoka is the variable TTF from Google Fonts and its
file is not in the repo, so that first argument is the path of the copy you downloaded; each script says
so when the path is wrong. If you cannot redraw them, say so in the PR.
diff --git a/examples/anker-nebula-mars-3-air/README.md b/examples/anker-nebula-mars-3-air/README.md
index e41d232db..d5010a475 100644
--- a/examples/anker-nebula-mars-3-air/README.md
+++ b/examples/anker-nebula-mars-3-air/README.md
@@ -12,7 +12,7 @@ address (Settings > Network on the projector).
| | |
|---|---|
| **Disabled** (15 packages, never uninstalled) | Google feedback and consent, Privacy Sandbox ad services, federated learning, on-device personalisation, partner attribution, both retail-demo apps, the AirPlay receiver, Spotify, Max, the Google TV movies app, the setup wizard, the stock Google TV home and its partner rows. The full list with reasons is in [`debloat.txt`](debloat.txt) |
-| **Back after every boot** | The firmware turns `com.google.android.katniss` (Assistant) back on at each boot. The owner keeps it on, so the mic button works. To keep it off instead, uncomment `com.google.android.katniss` and `com.google.android.tv.assistant` in [`debloat.txt`](debloat.txt) and run `tools/disable.sh` on it again, which records them first so [Undo everything](#undo-everything) brings them back; after each boot, `tools/check.py --fix` re-disables what came back |
+| **Back after every boot** | The firmware turns `com.google.android.katniss` (Assistant) back on at each boot. The owner keeps it on, so the mic button works. To keep it off instead, uncomment `com.google.android.katniss` and `com.google.android.tv.assistant` in [`debloat.txt`](debloat.txt) and run `tools/disable.sh` on it again, which records them first so [Undo everything](#undo-everything) brings them back; after each boot, `tools/venv/bin/python -I tools/check.py --fix` re-disables what came back |
| **Kept** | Chromecast built-in, Prime Video, YouTube + YouTube Music, Play Games, Nebula Play, Nebula Life, Netflix (see quirks), Google's Ambient Mode screensaver, and everything the projector needs: focus / keystone / battery settings, remote, Bluetooth pairing, HDMI inputs, USB media player, Dolby audio, keyboard, Play Store, firmware-update UI |
| **Screensaver** | Google Ambient Mode: disabled at first with the screensaver switched to the built-in "Colors", then re-enabled on request and made the active screensaver again |
| **Home** | `com.gathin.tvhome`, configured by [`config.json`](config.json): six-column dock (YouTube, Twitch, Netflix, Prime Video, Vodafone TV, VLC), the app library and the gear menu |
diff --git a/examples/tcl-65c8l-google-tv/README.md b/examples/tcl-65c8l-google-tv/README.md
index 61d2b3eca..773d751a5 100644
--- a/examples/tcl-65c8l-google-tv/README.md
+++ b/examples/tcl-65c8l-google-tv/README.md
@@ -135,7 +135,7 @@ Private DNS to an ad-blocking resolver works on this TV (it does not block YouTu
## After a firmware update
```
-TV_HOST=<tv ip> tools/check.py examples/tcl-65c8l-google-tv/debloat.txt com.gathin.tvhome
+TV_HOST=<tv ip> tools/venv/bin/python -I tools/check.py examples/tcl-65c8l-google-tv/debloat.txt com.gathin.tvhome
```
Add `--fix` after `check.py` to re-disable whatever came back and put the launcher back on Home.
diff --git a/tests/test_card_font_argument.py b/tests/test_card_font_argument.py
index 360744d52..c4f2df168 100644
--- a/tests/test_card_font_argument.py
+++ b/tests/test_card_font_argument.py
@@ -272,7 +272,9 @@ class GenTablesFontTest(unittest.TestCase):
"handing --font changed what --check says about the tables")
-COMMAND = re.compile(r"`(tools/readme_[\w]+\.py [^`]*)`") # a command: the script and what it is given
+# A command: what runs the script, then the script and what it is given.
+SCRIPT = re.compile(r"tools/readme_[\w]+\.py")
+COMMAND = re.compile(r"`([^`]*" + SCRIPT.pattern + r" [^`]*)`")
class PressRecipeShapeTest(unittest.TestCase):
@@ -282,7 +284,7 @@ class PressRecipeShapeTest(unittest.TestCase):
return COMMAND.findall(PRESS.read_text(encoding="utf-8"))
def test_the_page_prints_the_redraw_commands(self):
- named = {cmd.split()[0] for cmd in self.commands()}
+ named = {SCRIPT.findall(cmd)[0] for cmd in self.commands()}
self.assertEqual({"tools/readme_featured.py", "tools/readme_card.py"}, named,
"press.md no longer prints both redraw commands, so this check would prove nothing")
@@ -290,10 +292,14 @@ class PressRecipeShapeTest(unittest.TestCase):
for cmd in self.commands():
with self.subTest(command=cmd):
parts = cmd.split()
- self.assertEqual(3, len(parts), f"press.md prints '{cmd}', which is not <script> <font> <picture>")
- self.assertTrue((ROOT / parts[0]).is_file(), f"press.md names {parts[0]}, which is not in the repo")
- self.assertTrue((ROOT / parts[2]).is_file(),
- f"press.md writes {parts[2]}, which the repo does not ship")
+ at = parts.index(SCRIPT.findall(cmd)[0])
+ arguments = parts[at + 1:]
+ self.assertEqual(2, len(arguments),
+ f"press.md prints '{cmd}', which is not <script> <font> <picture>")
+ self.assertTrue((ROOT / parts[at]).is_file(),
+ f"press.md names {parts[at]}, which is not in the repo")
+ self.assertTrue((ROOT / arguments[1]).is_file(),
+ f"press.md writes {arguments[1]}, which the repo does not ship")
def test_the_page_says_the_font_is_not_in_the_repo(self):
# The one fact a reader cannot get from the commands themselves: the font path is theirs to supply.
diff --git a/tests/test_documented_tool_commands.py b/tests/test_documented_tool_commands.py
new file mode 100644
index 000000000..eaff6fbe0
--- /dev/null
+++ b/tests/test_documented_tool_commands.py
@@ -0,0 +1,239 @@
+"""Every `tools/<x>.py` command on a page a reader follows names the Python that runs it.
+
+A clone cannot run the scripts bare: `git ls-files -s tools` has all of them as 100644 except
+`tools/tv.py`, which is 100755 with the venv restart `tests/test_tv_runs_as_documented.py` exists for.
+So a page that writes `tools/check.py --fix` hands the reader this:
+
+ $ tools/check.py --fix list.txt
+ bash: tools/check.py: Permission denied (exit 126)
+
+and the card scripts, made executable instead, would be started by the first python3 on PATH rather
+than the venv docs/workflows/press.md has just installed Pillow into. A page that writes `"$PY" -I
+tools/tv.py ...` without ever setting PY is worse: the shell runs `"" -I tools/tv.py ...`, which is
+`bash: : command not found`, so nothing reaches the TV at all.
+
+Ten commands on seven pages gave a 100644 script bare (docs/TROUBLESHOOTING.md, both pages under
+docs/workflows/, themes/README.md twice, examples/anker-nebula-mars-3-air/README.md,
+docs/devices/skyworth-7t861-a23.md twice and examples/tcl-65c8l-google-tv/README.md), and eleven on
+four device notes ran on a `$PY` those pages never set (tcl-beyondtv4-uk-ar05, xiaomi-mitv-mftr0-hyperos3,
+xiaomi-mitv-mteq0-baymax, xiaomi-mitv4-ansm0). All of them name `tools/venv/bin/python -I tools/<x>.py`
+now, the form README.md's Tools table and docs/TROUBLESHOOTING.md's own
+`tools/venv/bin/python -I tools/check.py <list>` already used; a page may still set `PY=` to the venv's
+Python and use `"$PY"` (examples/skyworth-7s60-a5 and docs/devices/xiaomi-mitv-aetp0-dofus do).
+
+The sweep reads the pages a reader follows - README*.md, docs/, themes/, examples/, addons/ - for a code
+span or a code-block line that runs a tool with an argument, and judges what stands in front of the
+script: a Python (its path or a variable the page sets to one), or the script's own 100755 mode. A span
+that is only the path (`tools/gen_tables.py`, which a maintainer runs after merging) is a mention, not a
+command. PROMPT.md and .github/maintainer/MAINTAINER.md run `tools/relay.py` and `tools/gen_tables.py`
+bare too and are the maintainer's files (AGENTS.md, "Safety rules ... CI and workflows"), so they are not
+in the sweep.
+
+Needs no TV and no interpreter: the modes are git's and the pages are read.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+from pathlib import Path
+import glob
+import re
+import subprocess
+import unittest
+
+ROOT = Path(__file__).resolve().parents[1]
+
+# The pages a reader follows: the READMEs, the notes and workflows under docs/, and every folder page.
+PAGE_GLOBS = ("README*.md", "docs/**/*.md", "themes/**/*.md", "examples/**/*.md", "addons/**/*.md")
+
+SPAN = re.compile(r"`([^`\n]+)`")
+# The script a command runs, in the forms the pages use: tools/x.py, ./tools/x.py, tools\x.py.
+SCRIPT = re.compile(r"(?:\./)?tools[/\\]([A-Za-z0-9_.-]+)\.py")
+# A shell assignment of an interpreter, and a variable used as one: PY=tools/venv/bin/python, "$PY" -I ...
+ASSIGNMENT = re.compile(r"\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(\S+)")
+VARIABLE = re.compile(r"\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))")
+
+
+def tool_modes(root=ROOT):
+ """git's mode for every file under tools/, as {"tools/check.py": "100644", ...}; None without git."""
+ try:
+ run = subprocess.run(["git", "ls-files", "-s", "--", "tools"], cwd=str(root),
+ capture_output=True, text=True)
+ except (FileNotFoundError, OSError):
+ return None
+ if run.returncode != 0:
+ return None
+ modes = {}
+ for line in run.stdout.splitlines():
+ meta, path = line.split("\t", 1)
+ modes[path] = meta.split()[0]
+ return modes or None
+
+
+def code_commands(text):
+ """(line number, candidate) for each code span and code-block line in PAGE."""
+ found = []
+ fenced = False
+ for number, line in enumerate(text.splitlines(), 1):
+ if line.strip().startswith("```"):
+ fenced = not fenced
+ continue
+ if fenced:
+ found.append((number, line.strip()))
+ else:
+ found.extend((number, span) for span in SPAN.findall(line))
+ return found
+
+
+def judged(text):
+ """(line number, command, script, where the script starts) for each tool command the page gives."""
+ found = []
+ for number, candidate in code_commands(text):
+ command = candidate.strip()
+ match = SCRIPT.search(command)
+ if not match:
+ continue
+ if not command[match.end():][:1].isspace():
+ continue # the path alone, or a path with a comment after it: a mention, not a command
+ found.append((number, command, "tools/" + match.group(1) + ".py", match.start()))
+ return found
+
+
+def assignments(text):
+ """The shell variables PAGE sets, as {"PY": "tools/venv/bin/python", ...}."""
+ found = {}
+ for line in text.splitlines():
+ match = ASSIGNMENT.match(line)
+ if match:
+ found[match.group(1)] = match.group(2)
+ return found
+
+
+def refusals(text, modes, page=""):
+ """Why the commands PAGE gives would not run as typed; [] when every one of them would."""
+ variables = assignments(text)
+ problems = []
+ for number, command, script, start in judged(text):
+ prefix = command[:start]
+ where = f"{page}:{number}" if page else f"line {number}"
+ if "python" in prefix.lower():
+ continue # `tools/venv/bin/python -I tools/x.py ...`
+ named = [one or two for one, two in VARIABLE.findall(prefix)]
+ if named:
+ # `"$PY" -I tools/x.py ...`: fine when the page sets PY to an interpreter.
+ unset = [name for name in named if name not in variables]
+ if unset:
+ problems.append(f"{where}: `{command}` runs on ${unset[0]}, which the page never sets: "
+ f"the shell answers `command not found`, so nothing reaches the TV. Set "
+ f"{unset[0]}=tools/venv/bin/python, or name the venv's Python in the command")
+ elif not any("python" in variables[name] for name in named):
+ problems.append(f"{where}: `{command}` runs on ${named[0]}, which the page sets to "
+ f"{variables[named[0]]}, not a Python")
+ continue
+ mode = modes.get(script)
+ if mode == "100755":
+ continue # tv.py starts again under tools/venv itself
+ if mode is None:
+ problems.append(f"{where}: `{command}` names {script}, which tools/ does not hold")
+ else:
+ problems.append(f"{where}: `{command}` starts {script}, which git has as {mode}: "
+ f"the shell answers `Permission denied` (exit 126). Name the venv's Python, "
+ f"e.g. tools/venv/bin/python -I {script} ...")
+ return problems
+
+
+def pages(root=ROOT):
+ found = []
+ for pattern in PAGE_GLOBS:
+ found.extend(glob.glob(str(root / pattern), recursive=True))
+ return sorted(set(found))
+
+
+class DocumentedCommandsTest(unittest.TestCase):
+ """Every tool command on the pages a reader follows runs as typed, in a clone."""
+
+ @classmethod
+ def setUpClass(cls):
+ cls.modes = tool_modes()
+ if cls.modes is None:
+ raise unittest.SkipTest("git is not installed, so the modes a clone gets cannot be read")
+
+ def test_no_page_gives_a_command_a_clone_cannot_run(self):
+ problems, read = [], 0
+ for path in pages():
+ read += 1
+ text = Path(path).read_text(encoding="utf-8", errors="replace")
+ problems.extend(refusals(text, self.modes, page=str(Path(path).relative_to(ROOT))))
+ self.assertEqual([], problems, "\n".join(problems))
+ # A walk that read nothing would pass; the tree has 200 pages under these globs.
+ self.assertGreaterEqual(read, 200, "the sweep read %d pages" % read)
+
+ def test_the_sweep_reads_the_tool_commands_it_was_written_for(self):
+ # The rule only has teeth if it sees the commands: count the ones it reads, prefix included.
+ seen = []
+ for path in pages():
+ for number, command, script, _ in judged(Path(path).read_text(encoding="utf-8", errors="replace")):
+ seen.append("%s:%d %s" % (Path(path).relative_to(ROOT), number, command))
+ self.assertGreaterEqual(len(seen), 40, "the sweep read %d tool commands:\n%s" % (len(seen), "\n".join(seen)))
+
+
+class ReaderTest(unittest.TestCase):
+ """The rule itself, on pages written here: a command is judged, a mention is not."""
+
+ MODES = {"tools/check.py": "100644", "tools/readme_card.py": "100644", "tools/tv.py": "100755"}
+
+ def test_a_bare_command_is_refused(self):
+ problems = refusals("Run `tools/check.py --fix list.txt` on that list.", self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+ self.assertIn("page.md:1", problems[0])
+ self.assertIn("tools/check.py", problems[0])
+ self.assertIn("100644", problems[0])
+ self.assertIn("Permission denied", problems[0])
+
+ def test_the_venv_python_in_front_is_what_the_rule_wants(self):
+ for text in ("Run `tools/venv/bin/python -I tools/check.py --fix list.txt` on that list.",
+ " tools/venv/bin/python -I tools/check.py --fix list.txt\n",
+ "`TV_HOST=192.168.1.50 tools/venv/bin/python -I tools/check.py`"):
+ self.assertEqual([], refusals(text, self.MODES, "page.md"), text)
+
+ def test_an_environment_prefix_does_not_make_a_bare_command_run(self):
+ problems = refusals("`TV_HOST=192.168.1.50 tools/check.py list.txt`", self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+
+ def test_a_command_inside_a_code_block_is_judged_too(self):
+ problems = refusals(" ```bash\n TV_HOST=<tv ip> tools/readme_card.py font.ttf card.jpg\n ```",
+ self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+ self.assertIn("page.md:2", problems[0])
+
+ def test_an_executable_tool_may_be_given_bare(self):
+ self.assertEqual([], refusals("`tools/tv.py --probe` prints them.", self.MODES, "page.md"))
+
+ def test_a_mention_without_an_argument_is_not_a_command(self):
+ for text in ("`tools/gen_tables.py`, which a maintainer runs after merging.",
+ "| [`tools/readme_card.py`](tools/readme_card.py) | Draws the card. |"):
+ self.assertEqual([], refusals(text, self.MODES, "page.md"), text)
+
+ def test_a_script_the_tree_does_not_hold_is_named(self):
+ problems = refusals("`tools/no_such_tool.py --flag`", self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+ self.assertIn("which tools/ does not hold", problems[0])
+
+ def test_a_variable_the_page_sets_to_a_python_is_accepted(self):
+ text = ("```bash\nPY=tools/venv/bin/python\n"
+ '"$PY" -I tools/check.py --fix list.txt\n```\n')
+ self.assertEqual([], refusals(text, self.MODES, "page.md"))
+
+ def test_a_variable_the_page_never_sets_is_named(self):
+ problems = refusals('```bash\n"$PY" -I tools/check.py --fix list.txt\n```\n', self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+ self.assertIn("$PY, which the page never sets", problems[0])
+ self.assertIn("command not found", problems[0])
+
+ def test_a_variable_set_to_something_else_is_named(self):
+ text = '```bash\nPY=/bin/true\n"$PY" -I tools/check.py --fix list.txt\n```\n'
+ problems = refusals(text, self.MODES, "page.md")
+ self.assertEqual(1, len(problems), problems)
+ self.assertIn("which the page sets to /bin/true, not a Python", problems[0])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_wrong_handler_note.py b/tests/test_wrong_handler_note.py
index e92728519..1f6ca725e 100644
--- a/tests/test_wrong_handler_note.py
+++ b/tests/test_wrong_handler_note.py
@@ -64,7 +64,7 @@ class WrongHandlerNoteTest(unittest.TestCase):
self.assertIn("a list of its own", self.note)
def test_the_bullet_says_check_fix_needs_it_too(self):
- self.assertIn("`tools/check.py --fix`", self.note)
+ self.assertIn("`tools/venv/bin/python -I tools/check.py --fix`", self.note)
def test_the_quoted_message_is_what_the_scripts_print(self):
quoted = re.findall(r'"(the TV opens [^"]+)"', self.note)
diff --git a/themes/README.md b/themes/README.md
index cca0b0fe9..9fe471a6e 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -12,7 +12,7 @@ TV_HOST=192.168.1.50 tools/theme.sh --reset # back to the built-i
powershell -ExecutionPolicy Bypass -File tools\theme.ps1 -TvHost 192.168.1.50 themes\aurora
```
-`tools/manage.py list themes` and `list switches` list them from this file, `show <name>` gives one with its
+`tools/venv/bin/python -I tools/manage.py list themes` and `list switches` list them from this file, `show <name>` gives one with its
screenshot, and `manage.py set <switch> <value> --theme <your folder>` writes a key into a theme folder of your own
and pushes it with `theme.sh`. The folder has to be outside this checkout: one under `themes/` or `examples/` is
refused (copy a theme first), and a `config.json` it cannot read is named before anything is written or pushed.
@@ -130,7 +130,7 @@ A new key needs one there in the same pull request.
| `home_long_press_home` | bool | Every Home press opens Home, a held one too. Android turns a Home press held past 400 ms into ALL_APPS for the system-image launcher, which nothing answers once the stock launcher is disabled, so a firm press on a slow remote did nothing (Philips TPM191E, Android 12, where `long_press_timeout` does not move that limit). Needs `key_filter` (`HOME_KEY_SERVICE=1`), so held keys such as Volume Up/Down stop repeating, confirmed on that Philips; single presses still step. Off by default |
| `power_on_home_always` | bool | Home at every power-on, whatever the TV put in front: the last HDMI input, Live TV or an app, for TVs that come back to the last source (Philips). Unlike `power_on_home`, it does not wait for a window to show: the Home screen comes up about a second after the screen turns on (`HOME_KEY_SERVICE=1`). A key pressed before that wins. Ignored with `boot_to_live_tv`, or with an Open on start app. Off by default |
| `inputs_connected_only` | bool | The Inputs list shows only HDMI ports and CEC devices that report connected; empty ports, the AV jacks and devices asleep in standby fold behind a "More inputs" row that expands them. Some TVs (TCL) report an empty HDMI port as connected-standby, the same state a sleeping device has, so a device in standby is folded too. An HDMI row whose state the TV cannot be trusted with stays (`false` by default) |
-| `race_calendar` | list of races | F1 race-weekend mode: from 12 hours before a weekend's first session until 4 hours after the race starts, a panel under the clock shows the next session with a countdown (or the live one) and the weekend's session times in the TV's time zone. Write it with `tools/race_calendar.py <theme folder>`, which fetches the season from the free Jolpica API; the launcher itself never goes online |
+| `race_calendar` | list of races | F1 race-weekend mode: from 12 hours before a weekend's first session until 4 hours after the race starts, a panel under the clock shows the next session with a countdown (or the live one) and the weekend's session times in the TV's time zone. Write it with `tools/venv/bin/python -I tools/race_calendar.py <theme folder>`, which fetches the season from the free Jolpica API; the launcher itself never goes online |
| `home_idle_clock_minutes` | 0 to 1440 | Minutes Home may sit untouched before it shows the clock screensaver (a thin clock and date drifting over a slow glow, as the system "Clock" screensaver does). Any key returns to Home. It starts only from Home, never over Live TV or an app; 0 is off (default) |
| `clock_wallpaper` | bool | The clock screensaver over Home's wallpaper instead of black with a coloured glow; the clock still moves every minute (`false` by default) |
| `clock_wallpaper_dim` | 0 to 90 | How dark that wallpaper is behind the clock, in percent (50 by default) |