[snapshot/master] Expose removal log
---
web/app/snapshot/config/routing.py | 3 +
web/app/snapshot/controllers/removal.py | 92 ++++++++++++++++++++++
web/app/snapshot/lib/app_globals.py | 3 +
web/app/snapshot/model/snapshotmodel.py | 12 +++
web/app/snapshot/templates/removal-list-one.mako | 41 ++++++++++
web/app/snapshot/templates/removal-list.mako | 20 +++++
6 files changed, 171 insertions(+), 0 deletions(-)
create mode 100644 web/app/snapshot/controllers/removal.py
create mode 100644 web/app/snapshot/templates/removal-list-one.mako
create mode 100644 web/app/snapshot/templates/removal-list.mako
diff --git a/web/app/snapshot/config/routing.py b/web/app/snapshot/config/routing.py
index 83ea049..329d6c1 100644
--- a/web/app/snapshot/config/routing.py
+++ b/web/app/snapshot/config/routing.py
@@ -47,6 +47,9 @@ def make_map():
map.connect('/file/{hash}', controller='archive', action='file')
map.connect('/mr/file/{hash}/info', controller='package', action='mr_fileinfo')
+ map.connect('/removal/', controller='removal', action='root')
+ map.connect('/removal/{id}', controller='removal', action='one')
+
#map.connect('/{controller}/{action}')
#map.connect('/{controller}/{action}/{id}')
diff --git a/web/app/snapshot/controllers/removal.py b/web/app/snapshot/controllers/removal.py
new file mode 100644
index 0000000..2d59fc2
--- /dev/null
+++ b/web/app/snapshot/controllers/removal.py
@@ -0,0 +1,92 @@
+import logging
+
+from pylons import request, response, session, tmpl_context as c, g, config
+from pylons.controllers.util import abort, redirect_to, etag_cache
+
+from snapshot.lib.base import BaseController, render
+
+from snapshot.lib.dbinstance import DBInstance
+from snapshot.lib.control_helpers import *
+import os.path
+import re
+import urllib
+
+log = logging.getLogger(__name__)
+
+class RemovalController(BaseController):
+ db = None
+
+ def _db(self):
+ if self.db is None:
+ self.db = DBInstance(g.pool)
+ return self.db
+
+ def _db_close(self):
+ if not self.db is None:
+ self.db.close()
+
+ def _build_crumbs(self, entry=None):
+ crumbs = []
+
+ url = urllib.quote(request.environ.get('SCRIPT_NAME')) + "/"
+ crumbs.append( { 'url': url, 'name': 'snapshot.debian.org', 'sep': '|' });
+
+ url += 'removal/'
+ crumbs.append( { 'url': url, 'name': 'removal' });
+
+ if not entry is None:
+ entry=str(entry)
+ url += urllib.quote(entry)
+ crumbs.append( { 'url': url, 'name': entry, 'sep': '' });
+
+ crumbs[-1]['url'] = None
+ return crumbs
+
+ def root(self):
+ try:
+ set_expires(int(config['app_conf']['expires.removal']))
+ removals = g.shm.removal_get_list(self._db())
+
+ c.removals = removals
+ c.breadcrumbs = self._build_crumbs()
+ return render('/removal-list.mako')
+ finally:
+ self._db_close()
+
+ def one(self, id):
+ try:
+ try:
+ id = int(id)
+ except ValueError:
+ abort(404, 'No such log')
+
+ set_expires(int(config['app_conf']['expires.removal.one']))
+
+ removal = g.shm.removal_get_one(self._db(), id)
+ files = g.shm.removal_get_affected(self._db(), id)
+
+ fileinfo = {}
+ for hash in files:
+ fileinfo[hash] = g.shm.packages_get_file_info(self._db(), hash)
+ for hash in fileinfo:
+ fileinfo[hash] = map(lambda fi: dict(fi), fileinfo[hash])
+ for fi in fileinfo[hash]:
+ fi['dirlink'] = build_url_archive(fi['archive_name'], fi['run'], fi['path'])
+ fi['link'] = build_url_archive(fi['archive_name'], fi['run'], os.path.join(fi['path'], fi['name']), isadir=False )
+
+ files.sort(key=lambda a: (fileinfo[a][0]['name'], a)) # reproducible file order
+
+ c.removal = removal
+ c.files = files
+ c.fileinfo = fileinfo
+ c.breadcrumbs = self._build_crumbs(id)
+ c.title = 'Removal log #%d'%(id)
+ return render('/removal-list-one.mako')
+ finally:
+ self._db_close()
+
+
+
+# vim:set et:
+# vim:set ts=4:
+# vim:set shiftwidth=4:
diff --git a/web/app/snapshot/lib/app_globals.py b/web/app/snapshot/lib/app_globals.py
index ba3ab5d..4b61d19 100644
--- a/web/app/snapshot/lib/app_globals.py
+++ b/web/app/snapshot/lib/app_globals.py
@@ -34,6 +34,9 @@ class Globals(object):
default_expires['expires.package.mr.source_version'] = 300
default_expires['expires.root'] = 1800
+ default_expires['expires.removal'] = 1800
+ default_expires['expires.removal.one'] = 3600
+
for key in default_expires:
if not key in config['app_conf']: config['app_conf'][key] = default_expires[key]
diff --git a/web/app/snapshot/model/snapshotmodel.py b/web/app/snapshot/model/snapshotmodel.py
index 07205e2..9d60c80 100644
--- a/web/app/snapshot/model/snapshotmodel.py
+++ b/web/app/snapshot/model/snapshotmodel.py
@@ -347,6 +347,18 @@ class SnapshotModel:
rows = db.query("""SELECT DISTINCT name FROM srcpkg""")
return map(lambda x: x['name'], rows)
+ def removal_get_list(self, db):
+ rows = db.query("""SELECT removal_log_id, entry_added, reason FROM removal_log""")
+ return rows
+
+ def removal_get_one(self, db, id):
+ row = db.query_one("""SELECT removal_log_id, entry_added, reason FROM removal_log WHERE removal_log_id=%(removal_log_id)s""", {'removal_log_id': id})
+ return row
+
+ def removal_get_affected(self, db, id):
+ rows = db.query("""SELECT hash FROM removal_affects WHERE removal_log_id=%(removal_log_id)s""", {'removal_log_id': id})
+ return map(lambda x: x['hash'], rows)
+
# vim:set et:
# vim:set ts=4:
# vim:set shiftwidth=4:
diff --git a/web/app/snapshot/templates/removal-list-one.mako b/web/app/snapshot/templates/removal-list-one.mako
new file mode 100644
index 0000000..113dd20
--- /dev/null
+++ b/web/app/snapshot/templates/removal-list-one.mako
@@ -0,0 +1,41 @@
+<%inherit file="/page.mako" />
+
+<h1>Removal log #${c.removal['removal_log_id']}</h1>
+
+<p style="font-size: small">${c.removal['entry_added']}</p>
+<pre>${c.removal['reason']}</pre>
+
+<h1>Affected files</h1>
+
+<dl>
+ % for hash in c.files:
+ <dt style="font-size: x-small"><code>${hash}</code>:</dt>
+ % if hash in c.fileinfo:
+ <dd>
+ <dl>
+ % for fi in c.fileinfo[hash]:
+ <dt><a href="${fi['link']}"><code style="font-size: large"><strong>${fi['name']}</strong></code></a></dt>
+ <dd>
+ Seen in ${fi['archive_name']} on ${fi['run']} in
+ % if 'dirlink' in fi:
+ <a href="${fi['dirlink']}">${fi['path']}</a>.
+ % else:
+ ${fi['path']}.
+ % endif
+ <br />
+ Size: ${fi['size']}
+ </dd>
+ % endfor
+ </dl>
+ </dd>
+ % endif
+ %endfor
+</dl>
+
+
+<hr style="height:1px;" />
+<p style="font-size: small">(This information is only correct on snapshot-master)</p>
+
+## vim:syn=html
+## vim:set ts=4:
+## vim:set shiftwidth=4:
diff --git a/web/app/snapshot/templates/removal-list.mako b/web/app/snapshot/templates/removal-list.mako
new file mode 100644
index 0000000..4c476a3
--- /dev/null
+++ b/web/app/snapshot/templates/removal-list.mako
@@ -0,0 +1,20 @@
+<%inherit file="/page.mako" />
+
+<h1>Removal log</h1>
+
+<dl>
+%for e in c.removals:
+ <dt style="font-size: small">${e['entry_added']}</dt>
+ <dd>
+ <pre>${e['reason']}</pre>
+ <p style="font-size: x-small">[<a href="${e['removal_log_id']}">affected files]</a></p>
+ </dd>
+%endfor
+</dl>
+
+<hr style="height:1px;" />
+<p style="font-size: small">(This information is only correct on snapshot-master)</p>
+
+## vim:syn=html
+## vim:set ts=4:
+## vim:set shiftwidth=4:
--
1.5.6.5
Reply to: