Update sorting algorithm to order slots properly if package with lower slot has highe...
authorscarabeus <scarabeus@gentoo.org>
Sat, 4 Dec 2010 08:46:56 +0000 (08:46 -0000)
committerscarabeus <scarabeus@gentoo.org>
Sat, 4 Dec 2010 08:46:56 +0000 (08:46 -0000)
svn path=/trunk/gentoolkit/; revision=871

pym/gentoolkit/eshowkw/keywords_content.py

index b517a397a7e43f758cdc770caceca1ef3a5bd537..b9401ad5b5142cf0449f5b26165e4d1b2717f47b 100644 (file)
@@ -141,24 +141,22 @@ class keywords_content:
                        """Query all relevant data for version data formatting"""
                        self.versions = self.__getVersions(packages)
 
-       def __cpv_sort_ascending(self, cpv_list):
+       def __packages_sort(self, package_content):
                """
-               Use this to sort self.cp_list() results in ascending
-               order. It sorts in place and returns None.
+               Sort packages queried based on version and slot
+               %% pn , repo, slot, keywords
                """
-               if len(cpv_list) > 1:
-                       # If the cpv includes explicit -r0, it has to be preserved
-                       # for consistency in findname and aux_get calls, so use a
-                       # dict to map strings back to their original values.
+               from operator import itemgetter 
+
+               if len(package_content) > 1:
                        ver_map = {}
-                       for cpv in cpv_list:
-                               cpv = cpv.split('%')[0]
-                               ver_map[cpv] = '-'.join(port.versions.catpkgsplit(cpv)[2:])
+                       for cpv in package_content:
+                               ver_map[cpv[0]] = '-'.join(port.versions.catpkgsplit(cpv[0])[2:])
                        def cmp_cpv(cpv1, cpv2):
-                               cpv1 = cpv1.split('%')[0]
-                               cpv2 = cpv2.split('%')[0]
-                               return port.versions.vercmp(ver_map[cpv1], ver_map[cpv2])
-                       cpv_list.sort(key=port.util.cmp_sort_key(cmp_cpv))
+                               return port.versions.vercmp(ver_map[cpv1[0]], ver_map[cpv2[0]])
+                       #package_content.sort(key=lambda i: [getattr(i,a) for a in attrs])
+                       package_content.sort(key=port.util.cmp_sort_key(cmp_cpv))
+                       package_content.sort(key=itemgetter(2))
 
        def __xmatch(self, pdb, package):
                """xmatch function that searches for all packages over all repos"""
@@ -173,7 +171,7 @@ class keywords_content:
                        raise SystemExit(msg_err)
 
                mysplit = mycp.split('/')
-               d={}
+               mypkgs = []
                for oroot in pdb.porttrees:
                        try:
                                file_list = os.listdir(os.path.join(oroot, mycp))
@@ -190,11 +188,12 @@ class keywords_content:
                                        if ver_match is None or not ver_match.groups():
                                                # version is not allowed by portage or unset
                                                continue
-                                       d[mysplit[0]+'/'+pf+'%'+oroot] = None
+                                       # obtain related data from metadata and append to the pkg list
+                                       keywords, slot = self.__getMetadata(pdb, mysplit[0]+'/'+pf, oroot)
+                                       mypkgs.append([mysplit[0]+'/'+pf, oroot, slot, keywords])
 
-               mylist = list(d)
-               self.__cpv_sort_ascending(mylist)
-               return mylist
+               self.__packages_sort(mypkgs)
+               return mypkgs
 
        def __checkExist(self, pdb, package):
                """Check if specified package even exists."""
@@ -202,18 +201,16 @@ class keywords_content:
                if len(matches) <= 0:
                        msg_err = 'No such package "%s"' % package
                        raise SystemExit(msg_err)
-               content = [x.split('%') for x in matches]
-               return list(zip(*content))
+               return list(zip(*matches))
 
-       def __getMetadata(self, pdb, packages, repos):
+       def __getMetadata(self, pdb, package, repo):
                """Obtain all required metadata from portage auxdb"""
                try:
-                       metadata = [pdb.aux_get(pkg, ['KEYWORDS', 'SLOT'], tree)
-                               for pkg, tree in zip(packages, repos)]
+                       metadata = pdb.aux_get(package, ['KEYWORDS', 'SLOT'], repo)
                except KeyError:
                        # portage prints out more verbose error for us if we were lucky
                        raise SystemExit('Failed to obtain metadata')
-               return list(zip(*metadata))
+               return metadata
 
        def __formatKeywords(self, keywords, keywords_list, usebold = False, toplist = 'archlist'):
                """Loop over all keywords and replace them with nice visual identifier"""
@@ -299,8 +296,7 @@ class keywords_content:
 
        def __init__(self, package, keywords_list, porttree, ignoreslots = False, content_align = 'bottom', usebold = False, toplist = 'archlist'):
                """Query all relevant data from portage databases."""
-               packages, self.repositories = self.__checkExist(porttree, package)
-               self.keywords, self.slots = self.__getMetadata(porttree, packages, self.repositories)
+               packages, self.repositories, self.slots, self.keywords = self.__checkExist(porttree, package)
                # convert repositories from path to name
                self.repositories = [porttree.getRepositoryName(x) for x in self.repositories]
                self.slot_length = max([len(x) for x in self.slots])