incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1437985 - in /incubator/public/trunk/incuvoter: incuvoter.py votestatus.py
Date Thu, 24 Jan 2013 13:03:08 GMT
Author: brane
Date: Thu Jan 24 13:03:08 2013
New Revision: 1437985

URL: http://svn.apache.org/viewvc?rev=1437985&view=rev
Log:
Move timestamp parsing and formatting out of FeedDatabase.Vote.
Display only dates in vote status -- ignore times.

Modified:
    incubator/public/trunk/incuvoter/incuvoter.py
    incubator/public/trunk/incuvoter/votestatus.py

Modified: incubator/public/trunk/incuvoter/incuvoter.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/incuvoter/incuvoter.py?rev=1437985&r1=1437984&r2=1437985&view=diff
==============================================================================
--- incubator/public/trunk/incuvoter/incuvoter.py (original)
+++ incubator/public/trunk/incuvoter/incuvoter.py Thu Jan 24 13:03:08 2013
@@ -46,6 +46,38 @@ except ImportError:
     feedparser = None
 
 
+class __ZULU(datetime.tzinfo):
+    def utcoffset(self, dt):
+        return 0;
+    def dst(self, dt):
+        return timedelta(0)
+    def tzname(self,dt):
+        return "Z"
+
+    def adjust(self, dateobject):
+        if isinstance(dateobject, datetime.datetime):
+            if dateobject.tzinfo:
+                dateobject = dateobject.astimezone(self)
+            return dateobject
+        return None
+ZULU = __ZULU()
+
+def timestring(dateobject):
+    adjusted = ZULU.adjust(dateobject)
+    if adjusted:
+        return adjusted.strftime('%Y-%m-%d %H:%M:%S')
+    return str(dateobject)
+
+def timedate(dateobject):
+    adjusted = ZULU.adjust(dateobject)
+    if adjusted:
+        return adjusted.strftime('%Y-%m-%d')
+    return str(dateobject)
+
+def timeparse(datestring):
+    return datetime.datetime.strptime(datestring, '%Y-%m-%d %H:%M:%S')
+
+
 class FeedParser(object):
     # FIXME: Our own feed seems to be woefully incomplete.
     #        Use Markmail's for now.
@@ -91,7 +123,7 @@ class FeedParser(object):
     def record(self, database):
         feed_updated = self.feed.get('updated', None)
         if not feed_updated:
-            feed_updated = database.Vote.timefmt(datetime.datetime.utcnow())
+            feed_updated = timestring(datetime.datetime.utcnow())
         if database.updated == feed_updated:
             # Nothing changed, do not modify the database.
             return
@@ -115,7 +147,7 @@ class FeedParser(object):
                 updated = datetime.datetime.fromtimestamp(time.mktime(updated))
             if updated and created and created > updated:
                 updated = created
-            updated = database.Vote.timefmt(updated)
+            updated = timestring(updated)
             if parsed.group('firstres') or parsed.group('secondres'):
                 closed = updated
             else:
@@ -212,27 +244,6 @@ class FeedDatabase(object):
                 self.closed = other.closed
 
         @classmethod
-        def timeobj(cls, datestring):
-            return datetime.datetime.strptime(datestring, '%Y-%m-%d %H:%M:%S')
-
-        class __ZULU(datetime.tzinfo):
-            def utcoffset(self, dt):
-                return 0;
-            def dst(self, dt):
-                return timedelta(0)
-            def tzname(self,dt):
-                return "Z"
-        ZULU = __ZULU()
-
-        @classmethod
-        def timefmt(cls, dateobject):
-            if isinstance(dateobject, datetime.datetime):
-                if dateobject.tzinfo:
-                    dateobject = dateobject.astimezone(cls.ZULU)
-                return dateobject.isoformat().replace('T', ' ')
-            return str(dateobject)
-
-        @classmethod
         def find(cls, con, subject):
             sortkey = subject.upper()
             cursor = con.cursor()
@@ -309,7 +320,7 @@ class FeedDatabase(object):
                        " WHERE closed IS NOT NULL ORDER BY closed DESC")
         obsolete = []
         for row in cursor.fetchall():
-            updated = self.Vote.timeobj(row['updated'])
+            updated = timeparse(row['updated'])
             if now - updated > datetime.timedelta(days = 30):
                 obsolete.append(row['sortkey'])
         if obsolete:

Modified: incubator/public/trunk/incuvoter/votestatus.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/incuvoter/votestatus.py?rev=1437985&r1=1437984&r2=1437985&view=diff
==============================================================================
--- incubator/public/trunk/incuvoter/votestatus.py (original)
+++ incubator/public/trunk/incuvoter/votestatus.py Thu Jan 24 13:03:08 2013
@@ -32,7 +32,7 @@ import cgi
 import datetime
 
 sys.path.insert(0, os.path.dirname(__file__))
-from incuvoter import FeedDatabase
+from incuvoter import FeedDatabase, timedate, timeparse
 
 
 __page_template = """\
@@ -89,7 +89,7 @@ __current_table = """\
   <table>
     <tr>
      <th>Subject</th>
-     <th>Latest Activity</th>
+     <th>Activity</th>
      <th>Started</th>
     </tr>
 %s
@@ -121,12 +121,15 @@ __closed_row = """\
     </tr>"""
 
 
+def __datescape(dateobject):
+  return cgi.escape(timedate(dateobject)).replace('-', '&ndash;')
+
 def refresh_page(target, database):
     current = []
     now = datetime.datetime.utcnow()
     for vote in database.list_open_votes():
-        updated = vote.timeobj(vote.updated)
-        noticed = vote.timeobj(vote.noticed)
+        updated = timeparse(vote.updated)
+        noticed = timeparse(vote.noticed)
         if (not isinstance(updated, datetime.datetime)
             or not isinstance(noticed, datetime.datetime)):
             klass = 'warn'
@@ -141,8 +144,8 @@ def refresh_page(target, database):
         current.append(__current_row
                        % dict(klass = klass,
                               subject = cgi.escape(vote.subject),
-                              updated = cgi.escape(vote.timefmt(updated)),
-                              noticed = cgi.escape(vote.timefmt(noticed))))
+                              updated = __datescape(updated),
+                              noticed = __datescape(noticed)))
     if current:
         current = __current_table % '\n'.join(current)
     else:
@@ -150,8 +153,8 @@ def refresh_page(target, database):
 
     resolved = []
     for vote in database.list_resolved_votes():
-        noticed = vote.timeobj(vote.noticed)
-        closed = vote.timeobj(vote.closed)
+        noticed = timeparse(vote.noticed)
+        closed = timeparse(vote.closed)
         if (not isinstance(noticed, datetime.datetime)
             or not isinstance(closed, datetime.datetime)):
             klass = 'warn'
@@ -160,8 +163,8 @@ def refresh_page(target, database):
         resolved.append(__closed_row
                         % dict(klass = klass,
                                subject = cgi.escape(vote.subject),
-                               noticed = cgi.escape(vote.timefmt(noticed)),
-                               closed = cgi.escape(vote.timefmt(closed))))
+                               noticed = __datescape(noticed),
+                               closed = __datescape(closed)))
     if resolved:
         resolved = __closed_table % '\n'.join(resolved)
     else:



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message