1 |
Author: genone |
2 |
Date: 2008-09-28 18:50:02 +0000 (Sun, 28 Sep 2008) |
3 |
New Revision: 11590 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/glsa.py |
7 |
Log: |
8 |
print dates in a consistent format (patch by Robert Buchholz <rbu@g.o>) |
9 |
|
10 |
Modified: main/trunk/pym/portage/glsa.py |
11 |
=================================================================== |
12 |
--- main/trunk/pym/portage/glsa.py 2008-09-28 18:41:56 UTC (rev 11589) |
13 |
+++ main/trunk/pym/portage/glsa.py 2008-09-28 18:50:02 UTC (rev 11590) |
14 |
@@ -353,6 +353,32 @@ |
15 |
rValue += "-"+c_pv[3] |
16 |
return rValue |
17 |
|
18 |
+def format_date(datestr): |
19 |
+ """ |
20 |
+ Takes a date (announced, revised) date from a GLSA and formats |
21 |
+ it as readable text (i.e. "January 1, 2008"). |
22 |
+ |
23 |
+ @type date: String |
24 |
+ @param date: the date string to reformat |
25 |
+ @rtype: String |
26 |
+ @return: a reformatted string, or the original string |
27 |
+ if it cannot be reformatted. |
28 |
+ """ |
29 |
+ splitdate = datestr.split("-", 2) |
30 |
+ if len(splitdate) != 3: |
31 |
+ return datestr |
32 |
+ |
33 |
+ # This cannot raise an error as we use () instead of [] |
34 |
+ splitdate = (int(x) for x in splitdate) |
35 |
+ |
36 |
+ from datetime import date |
37 |
+ try: |
38 |
+ d = date(*splitdate) |
39 |
+ except ValueError: |
40 |
+ return datestr |
41 |
+ |
42 |
+ # TODO We could format to local date format '%x' here? |
43 |
+ return d.strftime("%B %d, %Y") |
44 |
|
45 |
# simple Exception classes to catch specific errors |
46 |
class GlsaTypeException(Exception): |
47 |
@@ -445,7 +471,7 @@ |
48 |
# the simple (single, required, top-level, #PCDATA) tags first |
49 |
self.title = getText(myroot.getElementsByTagName("title")[0], format="strip") |
50 |
self.synopsis = getText(myroot.getElementsByTagName("synopsis")[0], format="strip") |
51 |
- self.announced = getText(myroot.getElementsByTagName("announced")[0], format="strip") |
52 |
+ self.announced = format_date(getText(myroot.getElementsByTagName("announced")[0], format="strip")) |
53 |
|
54 |
count = 1 |
55 |
# Support both formats of revised: |
56 |
@@ -458,6 +484,8 @@ |
57 |
elif (self.revised.find(":") >= 0): |
58 |
(self.revised, count) = self.revised.split(":") |
59 |
|
60 |
+ self.revised = format_date(self.revised) |
61 |
+ |
62 |
try: |
63 |
self.count = int(count) |
64 |
except ValueError: |