Merge branch 'gentoolkit' of git+ssh://git.overlays.gentoo.org/proj/gentoolkit into...
authorBrian Dolbec <brian.dolbec@gmail.com>
Fri, 11 Feb 2011 05:54:34 +0000 (21:54 -0800)
committerBrian Dolbec <brian.dolbec@gmail.com>
Fri, 11 Feb 2011 05:54:34 +0000 (21:54 -0800)
bin/glsa-check
pym/gentoolkit/eshowkw/keywords_content.py
pym/gentoolkit/glsa/__init__.py

index a8c018888dc9ae80e6b55e79e8b8bd4d723a0381..a35375b6b0a5fcddfd8568444826b85f8781a702 100755 (executable)
@@ -358,7 +358,7 @@ if mode == "mail":
                import portage_mail
 
        import socket
-       from io import StringIO
+       from io import BytesIO
        try:
                from email.mime.text import MIMEText
        except ImportError:
@@ -380,11 +380,13 @@ if mode == "mail":
        mysubject = "[glsa-check] Summary for %s" % socket.getfqdn()
 
        # need a file object for summarylist()
-       myfd = StringIO()
-       myfd.write("GLSA Summary report for host %s\n" % socket.getfqdn())
-       myfd.write("(Command was: %s)\n\n" % " ".join(sys.argv))
+       myfd = BytesIO()
+       line = "GLSA Summary report for host %s\n" % socket.getfqdn()
+       myfd.write(line.encode("utf-8"))
+       line = "(Command was: %s)\n\n" % " ".join(sys.argv)
+       myfd.write(line.encode("utf-8"))
        summarylist(glsalist, fd1=myfd, fd2=myfd)
-       summary = str(myfd.getvalue())
+       summary = myfd.getvalue().decode("utf-8")
        myfd.close()
 
        myattachments = []
@@ -395,9 +397,10 @@ if mode == "mail":
                        if verbose:
                                sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e)))
                        continue
-               myfd = StringIO()
+               myfd = BytesIO()
                myglsa.dump(outstream=myfd)
-               myattachments.append(MIMEText(str(myfd.getvalue()), _charset="utf8"))
+               attachment = myfd.getvalue().decode("utf-8")
+               myattachments.append(MIMEText(attachment, _charset="utf8"))
                myfd.close()
 
        if glsalist or not quiet:
index e60e8d5d6bce1a2ff45f6a9c3951c7d4bcaf1379..7cf53e7682d76bad301fab018cc7d8798e136d5d 100644 (file)
@@ -98,32 +98,40 @@ class keywords_content:
        class VersionChecker:
                def __getVersions(self, packages):
                        """Obtain properly aligned version strings without colors."""
-                       return map(lambda x: self.__separateVersion(x), packages)
-
-               def __separateVersion(self, cpv):
-                       """Get version string for specfied cpv"""
-                       #pv = port.versions.cpv_getversion(cpv)
-                       return self.__prependVersionInfo(cpv, self.cpv_getversion(cpv))
-
-               # remove me when portage 2.1.9 is stable
-               def cpv_getversion(self, mycpv):
-                       """Returns the v (including revision) from an cpv."""
-                       cp = port.versions.cpv_getkey(mycpv)
-                       if cp is None:
-                               return None
-                       return mycpv[len(cp+"-"):]
-
-               def __prependVersionInfo(self, cpv, pv):
-                       """Prefix version with string based on whether version is installed or masked."""
+                       revlength = max([len(self.__getRevision(x)) for x in packages])
+                       return map(lambda x: self.__separateVersion(x, revlength), packages)
+
+               def __getRevision(self, cpv):
+                       """Get revision informations for each package for nice further alignment"""
+                       rev = port.catpkgsplit(cpv)[3]
+                       return rev if rev != 'r0' else ''
+
+               def __separateVersion(self, cpv, revlength):
+                       return self.__modifyVersionInfo(cpv, port.versions.cpv_getversion(cpv), revlength)
+
+               def __modifyVersionInfo(self, cpv, pv, revlength):
+                       """Prefix and suffix version with string based on whether version is installed or masked and its revision."""
                        mask = self.__getMaskStatus(cpv)
                        install = self.__getInstallStatus(cpv)
 
+                       # calculate suffix length
+                       currevlen = len(self.__getRevision(cpv))
+                       suffixlen = revlength - currevlen
+                       # +1 required for the dash in revision
+                       if suffixlen != 0 and currevlen == 0:
+                               suffixlen = suffixlen + 1
+                       suffix = ''
+                       for x in range(suffixlen):
+                               suffix = '%s ' % suffix
+
                        if mask and install:
-                               pv = '[M][I]%s' % pv
+                               pv = '[M][I]%s%s' % (pv, suffix)
                        elif mask:
-                               pv = '[M]%s' % pv
+                               pv = '[M]%s%s' % (pv, suffix)
                        elif install:
-                               pv = '[I]%s' % pv
+                               pv = '[I]%s%s' % (pv, suffix)
+                       else:
+                               pv = '%s%s' % (pv, suffix)
                        return pv
 
                def __getMaskStatus(self, cpv):
@@ -309,8 +317,9 @@ class keywords_content:
                self.slot_length = max([len(x) for x in self.slots])
                repositories_length = max([len(x) for x in self.repositories])
                self.keyword_length = len(keywords_list)
-               self.versions = self.VersionChecker(packages).versions
-               masks = self.VersionChecker(packages).masks
+               vers =self.VersionChecker(packages)
+               self.versions = vers.versions
+               masks = vers.masks
                self.version_length = max([len(x) for x in self.versions])
                self.version_count = len(self.versions)
                self.redundant = self.RedundancyChecker(masks, self.keywords, self.slots, ignoreslots).redundant
index ab0394785c7bffb9b51a5c8687166880b3a38867..af97ac6876dd7bffb55137aa2c922414a488b32f 100644 (file)
@@ -622,6 +622,7 @@ class Glsa:
                @param  outfile: Stream that should be used for writing
                                                 (defaults to sys.stdout)
                """
+               outstream = getattr(outstream, "buffer", outstream)
                outstream = codecs.getwriter(encoding)(outstream)
                width = int(self.config["PRINTWIDTH"])
                outstream.write(center("GLSA %s: \n%s" % (self.nr, self.title), width)+"\n")