[PATCH 2/4] Fix package and group removing with the dnf payload.

Chris Lumens clumens at redhat.com
Fri Feb 20 16:31:41 UTC 2015


We can't really use dnf the same way we were using yum here.  With yum, we were
treating the transaction as a thing we could add and remove stuff from as much
as we wanted and then when we were done, tell yum to go ahead and do it.  dnf
doesn't work that way - we need to keep track of the additions and removals in
anaconda, and then when we are done tell dnf the result.

Thus:

(1) For groups, we implement selectEnvironment ourselves.  Just check that the
group is not in the excluded list when adding.  Same for when iterating over
the list of groups to add.

(2) For packages, make sure they're not in the excluded list when adding.  For
a package to remove that is part of a group we are installing, we are already
passing the excluded list along to dnf.  That should work.

(3) Remove _remove_package and _remove_group, since they don't (and won't)
work.
---
 pyanaconda/packaging/__init__.py   | 10 +++++++---
 pyanaconda/packaging/dnfpayload.py | 40 +++++++-------------------------------
 2 files changed, 14 insertions(+), 36 deletions(-)

diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index 7642d2f..4aad56c 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -1033,12 +1033,16 @@ class PackagePayload(Payload):
     def environmentDescription(self, environmentid):
         raise NotImplementedError()
 
-    def selectEnvironment(self, environmentid):
+    def selectEnvironment(self, environmentid, excluded=None):
         if environmentid not in self.environments:
             raise NoSuchGroup(environmentid)
 
-        # Select each group within the environment
-        for groupid in self.environmentGroups(environmentid, optional=False):
+        if excluded is None:
+            excluded = []
+
+        # Select each group within the environment, as long as that group was
+        # not explicitly excluded by the user.
+        for groupid in set(self.environmentGroups(environmentid, optional=False)) - set(excluded):
             self.selectGroup(groupid)
 
     def environmentGroups(self, environmentid, optional=True):
diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py
index 36598f5..288c49e 100644
--- a/pyanaconda/packaging/dnfpayload.py
+++ b/pyanaconda/packaging/dnfpayload.py
@@ -282,46 +282,36 @@ class DNFPayload(packaging.PackagePayload):
         elif self.data.packages.environment:
             env = self.data.packages.environment
 
+        excludedGroups = [group.name for group in self.data.packages.excludedGroupList]
+
         if env:
             try:
-                self.selectEnvironment(env)
+                self.selectEnvironment(env, excludedGroups)
                 log.info("selected env: %s", env)
             except packaging.NoSuchGroup as e:
                 self._miss(e)
 
         for group in self.data.packages.groupList:
-            if group.name == 'core':
+            if group.name == 'core' or group.name in excludedGroups:
                 continue
+
             default = group.include in (GROUP_ALL,
                                         GROUP_DEFAULT)
             optional = group.include == GROUP_ALL
+
             try:
                 self._select_group(group.name, default=default, optional=optional)
                 log.info("selected group: %s", group.name)
             except packaging.NoSuchGroup as e:
                 self._miss(e)
 
-        for group in self.data.packages.excludedGroupList:
-            try:
-                self._deselect_group(group.name)
-                log.info("deselected group: %s", group.name)
-            except packaging.NoSuchGroup:
-                log.info("skipped removing nonexistant group: %s", group.name)
-
-        for pkg_name in self.data.packages.packageList:
+        for pkg_name in set(self.data.packages.packageList) - set(self.data.packages.excludedList):
             try:
                 self._install_package(pkg_name)
                 log.info("selected package: '%s'", pkg_name)
             except packaging.NoSuchPackage as e:
                 self._miss(e)
 
-        for pkg_name in self.data.packages.excludedList:
-            try:
-                self._remove_package(pkg_name)
-                log.info("removed package: %s", pkg_name)
-            except packaging.NoSuchPackage:
-                log.info("skipped removing nonexistant package: %s", pkg_name)
-
         self._select_kernel_package()
 
         for pkg_name in self.requiredPackages:
@@ -386,12 +376,6 @@ class DNFPayload(packaging.PackagePayload):
         except dnf.exceptions.MarkingError:
             raise packaging.NoSuchPackage(pkg_name, required=required)
 
-    def _remove_package(self, pkg_name):
-        try:
-            return self._base.remove(pkg_name)
-        except dnf.exceptions.PackagesNotInstalledError:
-            raise packaging.NoSuchPackage(pkg_name)
-
     def _miss(self, exn):
         if self.data.packages.handleMissing == KS_MISSING_IGNORE:
             return
@@ -438,16 +422,6 @@ class DNFPayload(packaging.PackagePayload):
             # DNF raises this when it is already selected
             log.debug(e)
 
-    def _deselect_group(self, group_id):
-        grp = self._base.comps.group_by_pattern(group_id)
-        if grp is None:
-            raise packaging.NoSuchGroup(group_id)
-        try:
-            self._base.group_remove(grp)
-        except dnf.exceptions.CompsError as e:
-            # DNF raises this when it is already not selected
-            log.debug(e)
-
     def _select_kernel_package(self):
         kernels = self.kernelPackages
         for kernel in kernels:
-- 
2.2.2



More information about the anaconda-patches mailing list