oops, missed this bit. the rest ofbug 464018 - unify url params for pushlog, json-pushes
authorTed Mielczarek <ted.mielczarek@gmail.com>
Fri, 21 Nov 2008 10:11:11 -0500
changeset 50 3b7407f0c22c
parent 49 802d27b80d59
child 51 ecae76413277
push id24
push usertmielczarek@mozilla.com
push dateFri, 21 Nov 2008 15:11:14 +0000
bugs464018
oops, missed this bit. the rest ofbug 464018 - unify url params for pushlog, json-pushes
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -32,40 +32,38 @@ def addcommand(f, name):
 def addwebcommand(f, name):
     setattr(hgwebcommands, name, f)
     hgwebcommands.__all__.append(name)
 
 ATOM_MIMETYPE = 'application/atom+xml'
 
 # just an enum
 class QueryType:
-    DATE = 0
-    CHANGESET = 1
-    PUSHID = 2
-    COUNT = 3
+    DATE, CHANGESET, PUSHID, COUNT = range(4)
 
 class PushlogQuery:
-    def __init__(self, urlbase='', repo=None, dbconn=None, tipsonly=False, reponame='', page=1, dates=[]):
+    page = 1
+    dates = []
+    entries = []
+    totalentries = 1
+    # by default, we return the last 10 pushes
+    querystart = QueryType.COUNT
+    querystart_value = PUSHES_PER_PAGE
+    # don't need a default here, since by default
+    # we'll get everything newer than whatever your start
+    # query is
+    queryend = None
+    queryend_value = None
+
+    def __init__(self, repo, dbconn, urlbase='', tipsonly=False, reponame=''):
         self.repo = repo
         self.conn = dbconn
         self.urlbase = urlbase
         self.tipsonly = tipsonly
         self.reponame = reponame
-        self.page = page
-        self.dates = dates
-        self.entries = []
-        self.totalentries = 1
-        # by default, we return the last 10 pushes
-        self.querystart = QueryType.COUNT
-        self.querystart_value = PUSHES_PER_PAGE
-        # don't need a default here, since by default
-        # we'll get everything newer than whatever your start
-        # query is
-        self.queryend = QueryType.COUNT
-        self.queryend_value = 0
 
     def DoQuery(self):
         """Figure out what the query parameters are, and query the database
         using those parameters."""
         self.entries = []
         if self.querystart == QueryType.COUNT:
             # Get entries from self.page, using self.querystart_value as
             # the number of pushes per page.
@@ -118,16 +116,36 @@ class PushlogQuery:
                     if self.tipsonly and id == lastid:
                         continue
                     self.entries.append((id,user,date,node))
                     lastid = id
             except sqlite.OperationalError:
                 # likely just an empty db, so return an empty result
                 pass
 
+    def description(self):
+        if self.querystart == QueryType.COUNT:
+            return ''
+        bits = []
+        isotime = lambda x: datetime.utcfromtimestamp(x).isoformat(' ')
+        if self.querystart == QueryType.DATE:
+            bits.append('after %s' % isotime(self.querystart_value))
+        elif self.querystart == QueryType.CHANGESET:
+            bits.append('after changeset %s' % self.querystart_value)
+        elif self.querystart == QueryType.PUSHID:
+            bits.append('after push ID %s' % self.querystart_value)
+
+        if self.queryend == QueryType.DATE:
+            bits.append('before %s' % isotime(self.queryend_value))
+        elif self.queryend == QueryType.CHANGESET:
+            bits.append('up to and including changeset %s' % self.queryend_value)
+        elif self.queryend == QueryType.PUSHID:
+            bits.append('up to and including push ID %s' % self.queryend_value)
+        return 'Changes pushed ' + ', '.join(bits)
+
 def localdate(ts):
     """Given a timestamp, return a (timestamp, tzoffset) tuple,
     which is what Mercurial works with. Attempts to get DST
     correct as well."""
     t = time.localtime(ts)
     offset = time.timezone
     if t[8] == 1:
         offset = time.altzone
@@ -175,43 +193,39 @@ def pushlogSetup(repo, req):
     tipsonly = False
     if 'tipsonly' in req.form and req.form['tipsonly'][0] == '1':
         tipsonly = True
 
     query = PushlogQuery(urlbase='%s://%s%s' % (proto, req.env['SERVER_NAME'], port),
                          repo=repo,
                          dbconn=conn,
                          tipsonly=tipsonly,
-                         reponame=reponame,
-                         page=page)
+                         reponame=reponame)
+    query.page = page
 
     # find start component
     if 'startdate' in req.form:
         startdate = doParseDate(req.form['startdate'][0])
         query.querystart = QueryType.DATE
         query.querystart_value = startdate
-        #TODO: figure out how to make this not suck
-        #query.dates = [{'startdate':localdate(startdate)}]
     elif 'fromchange' in req.form:
         query.querystart = QueryType.CHANGESET
         query.querystart_value = req.form.get('fromchange', ['null'])[0]
     elif 'startID' in req.form:
         query.querystart = QueryType.PUSHID
         query.querystart_value = req.form.get('startID', ['0'])[0]
     else:
         # default is last 10 pushes
         query.querystart = QueryType.COUNT
         query.querystart_value = PUSHES_PER_PAGE
 
     if 'enddate' in req.form:
         enddate = doParseDate(req.form['enddate'][0])
         query.queryend = QueryType.DATE
         query.queryend_value = enddate
-        #XXX: breaks if not using startdate!
-        #query.dates['enddate'] =  localdate(enddate)
     elif 'tochange' in req.form:
         query.queryend = QueryType.CHANGESET
         query.queryend_value = req.form.get('tochange', ['default'])[0]
     elif 'endID' in req.form:
         query.queryend = QueryType.PUSHID
         query.queryend_value = req.form.get('endID', [None])[0]
 
     query.DoQuery()
@@ -339,30 +353,24 @@ def pushlogHTML(web, req, tmpl):
         if limit > 0:
             l = l[:limit]
 
         for e in l:
             yield e
 
     parity = paritygen(web.stripecount)
 
-    if 'startdate' in req.form and 'enddate' in req.form:
-        startdate = req.form['startdate']
-        enddate = req.form['enddate']
-    else:
-        startdate = "1 week ago"
-        enddate = "now"
     return tmpl('pushlog',
                 changenav=changenav(),
                 rev=0,
                 entries=lambda **x: changelist(limit=0,**x),
                 latestentry=lambda **x: changelist(limit=1,**x),
-                startdate=startdate,
-                enddate=enddate,
-                query=query.dates,
+                startdate='startdate' in req.form and req.form['startdate'] or '1 week ago',
+                enddate='enddate' in req.form and req.form['enddate'] or 'now',
+                querydescription=query.description(),
                 archives=web.archivelist("tip"))
 
 def pushes_worker(query):
     """Given a PushlogQuery, return a data structure mapping push IDs
     to a map of data about the push."""
     pushes = {}
     for id, user, date, node in query.entries:
         if id in pushes: