From c7025a6e3f360850c98c0ea4aa9760d671939a2f Mon Sep 17 00:00:00 2001 From: fuzzyray Date: Thu, 7 May 2009 21:52:43 +0000 Subject: [PATCH] Add patch from Robert Buchholz: Reformat '2008-01-01' dates to 'January 01, 2008' to keep output consistent. svn path=/branches/gentoolkit-0.2.4/; revision=623 --- src/glsa-check/glsa.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/glsa-check/glsa.py b/src/glsa-check/glsa.py index 0931908..b1ff847 100644 --- a/src/glsa-check/glsa.py +++ b/src/glsa-check/glsa.py @@ -397,6 +397,32 @@ def getMinUpgrade(vulnerableList, unaffectedList, minimize=True): 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): @@ -483,7 +509,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: @@ -496,6 +522,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: -- 2.26.2