[Piuparts-devel] Bug#648162: [PATCH v2] use apt-get remove; remove/purge all packages at once
Andreas Beckmann
debian at abeckmann.de
Wed Nov 9 10:37:26 UTC 2011
this patch is available from
git://github.com/anbe42/piuparts.git feature/648162-apt-get-remove
------ 8< -----
Removing packages with dpkg one-by-one does not respect dependencies
and may fail e.g. when Pre-Depends are involved. Therefore use
apt-get remove on all packages in one run to reorder them properly.
apt-get purge can't be used because it fails on unknown packages (i.e. not
in the archive and not in config-files-remaining state). See #637853.
Also apt-get in lenny is not able to properly purge packages in
config-files-remaining state.
But we can purge all packages in one dpkg call.
The remove_or_purge() method is replaced by two new methods
remove_packages() and purge_packages().
Signed-off-by: Andreas Beckmann <debian at abeckmann.de>
---
piuparts.py | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/piuparts.py b/piuparts.py
index 4fffbd6..3f22d46 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -865,12 +865,15 @@ class Chroot:
vdict[name] = status
return vdict
- def remove_or_purge(self, operation, packages):
- """Remove or purge packages in a chroot."""
- for name in packages:
- self.run(["dpkg", "--" + operation, name], ignore_errors=True)
- self.run(["dpkg", "--remove", "--pending"], ignore_errors=True)
+ def remove_packages(self, packages):
+ """Remove packages in a chroot."""
+ if packages:
+ self.run(["apt-get", "remove"] + packages, ignore_errors=True)
+ def purge_packages(self, packages):
+ """Purge packages in a chroot."""
+ if packages:
+ self.run(["dpkg", "--purge"] + packages, ignore_errors=True)
def restore_selections(self, changes, packages):
"""Restore package selections in a chroot by applying 'changes'.
@@ -898,8 +901,8 @@ class Chroot:
self.run_scripts("pre_remove")
# First remove all packages.
- self.remove_or_purge("remove", deps_to_remove + deps_to_purge +
- nondeps_to_remove + nondeps_to_purge)
+ self.remove_packages(deps_to_remove + deps_to_purge +
+ nondeps_to_remove + nondeps_to_purge)
# Run custom scripts after removing all packages.
if settings.scriptsdir is not None:
self.run_scripts("post_remove")
@@ -916,13 +919,13 @@ class Chroot:
if not settings.skip_logrotatefiles_test and logrotatefiles:
installed = self.install_logrotate()
self.check_output_logrotatefiles(logrotatefiles_list)
- self.remove_or_purge("purge", installed)
+ self.purge_packages(installed)
# Then purge all packages being depended on.
- self.remove_or_purge("purge", deps_to_purge)
+ self.purge_packages(deps_to_purge)
# Finally, purge actual packages.
- self.remove_or_purge("purge", nondeps_to_purge)
+ self.purge_packages(nondeps_to_purge)
# Run custom scripts after purge all packages.
if settings.scriptsdir is not None:
@@ -1718,7 +1721,7 @@ def install_purge_test(chroot, root_info, selections, package_list, packages):
chroot.install_package_files([metapackage])
# Now remove it
metapackagename = os.path.basename(metapackage)[:-4]
- chroot.remove_or_purge("purge", [metapackagename])
+ chroot.purge_packages([metapackagename])
shutil.rmtree(os.path.dirname(metapackage))
# Save the file ownership information so we can tell which
--
1.7.7.1
More information about the Piuparts-devel
mailing list