import portage_mail
import socket
- from io import StringIO
+ from io import BytesIO
try:
from email.mime.text import MIMEText
except ImportError:
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 = []
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:
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):
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