Files
DroidDeck/tools/desktop-kde/removal-manifests.py
T
MaxsTechReview c5577478ca chore: remove source comments and unused code, translate every missing string (#1965)
* chore(i18n): translate every missing string in all locales

Adds the 87 strings the bottom-screen Dashboard and in-game stats pages
introduced to all 32 locales, plus the 51 older settings strings Japanese
and the 50 Chinese locales were still missing. Every locale now has all
3456 translatable strings with the same placeholders as English.

Also translates 36 entries that were still English where the language
does not use the English word, and makes es-419 touch_app_id use the same
%1$s placeholder as English.

* chore(patches): drop comments from the lines downstream patches add

Removes comment lines and trailing comments from lines our patches add,
with hunk headers recounted. Lines that a later patch uses as context
and the upstream backport 0123 are left as they are.

The gamescope, FEX, proot and xodus series still apply to their pinned
sources, and the patched trees differ only in those comments.
test_hud_frames now finds the HUD writer by its first declaration.

* docs: credit Greenlight, Better xCloud, viture-v2, GameNative and DiRTTelemetryErrorFix

These were credited only in source headers and NOTICE files.

* chore: remove source comments and unused functions

Removes explanatory comments from first-party Kotlin, Java, C, C++,
Rust, TypeScript, Python, shell, Gradle, CMake and workflow files.
License and attribution headers stay, and vendored third-party trees,
generated files and license files are untouched. A shellcheck directive
is kept, and udevmon's fallthrough comments became fallthrough attributes.

Syntax trees and token streams match the previous sources apart from the
comments and Python docstrings. Module docstrings that argparse prints
are kept, and device-smoke.sh prints the same --help text from a heredoc.

Also removes 37 functions and 4 fields that nothing referenced.

* chore: remove comments from the Syncthing integration and the latest main sources

* docs: credit Syncthing and the syncthing-android fork

* chore(i18n): translate the Syncthing strings in all locales

The 107 strings the Syncthing integration added are now in all 32 locales.
sync_web_path_locked names the Syncthing tab by its label.

* docs: credit @xXJSONDeruloXx for the HUD metric readers

The CPU, GPU load, thermal and battery readers come from their
PerformanceHudView pull requests #777, #877, #991, #1406 and #1573.
The FusionHUD credit line is unchanged.

* docs: credit the HUD metric readers to @xXJSONDeruloXx's work
2026-11-01 16:27:27 -05:00

138 lines
6.9 KiB
Python

#!/usr/bin/env python3
import gzip
import hashlib
import json
import pathlib
import subprocess
import sys
import tarfile
PINS = [
('lxqt-r1', 'c2bb860b3b1688287451e2495be5db313ec07f8c8af501dfac2768a9f417bc86'),
('desktop-kde-r1', '55747e75d0ec055ab7ea1e92a757f3be227cc3205bb9101f5b53cadef6318579'),
('desktop-kde-r2', '9ba832677b498654136c69d8c8330434d17e4d53cd099acac9bde3ba429b35bf'),
('emulators-r1', 'a1f4806a9663d28f424b4cab1277e0ede80a92e69de5bc063cdc8b45af220164'),
]
SHARED_SEEDS = {'xorg-xwayland', 'qt6-wayland', 'wayland-utils', 'noto-fonts', 'noto-fonts-emoji', 'xdg-utils'}
def sha(file):
with open(file, 'rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
def inventory(archive, digest):
if sha(archive) != digest:
raise ValueError(f'{archive}: checksum differs from the published pin')
entries = {}
process = subprocess.Popen(['zstd', '-dc', str(archive)], stdout=subprocess.PIPE)
try:
with tarfile.open(fileobj=process.stdout, mode='r|') as tar:
for entry in tar:
path = entry.name.removeprefix('./').rstrip('/')
assert not any(c in path for c in '\t\n\r') and '..' not in path.split('/') and not path.startswith('/')
if entry.isfile():
entries[path] = f'F\t{entry.size}\t{hashlib.file_digest(tar.extractfile(entry), "sha256").hexdigest()}\t{path}'
elif entry.issym():
assert not any(c in entry.linkname for c in '\t\n\r')
entries[path] = f'L\t0\t{entry.linkname}\t{path}'
elif entry.islnk():
target = entry.linkname.removeprefix('./')
record = entries[target].split('\t', 3)
entries[path] = '\t'.join(record[:3] + [path])
finally:
process.stdout.close()
if process.wait() != 0:
raise ValueError('zstd failed')
return entries
def write(out, name, records):
with open(out / name, 'wb') as stream:
with gzip.GzipFile(fileobj=stream, mode='wb', mtime=0, filename='') as gz:
gz.write(('\n'.join(sorted(set(records))) + '\n').encode())
def application_paths(here, cache):
seeds = {line.strip() for line in (here / 'seeds.txt').read_text().splitlines() if line.strip() and not line.startswith('#')} - SHARED_SEEDS
packages = dict(line.split() for line in (cache / 'desktop-kde.packages.txt').read_text().splitlines())
selected = set()
found = set()
for filename, digest in packages.items():
package = filename.rsplit('-', 3)[0]
if package not in seeds:
continue
archive = cache / filename
if sha(archive) != digest:
raise ValueError(f'{filename}: source package checksum mismatch')
with tarfile.open(archive) as tar:
selected.update(e.name.removeprefix('./').rstrip('/') for e in tar if not e.isdir() and not e.name.removeprefix('./').startswith('.'))
found.add(package)
assert found == seeds, f'missing desktop packages: {seeds - found}'
selected.update(str(p.relative_to(here / 'overlay')) for p in (here / 'overlay').rglob('*') if p.is_file() or p.is_symlink())
return selected, packages, seeds
def add(archive, tag, digest, cache, out):
here = pathlib.Path(__file__).resolve().parent
selected, packages, seeds = application_paths(here, cache)
inv = inventory(archive, digest)
generated = ('usr/share/droiddeck/pacman/', 'usr/lib/droiddeck/')
remove = gzip.decompress((out / 'kde-remove.tsv.gzip').read_bytes()).decode().splitlines()
keep = gzip.decompress((out / 'kde-keep.txt.gzip').read_bytes()).decode().splitlines()
remove += [record for path, record in inv.items() if path in selected or path.startswith(generated)]
keep += list(inv)
write(out, 'kde-remove.tsv.gzip', remove)
write(out, 'kde-keep.txt.gzip', keep)
versions = (out / 'versions.txt').read_text().split()
(out / 'versions.txt').write_text('\n'.join(dict.fromkeys(versions + [tag])) + '\n')
sources = json.loads((out / 'sources.json').read_text())
sources['archives'][tag] = digest
sources['desktopApplications'] = {n: h for n, h in packages.items() if n.rsplit('-', 3)[0] in seeds}
(out / 'sources.json').write_text(json.dumps(sources, indent=2) + '\n')
print(tag, digest)
print('KDE removable paths', sum(path in selected or path.startswith(generated) for path in inv))
def main():
archives = [pathlib.Path(p) for p in sys.argv[1:5]]
cache, out, legacy_cache = map(pathlib.Path, sys.argv[5:8])
here = pathlib.Path(__file__).resolve().parent
selected, packages, seeds = application_paths(here, cache)
inventories = [inventory(p, pin[1]) for p, pin in zip(archives, PINS)]
out.mkdir(parents=True, exist_ok=True)
legacy_seeds = {line.strip() for line in (here / 'lxqt-applications.txt').read_text().splitlines()
if line.strip() and not line.startswith('#')}
legacy_selected = set()
legacy_sources = {}
legacy_found = set()
for filename in (legacy_cache / 'selected.txt').read_text().splitlines():
package = filename.rsplit('-', 3)[0]
if package not in legacy_seeds:
continue
archive = legacy_cache / filename
with tarfile.open(archive) as tar:
legacy_selected.update(e.name.removeprefix('./').rstrip('/') for e in tar if not e.isdir())
legacy_sources[filename] = sha(archive)
legacy_found.add(package)
assert legacy_found == legacy_seeds, f'missing LXQt applications: {legacy_seeds - legacy_found}'
legacy_selected.update({'usr/local/bin/steamdeck-desktop', 'usr/local/bin/steamdeck-steam'})
write(out, 'lxqt-r1.tsv.gzip', [record for path, record in inventories[0].items() if path in legacy_selected])
write(out, 'kde-remove.tsv.gzip', [record for inv in inventories[1:3] for path, record in inv.items() if path in selected])
write(out, 'kde-keep.txt.gzip', [path for inv in inventories[1:3] for path in inv])
write(out, 'emulators-keep.txt.gzip', inventories[3])
(out / 'versions.txt').write_text('desktop-kde-r1\ndesktop-kde-r2\n')
(out / 'sources.json').write_text(json.dumps({'archives': dict(PINS), 'desktopApplications': {n: h for n, h in packages.items() if n.rsplit('-', 3)[0] in seeds}, 'legacyApplications': legacy_sources}, indent=2) + '\n')
for name, digest in PINS:
print(name, digest)
print('KDE removable paths', sum(path in selected for path in inventories[2]))
print('KDE removable bytes', sum(int(record.split('\t')[1]) for path, record in inventories[2].items() if path in selected))
print('LXQt removable paths', sum(path in legacy_selected for path in inventories[0]))
if __name__ == '__main__':
if sys.argv[1:2] == ['--add']:
add(pathlib.Path(sys.argv[2]), sys.argv[3], sys.argv[4], pathlib.Path(sys.argv[5]), pathlib.Path(sys.argv[6]))
else:
main()