[neon/forks/ubuntu-release-upgrader/Neon/unstable_focal] /: DistUpgrade/DistUpgradeQuirks.py: use apt's problem resolver to better calculate upgrades where python is replaced by python-is-python2 thereby resolving a host of upgrade failures. Thanks to Julian for the initial patch. (LP: #1898152)

Brian Murray null at kde.org
Mon Apr 12 11:16:39 BST 2021


Git commit 3d54bbfd11172e26b31128f81d149df35cdef31d by Brian Murray.
Committed on 31/03/2021 at 17:06.
Pushed by jriddell into branch 'Neon/unstable_focal'.

DistUpgrade/DistUpgradeQuirks.py:  use apt's problem resolver to better calculate upgrades where python is replaced by python-is-python2 thereby resolving a host of upgrade failures. Thanks to Julian for the initial patch. (LP: #1898152)

M  +4    -4    DistUpgrade/DistUpgradeCache.py
M  +29   -18   DistUpgrade/DistUpgradeQuirks.py
M  +9    -0    debian/changelog

https://invent.kde.org/neon/forks/ubuntu-release-upgrader/commit/3d54bbfd11172e26b31128f81d149df35cdef31d

diff --git a/DistUpgrade/DistUpgradeCache.py b/DistUpgrade/DistUpgradeCache.py
index 72c4361f..d34e3232 100644
--- a/DistUpgrade/DistUpgradeCache.py
+++ b/DistUpgrade/DistUpgradeCache.py
@@ -420,10 +420,10 @@ class MyCache(apt.Cache):
                 return False
         return True
 
-    def mark_install(self, pkg, reason=""):
+    def mark_install(self, pkg, reason="", **flags):
         logging.debug("Installing '%s' (%s)" % (pkg, reason))
         if pkg in self:
-            self[pkg].mark_install()
+            self[pkg].mark_install(**flags)
             if not (self[pkg].marked_install or self[pkg].marked_upgrade):
                 logging.error("Installing/upgrading '%s' failed" % pkg)
                 #raise SystemError("Installing '%s' failed" % pkg)
@@ -439,10 +439,10 @@ class MyCache(apt.Cache):
                 return False
         return True
 
-    def mark_remove(self, pkg, reason=""):
+    def mark_remove(self, pkg, reason="", **flags):
         logging.debug("Removing '%s' (%s)" % (pkg, reason))
         if pkg in self:
-            self[pkg].mark_delete()
+            self[pkg].mark_delete(**flags)
 
     def mark_purge(self, pkg, reason=""):
         logging.debug("Purging '%s' (%s)" % (pkg, reason))
diff --git a/DistUpgrade/DistUpgradeQuirks.py b/DistUpgrade/DistUpgradeQuirks.py
index 4c3381f4..0460c59a 100644
--- a/DistUpgrade/DistUpgradeQuirks.py
+++ b/DistUpgrade/DistUpgradeQuirks.py
@@ -907,27 +907,38 @@ class DistUpgradeQuirks(object):
                         ('libpython-stdlib', None),
                         ('libpython-dbg', None))
         cache = self.controller.cache
+
+        # We run with auto_inst=False first to mark our explicit choices so it
+        # can guide the code with auto_inst=True when it makes decisions
+        for auto_inst in False, True:
+            for old, new in replacements:
+                logging.info("checking for %s (auto_inst=%s)" %
+                             (old, auto_inst))
+                if old in cache and cache[old].is_installed:
+                    if new:
+                        logging.info("installing %s because %s was installed" %
+                                     (new, old))
+                        reason = "%s was installed on the system" % old
+                        if not cache.mark_install(new, reason, auto_fix=False,
+                                                  auto_inst=auto_inst):
+                            logging.info("failed to install %s" % new)
+                    logging.info("removing %s because %s is being installed" %
+                                 (old, new))
+                    reason = "%s is being installed on the system" % new
+                    if not cache.mark_remove(old, reason, auto_fix=False):
+                        logging.info("failed to remove %s", old)
+
+        solver = apt.cache.ProblemResolver(cache)
+
         for old, new in replacements:
-            logging.info("checking for %s" % old)
             if old in cache and cache[old].is_installed:
                 if new:
-                    logging.info("installing %s because %s was installed" %
-                                 (new, old))
-                    reason = "%s was installed on the system" % old
-                    if not cache.mark_install(new, reason):
-                        logging.info("failed to install %s" % new)
-                logging.info("removing %s because %s is being installed" %
-                             (old, new))
-                reason = "%s is being installed on the system" % new
-                if not cache.mark_remove(old, reason):
-                    logging.info("failed to remove %s", old)
-
-            # protect our decision to remove legacy 'python' (as a
-            # dependency of python-minimal, removed above)
-            py = 'python'
-            if py in cache and cache[py].marked_delete:
-                resolver = apt.cache.ProblemResolver(cache)
-                resolver.protect(cache[py])
+                    solver.clear(cache[new])
+                    solver.protect(cache[new])
+                solver.clear(cache[old])
+                solver.remove(cache[old])
+
+        solver.resolve()
 
     def ensure_recommends_are_installed_on_desktops(self):
         """ ensure that on a desktop install recommends are installed
diff --git a/debian/changelog b/debian/changelog
index 8d197133..ad620b8b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+ubuntu-release-upgrader (1:20.04.31) focal; urgency=medium
+
+  * DistUpgrade/DistUpgradeQuirks.py:  use apt's problem resolver to better
+    calculate upgrades where python is replaced by python-is-python2 thereby
+    resolving a host of upgrade failures. Thanks to Julian for the initial
+    patch. (LP: #1898152)
+
+ -- Brian Murray <brian at ubuntu.com>  Wed, 31 Mar 2021 10:05:14 -0700
+
 ubuntu-release-upgrader (1:20.04.30) focal; urgency=medium
 
   * data/mirrors.cfg: update mirrors for the 20.04.2 point release.



More information about the Neon-commits mailing list