Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
tools: tv.py refuses a --screenshot destination whose last word is . or ..
xbsheng93e980e307c9
diff --git a/tests/test_tv_screenshot_target.py b/tests/test_tv_screenshot_target.pyindex 007e71eb5..c1fea4c6b 100644--- a/tests/test_tv_screenshot_target.py+++ b/tests/test_tv_screenshot_target.py@@ -24,6 +24,12 @@ Two shapes of a destination were left after that: a word that is only whitespaceafter which that folder was made and the pull wrote to a folder name. Both are refused now, by thesame judge, before the TV is opened; each has a test below.+A last word of `.` or `..` was the third shape of the same kind (`--screenshot newshots/.`, and+`newshots/..`): the folder it names is not there, so isdir() answers no and abspath() drops the tail the+way it drops a separator, and the run went on to `screencap` before the pull's open() failed on a path+with no such folder - exit 1, the code kept for a capture that came back empty. Refused with the other+two, and a `.` in the middle of a path (`shots/./01-home.png`) is still one file name.+Run from the repository root: python3 -m unittest discover -s tests -v"""import os@@ -169,6 +175,31 @@ class ScreenshotTargetTest(unittest.TestCase):self.assertRefused(["--screenshot", target], "ends with a separator", "01-home.png","Nothing was captured.")+ def test_a_destination_that_ends_in_one_dot_is_refused(self):+ # `--screenshot newshots/.` names that folder itself, and the folder is not there yet: isdir()+ # answers no, and the separator check sees a dot rather than a separator. The folder was then+ # made and the pull wrote to a name that is a folder, after `screencap` had run on the TV.+ work = self.work()+ target = os.path.join(str(work), "newshots", ".")+ self.assertRefused(["--screenshot", target], "names a folder rather than a file",+ "01-home.png", "Nothing was captured.")++ def test_a_destination_that_ends_in_two_dots_is_refused(self):+ # The same shape one level up: `--screenshot newshots/..` names the folder that holds `newshots`,+ # which an owner reading the name does not expect, and the pull cannot write it as a file.+ work = self.work()+ target = os.path.join(str(work), "newshots", "..")+ self.assertRefused(["--screenshot", target], "names a folder rather than a file",+ "01-home.png", "Nothing was captured.")++ def test_a_dot_in_the_middle_of_the_path_is_still_a_file(self):+ # `shots/./01-home.png` is one file name with a pointless hop in it; it must keep working.+ work = self.work()+ local = Path(os.path.join(str(work), "shots", ".", "01-home.png"))+ status, out, err, opened, sent = self.run_tv(["--screenshot", str(local), ], work)+ self.assertEqual(0, status, err)+ self.assertTrue((work / "shots" / "01-home.png").is_file(), err)+def test_a_blank_destination_is_refused(self):# `--screenshot "$SHOT"` with SHOT holding a space: accepted, the pull wrote a file named " ",# and the run reported a screenshot at a path that is not the one the reader asked for.diff --git a/tools/tv.py b/tools/tv.pyindex f7a8507f6..e92356410 100755--- a/tools/tv.py+++ b/tools/tv.py@@ -508,12 +508,15 @@ def screenshot_target(local):have been judged this way since #2039; this is the flag the pages hand out most.A folder that is not there is still made rather than refused: that is the one shape the command is- expected to fix for itself. Two words are not a file name and are refused here: one that is only+ expected to fix for itself. Three words are not a file name and are refused here: one that is onlywhitespace, which `--screenshot "$SHOT"` sends when SHOT holds a space (the pull wrote a file named" " and the run printed `screenshot (N bytes)`, exit 0, while the path the reader meant was- never made), and one that ends with a separator while that folder is not there yet - the check below+ never made), one that ends with a separator while that folder is not there yet - the check belowonly answers a folder that exists, and os.path.abspath() drops the separator, so the folder was made- and `screencap` ran on the TV before the pull wrote to a name that is a folder.+ and `screencap` ran on the TV before the pull wrote to a name that is a folder - and one whose last+ word is `.` or `..`, which names the folder itself or its parent (`--screenshot newshots/.`): the+ folder is not there, isdir() answers no and abspath() drops the tail as well, so the pull's open() of+ the destination was the first thing to fail."""if not local:usage_error("--screenshot needs the file to save to")@@ -527,6 +530,14 @@ def screenshot_target(local):path_error(f"{local} ends with a separator, so it names a folder, and --screenshot saves the PNG "f"to a file: give a file name such as {os.path.join(local, '01-home.png')}. "f"Nothing was captured.")+ if os.path.basename(local) in (".", ".."):+ # `--screenshot newshots/.` names that folder itself (and `newshots/..` its parent), and the folder+ # is not there yet: os.path.isdir() answers no, the check above sees a dot rather than a separator,+ # and os.path.abspath() drops the tail, so the parent was made, `screencap` ran on the TV, and the+ # pull's open() of the destination - a path with no such folder - was the first thing to fail.+ path_error(f"{local} ends in {os.path.basename(local)!r}, which names a folder rather than a file, "+ f"and --screenshot saves the PNG to a file: give the file a name such as "+ f"{os.path.join(local, '01-home.png')}. Nothing was captured.")folder = os.path.dirname(os.path.abspath(local))if os.path.exists(folder) and not os.path.isdir(folder):path_error(f"{folder} is a file, not a folder: --screenshot cannot save {local} inside it. "