Minimize the number of manually installed packages

Minimize the number of manually installed packages in images by marking
dependencies of metapackages as automatically installed.

Squashed commits:
* minimize-manual.py: Followup with some cleanup, correct permissions
* fixup: Do not assume current directory
* Reorganize minimal-manual file location.
sil2100/backport-datasource-raspi3
Julian Andres Klode 6 years ago
parent 6e27dfdaf8
commit be180bcf93

7
debian/changelog vendored

@ -1,3 +1,10 @@
livecd-rootfs (2.525.20) UNRELEASED; urgency=medium
* Minimize the number of manually installed packages in images by marking
dependencies of metapackages as automatically installed. (LP: #1800610)
-- Julian Andres Klode <juliank@ubuntu.com> Mon, 04 Mar 2019 18:00:26 +0100
livecd-rootfs (2.525.19) bionic; urgency=medium
* Make sure buildd images have a /usr/sbin/policy-rc.d symlink

1
debian/control vendored

@ -28,6 +28,7 @@ Depends: ${misc:Depends},
parted,
procps,
python-minimal | python,
python3-apt,
python3-software-properties,
qemu-utils,
rsync,

1
debian/install vendored

@ -1,2 +1,3 @@
live-build usr/share/livecd-rootfs
get-ppa-fingerprint usr/share/livecd-rootfs
minimize-manual usr/share/livecd-rootfs

@ -435,6 +435,8 @@ EOF
(cd chroot && find usr/share/doc -maxdepth 1 -type d | xargs du -s | sort -nr)
echo END docdirs
/usr/share/livecd-rootfs/minimize-manual chroot
lb binary "$@"
touch binary.success
) 2>&1 | tee binary.log

@ -0,0 +1,52 @@
#!/usr/bin/python3
"""Minimize the number of manually installed packages in the image.
Finds all manually installed meta packages, and marks their dependencies
as automatically installed.
"""
import sys
import apt
def is_root(pkg):
"""Check if the package is a root package (manually inst. meta)"""
return (pkg.is_installed and
not pkg.is_auto_installed and
(pkg.section == "metapackages" or
pkg.section.endswith("/metapackages")))
def main():
"""Main function"""
cache = apt.Cache(rootdir=sys.argv[1] if len(sys.argv) > 1 else None)
roots = set(pkg for pkg in cache if is_root(pkg))
workset = set(roots)
seen = set()
with cache.actiongroup():
while True:
print("Iteration", file=sys.stderr)
to_proc = workset - seen
if not to_proc:
break
for pkg in sorted(to_proc):
print(" Visiting", pkg, file=sys.stderr)
if pkg not in roots:
pkg.mark_auto()
for dep in (pkg.installed.dependencies +
pkg.installed.recommends):
for bdep in dep.or_dependencies:
for ver in bdep.target_versions:
if ver.package.is_installed:
workset.add(ver.package)
seen.add(pkg)
cache.commit()
if __name__ == '__main__':
main()
Loading…
Cancel
Save