[yum-cvs] yum/yum packageSack.py,1.6,1.7 packages.py,1.51,1.52

Seth Vidal skvidal at linux.duke.edu
Tue Aug 22 04:04:52 UTC 2006


Update of /home/groups/yum/cvs/yum/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv20429/yum

Modified Files:
	packageSack.py packages.py 
Log Message:
rich comparison methods for package objects



Index: packageSack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/packageSack.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- packageSack.py	22 Aug 2006 02:54:07 -0000	1.6
+++ packageSack.py	22 Aug 2006 04:04:50 -0000	1.7
@@ -291,6 +291,7 @@
     def __len__(self):
         return len(self.simplePkgList())
     
+
     def _checkIndexes(self, failure='error'):
         """check to see if the indexes are built, if not do what failure demands
            either error out or build the indexes, default is to error out"""

Index: packages.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/packages.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- packages.py	19 Aug 2006 19:22:37 -0000	1.51
+++ packages.py	22 Aug 2006 04:04:50 -0000	1.52
@@ -29,6 +29,11 @@
 
 base=None
 
+def comparePoEVR(po1, po2):
+    (e1, v1, r1) = (po1.epoch, po1.ver, po1.rel)
+    (e2, v2, r2) = (po2.epoch, po2.ver, po2.rel)
+    return rpmUtils.miscutils.compareEVR((e1, v1, r1), (e2, v2, r2))
+
 def buildPkgRefDict(pkgs):
     """take a list of pkg objects and return a dict the contains all the possible
        naming conventions for them eg: for (name,i386,0,1,1)
@@ -177,7 +182,63 @@
         self.files['ghost'] = []
         self.changelog = [] # (ctime, cname, ctext)
         self.licenses = []
+
+    def __lt__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc < 0:
+            val = True
+        
+        return val
+        
+    def __gt__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc > 0:
+            val = True
+        
+        return val
+
+    def __le__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc <= 0:
+            val = True
+        
+        return val
     
+
+    def __ge__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc >= 0:
+            val = True
+        
+        return val
+    
+
+    def __eq__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc == 0:
+            val = True
+        
+        return val
+    
+
+    def __ne__(self, other):
+        val = False
+        rc = comparePoEVR(self, other)
+        if rc != 0:
+            val = True
+        
+        return val
+    
+    def __hash__(self):
+        mystr = '%s - %s:%s-%s-%s.%s' % (self.repoid, self.epoch, self.name,
+                                         self.ver, self.rel, self.arch)
+        return hash(mystr)
+        
     def returnPrco(self, prcotype):
         """return list of provides, requires, conflicts or obsoletes"""
         if self.prco.has_key(prcotype):




More information about the Yum-cvs-commits mailing list