zypp: deselect packages while zypp resolving finished
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Sep 2011 10:12:10 +0000 (18:12 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Fri, 16 Sep 2011 10:12:10 +0000 (18:12 +0800)
The deselect operation should be called after zypp resolving
process finished, fix BMC#22939

plugins/backend/zypppkgmgr.py

index eba1950..04439dd 100644 (file)
@@ -64,6 +64,7 @@ class Zypp(BackendPlugin):
         self.__pkgs_content = {}
         self.creator = creator
         self.repos = []
+        self.to_deselect = []
         self.localpkgs = {}
         self.repo_manager = None
         self.repo_manager_options = None
@@ -172,41 +173,31 @@ class Zypp(BackendPlugin):
             return None
         else:
             raise CreatorError("Unable to find package: %s" % (pkg,))
-
-    def deselectPackage(self, pkg):
-        """Deselect package.  Can be specified as name.arch or name*"""
-
-        if not self.Z:
-            self.__initialize_zypp()
-
-        startx = pkg.startswith("*")
-        endx = pkg.endswith("*")
-        ispattern = startx or endx
-        sp = pkg.rsplit(".", 2)
-        for item in self.Z.pool():
-            kind = "%s" % item.kind()
-            if kind == "package":
-                name = "%s" % item.name()
-                if not ispattern:
-                    if len(sp) == 2:
-                        arch = "%s" % item.arch()
-                        if name == sp[0] and arch == sp[1]:
-                            if item.status().isToBeInstalled():
-                                item.status().resetTransact(zypp.ResStatus.USER)
-                            break
-                    else:
-                        if name == sp[0]:
-                            if item.status().isToBeInstalled():
-                                item.status().resetTransact(zypp.ResStatus.USER)
-                            break
+    def inDeselectPackages(self, name):
+        """check if specified pacakges are in the list of inDeselectPackages"""
+        for pkg in self.to_deselect:
+            startx = pkg.startswith("*")
+            endx = pkg.endswith("*")
+            ispattern = startx or endx
+            sp = pkg.rsplit(".", 2)
+            if not ispattern:
+                if len(sp) == 2:
+                    arch = "%s" % item.arch()
+                    if name == sp[0] and arch == sp[1]:
+                        return True;
                 else:
-                    if startx and name.endswith(sp[0][1:]):
-                        if item.status().isToBeInstalled():
-                            item.status().resetTransact(zypp.ResStatus.USER)
+                    if name == sp[0]:
+                        return True;
+            else:
+                if startx and name.endswith(sp[0][1:]):
+                        return True;
+                if endx and name.startswith(sp[0][:-1]):
+                        return True;
+        return False;
 
-                    if endx and name.startswith(sp[0][:-1]):
-                        if item.status().isToBeInstalled():
-                            item.status().resetTransact(zypp.ResStatus.USER)
+    def deselectPackage(self, pkg):
+        """collect packages should not be installed"""
+        self.to_deselect.append(pkg)
 
     def __selectIncpkgs(self):
         found = False
@@ -322,7 +313,7 @@ class Zypp(BackendPlugin):
         installed_pkgs = todo._toInstall
         dlpkgs = []
         for item in installed_pkgs:
-            if not zypp.isKindPattern(item):
+            if not zypp.isKindPattern(item) and not self.inDeselectPackages(item.name()):
                 dlpkgs.append(item)
 
         # record the total size of installed pkgs