aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2009-08-28 22:52:10 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2009-08-28 22:52:10 +0000
commit0d1e888a0b964695420b561c54bcc3c113d8a9b9 (patch)
treeaa435c9b4f6b929f5d68aae58d5544c30b51f756 /web
parentAllow excess whitespace between "bug" and the bug number. (diff)
downloadpackages-0d1e888a0b964695420b561c54bcc3c113d8a9b9.tar.gz
packages-0d1e888a0b964695420b561c54bcc3c113d8a9b9.tar.bz2
packages-0d1e888a0b964695420b561c54bcc3c113d8a9b9.zip
Bug #233104: support for /data/YYYYMMDD/ pages. Thanks to manuel.schoelling@gmx.de.
Diffstat (limited to 'web')
-rw-r--r--web/controller.py59
-rw-r--r--web/lib/filters.py11
-rw-r--r--web/lib/query_filter.py2
-rw-r--r--web/model.py38
4 files changed, 108 insertions, 2 deletions
diff --git a/web/controller.py b/web/controller.py
index 7e56b1e..712fbdc 100644
--- a/web/controller.py
+++ b/web/controller.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""Packages2 CherryPy Application and launcher"""
-import os, sys, math
+import os, sys, math, time
import cherrypy
@@ -47,6 +47,13 @@ class Root(object):
return self.database.mc_wrap('cache_verbumps', f, time=300)
@property
+ def cache_date(self):
+ def f():
+ entry_filter = filters.EntryFilters(self.database)
+ return entry_filter.date_filter()
+ return self.database.mc_wrap('cache_date', f, time=300)
+
+ @property
def cache_categories(self):
def f():
return self.database.get_category_list()
@@ -409,6 +416,53 @@ class Root(object):
@cherrypy.expose
@template.expire_on_30_min()
+ @template.output('index.html', method='xhtml')
+ def date(self, *args, **kwds):
+ """Render the /date/<date> page as HTML"""
+ # Do not complain about correct usage of ** magic
+ # pylint: disable-msg=W0142
+ return self._date(*args, **kwds)
+
+ def _date(self, *args, **kwds):
+ """Render the /date/<date> page per the caller"""
+ date = ''
+ if len(args) == 1:
+ try:
+ date = time.strptime(args[0][0:8]+" UTC", "%Y%m%d %Z")
+ pagetitle = time.strftime("/date/%Y%m%d",date)
+ except:
+ date = ''
+ if date == '':
+ raise cherrypy.HTTPRedirect("/")
+
+ db = self.database
+ entry_filter = filters.EntryFilters(db)
+ package_entries = entry_filter.date_filter(date)
+
+ center_pkgs = build_centerpkg_list(package_entries,
+ db.get_package_details_cpv, None)
+# Empty resultsets are allowed
+# if not center_pkgs:
+# raise cherrypy.HTTPRedirect("/")
+
+ left_entrylist = self.cache_latest
+ left_daycount = filters.limit_leftcount(kwds)
+ arches = filters.limit_arches(kwds)
+
+ day_list = latest_per_day(left_entrylist, left_daycount)
+
+ latest_entry = entry_filter.latest_entry()
+ http_lastmodified = lastmodified_httpheader(latest_entry)
+ cherrypy.response.headers['Last-Modified'] = http_lastmodified
+ kwds = sanitize_query_string(kwds)
+ db.close_mc()
+ return template.render(arches = arches,
+ daylist = day_list, center_pkgs = center_pkgs,
+ lastupdate = latest_entry, pagetitle = pagetitle,
+ safeqs = kwds)
+
+ @cherrypy.expose
+ @template.expire_on_30_min()
@template.output('index.xml', method='xml')
def feed(self, *args, **kwds):
"""Render the /feed/<someurl> page as Atom"""
@@ -431,10 +485,13 @@ class Root(object):
return self._verbump(*args, **kwds)
elif base == "newpackage":
return self._newpackage(*args, **kwds)
+ elif base == "date":
+ return self._date(*args, **kwds)
else:
raise Exception('Unknown page!')
+
def database_connect():
"""Create a DB connection and store it in the current thread"""
from etc.database_config import DatabaseConfig
diff --git a/web/lib/filters.py b/web/lib/filters.py
index 8f28147..21709af 100644
--- a/web/lib/filters.py
+++ b/web/lib/filters.py
@@ -159,6 +159,17 @@ class EntryFilters(object):
"""Filter packages to new packages only (uncached)"""
return self.package_source.get_latest_cpvs_by_newpkg(limit)
+ def date_filter(self, date, limit=None):
+ """Filter packages to new by date only"""
+ key = 'date_filter_%r%r' % (date, limit, )
+ def f():
+ return self._date_filter(date, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
+
+ def _date_filter(self, date, limit=None):
+ """Filter packages to new packages only since date (uncached)"""
+ return self.package_source.get_latest_cpvs_by_date(date, limit)
+
def unfiltered(self, limit=None):
"""unfiltered list"""
key = 'unfiltered_%r' % (limit, )
diff --git a/web/lib/query_filter.py b/web/lib/query_filter.py
index 4b44fc2..89347ad 100644
--- a/web/lib/query_filter.py
+++ b/web/lib/query_filter.py
@@ -105,6 +105,8 @@ def create_rel(path):
t = 'Version bumps'
elif path.startswith('/newpackage'):
t = 'New packages'
+ elif path.startswith('/date'):
+ t = 'New packages since a selected date'
elif path.startswith('/faq'):
t = 'FAQ'
rsspath = None
diff --git a/web/model.py b/web/model.py
index 6c64472..39de032 100644
--- a/web/model.py
+++ b/web/model.py
@@ -1,4 +1,4 @@
-from time import localtime, strftime, time
+from time import localtime, strftime, time, mktime
import datetime
import re, sys
import operator
@@ -314,6 +314,42 @@ class PackageDB(object):
return self._get_latest_cpvs_by_pkgname(pkgname, limit)
return self.mc_wrap(key, f)
+ sql['SELECT_get_latest_cpvs_by_date'] = """
+ SELECT __CPV__, verbumps.mtime
+ FROM verbumps
+ JOIN versions USING(cpv)
+ JOIN metadata USING(cp)
+ JOIN packages USING (cp)
+ JOIN categories USING (c)
+ WHERE verbumps.mtime > ? AND verbumps.newpkg = 1
+ ORDER by verbumps.mtime DESC
+ LIMIT 0, ?
+ """
+ def get_latest_cpvs_by_date(self, date, limit=None):
+ """return new cpvs since date"""
+ # We cannot rely on the contents of ChangeLog here
+ # otherwise we could add this bit of magic:
+ # AND SUBSTR(metadata.changelog,1,1)='*'
+
+ sql = self.sql['SELECT_get_latest_cpvs_by_date']
+
+ i = self.get_latest_timestamp()
+ if i is None:
+ i = time.time()
+ datetime = mktime(date)
+ if limit is None:
+ limit = 300
+ try:
+ params = (datetime, int(limit), )
+ except ValueError:
+ return []
+
+ cursor = self.cursor()
+ cursor.execute(sql, params)
+ entries = cursor.fetchall()
+ cursor.close()
+ return entries
+
sql['SELECT_get_latest_cpvs_by_pkgname'] = """
SELECT __CPV__, versions.mtime
FROM versions