diff options
author | Marius Mauch <genone@gentoo.org> | 2008-09-28 18:50:02 +0000 |
---|---|---|
committer | Marius Mauch <genone@gentoo.org> | 2008-09-28 18:50:02 +0000 |
commit | d2d0cdaf2b19eebf5c6891054ca68cbead90ca28 (patch) | |
tree | 5e5f0789c1bac15ee06f45c157ba2888588a2b08 | |
parent | 645ac02ee03e54f797c20594755db0f80873ee55 (diff) | |
download | portage-d2d0cdaf2b19eebf5c6891054ca68cbead90ca28.tar.gz portage-d2d0cdaf2b19eebf5c6891054ca68cbead90ca28.tar.bz2 portage-d2d0cdaf2b19eebf5c6891054ca68cbead90ca28.zip |
print dates in a consistent format (patch by Robert Buchholz <rbu@gentoo.org>)
svn path=/main/trunk/; revision=11590
-rw-r--r-- | pym/portage/glsa.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index b7f0c953e..e44c279b1 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -353,6 +353,32 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize= rValue += "-"+c_pv[3] return rValue +def format_date(datestr): + """ + Takes a date (announced, revised) date from a GLSA and formats + it as readable text (i.e. "January 1, 2008"). + + @type date: String + @param date: the date string to reformat + @rtype: String + @return: a reformatted string, or the original string + if it cannot be reformatted. + """ + splitdate = datestr.split("-", 2) + if len(splitdate) != 3: + return datestr + + # This cannot raise an error as we use () instead of [] + splitdate = (int(x) for x in splitdate) + + from datetime import date + try: + d = date(*splitdate) + except ValueError: + return datestr + + # TODO We could format to local date format '%x' here? + return d.strftime("%B %d, %Y") # simple Exception classes to catch specific errors class GlsaTypeException(Exception): @@ -445,7 +471,7 @@ class Glsa: # the simple (single, required, top-level, #PCDATA) tags first self.title = getText(myroot.getElementsByTagName("title")[0], format="strip") self.synopsis = getText(myroot.getElementsByTagName("synopsis")[0], format="strip") - self.announced = getText(myroot.getElementsByTagName("announced")[0], format="strip") + self.announced = format_date(getText(myroot.getElementsByTagName("announced")[0], format="strip")) count = 1 # Support both formats of revised: @@ -458,6 +484,8 @@ class Glsa: elif (self.revised.find(":") >= 0): (self.revised, count) = self.revised.split(":") + self.revised = format_date(self.revised) + try: self.count = int(count) except ValueError: |