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: stop match.py when list directories cannot be read
Sandiv Dathunarachchi3e33c72f7f47
diff --git a/tests/test_match.py b/tests/test_match.pyindex 8e810cc98..74ef44b8d 100644--- a/tests/test_match.py+++ b/tests/test_match.py@@ -7,7 +7,9 @@ file or examples folder that cannot be used ends the run at 2 with one line, noRun from the repository root: python3 -m unittest discover -s tests -v"""+import errnoimport io+import osfrom contextlib import redirect_stderr, redirect_stdoutfrom pathlib import Pathimport subprocess@@ -247,6 +249,26 @@ class MainTest(MatchCase):self.assertEqual("", out)self.assertIn("no */debloat*.txt", err)+ def test_an_unreadable_directory_refuses_partial_counts(self):+ self.add_list("a", "com.example.common\n")+ hidden = self.add_list("b", "com.example.hidden\n").parent+ packages = self.write("p.txt", "package:com.example.common\npackage:com.example.hidden\n")+ real_scandir = os.scandir+ for denied in (self.examples, hidden):+ with self.subTest(directory=denied.name):+ def scandir(path):+ if Path(path) == denied:+ raise PermissionError(errno.EACCES, "Permission denied", str(denied))+ return real_scandir(path)++ with mock.patch.object(os, "scandir", side_effect=scandir):+ code, out, err = self.run_main(str(packages), "--examples", str(self.examples))+ self.assertEqual(2, code, out + err)+ self.assertEqual("", out, "a partial tally must not be presented as complete")+ self.assertIn(str(denied), err)+ self.assertIn("Permission denied", err)+ self.assertNotIn("Traceback", err)+def test_the_default_examples_folder_is_this_checkout(self):self.assertEqual(ROOT / "examples", match.EXAMPLES)@@ -264,6 +286,29 @@ class CommandLineTest(MatchCase):self.assertIn("com.example.ads", result.stdout)self.assertNotIn("Traceback", result.stderr)+ def test_an_empty_examples_path_uses_the_current_directory(self):+ self.add_list("a", "com.example.ads # ads\n# com.example.store # updates\n")+ self.add_list("b", "com.example.ads # ads\ncom.example.store # updates\n")+ (self.examples / "a" / "debloat-extra.txt").write_text(+ "com.example.ads # alternate\ncom.example.extra # secondary\n", encoding="utf-8")+ packages = self.write("p.txt", "package:com.example.ads\npackage:com.example.store\n"+ "package:com.example.extra\npackage:com.example.none\n")+ previous = os.getcwd()+ try:+ os.chdir(self.examples)+ results = [self.run_script(str(packages), "--examples", root) for root in ("", ".")]+ finally:+ os.chdir(previous)+ for result in results:+ self.assertEqual(0, result.returncode, result.stderr)+ self.assertIn("4 packages, counted over 3 lists", result.stderr)+ self.assertEqual(results[0].stdout, results[1].stdout)+ rows = {line.split()[0]: line.split()[1:] for line in results[0].stdout.splitlines()[1:]}+ self.assertEqual({"com.example.ads": ["3", "0", "ads"],+ "com.example.extra": ["1", "0", "secondary"],+ "com.example.none": ["0", "0"],+ "com.example.store": ["1", "1", "updates"]}, rows)+def test_an_unreadable_file_exits_2_without_a_traceback(self):result = self.run_script(str(self.base / "gone.txt"), "--examples", str(self.examples))self.assertEqual(2, result.returncode, result.stdout + result.stderr)@@ -293,6 +338,23 @@ class CommandLineTest(MatchCase):self.assertNotIn("Traceback", result.stderr)self.assertEqual("", result.stdout)+ @unittest.skipUnless(os.name == "posix", "POSIX directory permissions are needed")+ def test_a_directory_without_read_permission_exits_2(self):+ if os.geteuid() == 0:+ self.skipTest("root can enumerate a directory without its read permission")+ self.add_list("a", "com.example.common\n")+ hidden = self.add_list("b", "com.example.hidden\n").parent+ packages = self.write("p.txt", "package:com.example.common\npackage:com.example.hidden\n")+ hidden.chmod(0)+ try:+ result = self.run_script(str(packages), "--examples", str(self.examples))+ finally:+ hidden.chmod(0o700)+ self.assertEqual(2, result.returncode, result.stdout + result.stderr)+ self.assertEqual("", result.stdout)+ self.assertIn(str(hidden), result.stderr)+ self.assertNotIn("Traceback", result.stderr)+def test_the_checkouts_own_examples_are_read_by_default(self):packages = self.write("p.txt", "package:com.example.unlikely.to.exist\n")result = self.run_script(str(packages))diff --git a/tools/match.py b/tools/match.pyindex 528e8678c..b4fba1073 100644--- a/tools/match.py+++ b/tools/match.py@@ -82,7 +82,19 @@ def tally(packages, examples):"""{package: (disabled, commented, most common note)} over every examples/*/debloat*.txt."""# The same discovery tests/test_examples.py and tests/test_stock_launcher_undo.py sweep with: a folder# may ship a second list beside debloat.txt, and tools/disable.sh takes it like the first.- lists = sorted(Path(examples).glob("*/debloat*.txt"))+ # glob() suppresses directory read errors, which would silently produce a partial tally.+ lists = []+ root = Path(examples)+ try:+ with os.scandir(root) as folders:+ for folder in folders:+ if folder.is_dir():+ with os.scandir(folder.path) as entries:+ lists.extend(Path(entry.path) for entry in entries+ if Path(entry.name).match("debloat*.txt"))+ except OSError as e:+ raise SystemExit(f"could not read {e.filename or examples} ({e.strerror or e}): no counts printed")+ lists.sort()if not lists:raise SystemExit(f"{examples}: no */debloat*.txt lists in it")wanted = set(packages)