[snapshot/master] Get rid of deprecated pylons.g, instead use pylons.app_globals
---
web/app/snapshot/controllers/archive.py | 28 ++++++++--------
web/app/snapshot/controllers/misc.py | 4 +-
web/app/snapshot/controllers/package.py | 52 +++++++++++++++---------------
web/app/snapshot/controllers/removal.py | 14 ++++----
web/app/snapshot/controllers/root.py | 12 +++---
web/app/snapshot/templates/page.mako | 8 ++--
6 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/web/app/snapshot/controllers/archive.py b/web/app/snapshot/controllers/archive.py
index eba5509..e639491 100644
--- a/web/app/snapshot/controllers/archive.py
+++ b/web/app/snapshot/controllers/archive.py
@@ -22,7 +22,7 @@
import logging
-from pylons import request, response, session, tmpl_context as c, g, config
+from pylons import request, response, session, tmpl_context as c, app_globals, config
from pylons.controllers.util import abort, redirect_to, etag_cache
from snapshot.lib.base import BaseController, render
@@ -72,7 +72,7 @@ class ArchiveController(BaseController):
def _db(self):
if self.db is None:
- self.db = DBInstance(g.pool)
+ self.db = DBInstance(app_globals.pool)
return self.db
def _db_close(self):
@@ -87,7 +87,7 @@ class ArchiveController(BaseController):
def archive_base(self, archive):
try:
- #etag_cache( g.shm.mirrorruns_get_etag(self._db(), archive) )
+ #etag_cache( app_globals.shm.mirrorruns_get_etag(self._db(), archive) )
set_expires(int(config['app_conf']['expires.archive.index']))
if 'year' in request.params and 'month' in request.params:
@@ -95,7 +95,7 @@ class ArchiveController(BaseController):
m = request.params['month']
return self._archive_ym(archive, y, m)
- yearmonths = g.shm.mirrorruns_get_yearmonths_from_archive(self._db(), archive)
+ yearmonths = app_globals.shm.mirrorruns_get_yearmonths_from_archive(self._db(), archive)
if yearmonths is None:
abort(404, 'Archive "%s" does not exist'%(archive))
@@ -114,7 +114,7 @@ class ArchiveController(BaseController):
if not re.match('\d{1,2}$', month): # match matches only at start of string
abort(404, 'Month "%s" is not valid.'%(month))
- runs = g.shm.mirrorruns_get_runs_from_archive_ym(self._db(), archive, year, month)
+ runs = app_globals.shm.mirrorruns_get_runs_from_archive_ym(self._db(), archive, year, month)
if runs is None:
abort(404, 'Archive "%s" does not exist'%(archive))
if len(runs) == 0:
@@ -134,7 +134,7 @@ class ArchiveController(BaseController):
def _regular_file(self, digest, visiblepath=None):
try:
- realpath = g.shm.get_filepath(digest)
+ realpath = app_globals.shm.get_filepath(digest)
fa = SnapshotFileApp(realpath, digest, visiblepath)
return fa(request.environ, self.start_response)
except OSError, error:
@@ -153,7 +153,7 @@ class ArchiveController(BaseController):
crumbs = []
url = request.environ.get('SCRIPT_NAME') + "/"
- crumbs.append( { 'url': url, 'name': g.domain, 'sep': '|' });
+ crumbs.append( { 'url': url, 'name': app_globals.domain, 'sep': '|' });
crumbs.append( { 'url': None, 'name': 'archive:', 'sep': '' });
@@ -190,7 +190,7 @@ class ArchiveController(BaseController):
url = construct_url(request.environ)
raise HTTPMovedPermanently(url)
- list = g.shm.mirrorruns_readdir(self._db(), run['mirrorrun_id'], stat['path'])
+ list = app_globals.shm.mirrorruns_readdir(self._db(), run['mirrorrun_id'], stat['path'])
list = map(lambda b: dict(b), list)
for e in list:
e['quoted_name'] = urllib.quote(e['name'])
@@ -199,9 +199,9 @@ class ArchiveController(BaseController):
if stat['path'] != '/':
list = [ { 'filetype': 'd', 'name': '..', 'quoted_name': '..', 'first_run': None, 'last_run': None } ] + list
- node_info = g.shm.mirrorruns_get_first_last_from_node(self._db(), stat['node_id'])
- neighbors = g.shm.mirrorruns_get_neighbors(self._db(), run['mirrorrun_id'])
- neighbors_change = g.shm.mirrorruns_get_neighbors_change(self._db(), run['archive_id'], run['run'], stat['directory_id'])
+ node_info = app_globals.shm.mirrorruns_get_first_last_from_node(self._db(), stat['node_id'])
+ neighbors = app_globals.shm.mirrorruns_get_neighbors(self._db(), run['mirrorrun_id'])
+ neighbors_change = app_globals.shm.mirrorruns_get_neighbors_change(self._db(), run['archive_id'], run['run'], stat['directory_id'])
c.run = run
c.readdir = list
@@ -242,17 +242,17 @@ class ArchiveController(BaseController):
def dir(self, archive, date, url):
try:
- #etag_cache( g.shm.mirrorruns_get_etag(self._db(), archive) )
+ #etag_cache( app_globals.shm.mirrorruns_get_etag(self._db(), archive) )
set_expires(int(config['app_conf']['expires.archive.dir']))
if not self._dateok(date):
abort(404, 'Invalid date string - nothing to be found here.')
- run = g.shm.mirrorruns_get_mirrorrun_at(self._db(), archive, date)
+ run = app_globals.shm.mirrorruns_get_mirrorrun_at(self._db(), archive, date)
if run is None:
abort(404, 'No mirrorrun found at this date.')
- stat = g.shm.mirrorruns_stat(self._db(), run['mirrorrun_id'], '/'+url)
+ stat = app_globals.shm.mirrorruns_stat(self._db(), run['mirrorrun_id'], '/'+url)
if stat is None:
abort(404, 'No such file or directory.')
diff --git a/web/app/snapshot/controllers/misc.py b/web/app/snapshot/controllers/misc.py
index 45d3e65..8e6c6ca 100644
--- a/web/app/snapshot/controllers/misc.py
+++ b/web/app/snapshot/controllers/misc.py
@@ -36,10 +36,10 @@ class MiscController(BaseController):
def trace(self):
db = None
try:
- db = DBInstance(g.pool)
+ db = DBInstance(app_globals.pool)
set_expires(int(config['app_conf']['expires.root']))
- last = g.shm.get_last_mirrorrun(db)
+ last = app_globals.shm.get_last_mirrorrun(db)
content = []
content.append("%s\n"%(last.ctime()))
diff --git a/web/app/snapshot/controllers/package.py b/web/app/snapshot/controllers/package.py
index 139761f..848c40a 100644
--- a/web/app/snapshot/controllers/package.py
+++ b/web/app/snapshot/controllers/package.py
@@ -22,7 +22,7 @@
import logging
-from pylons import request, response, session, tmpl_context as c, g, config
+from pylons import request, response, session, tmpl_context as c, app_globals, config
from pylons.controllers.util import abort, redirect_to, etag_cache
from snapshot.lib.base import BaseController, render
@@ -42,7 +42,7 @@ class PackageController(BaseController):
def _db(self):
if self.db is None:
- self.db = DBInstance(g.pool)
+ self.db = DBInstance(app_globals.pool)
return self.db
def _db_close(self):
@@ -53,7 +53,7 @@ class PackageController(BaseController):
crumbs = []
url = urllib.quote(request.environ.get('SCRIPT_NAME')) + "/"
- crumbs.append( { 'url': url, 'name': g.domain, 'sep': '|' });
+ crumbs.append( { 'url': url, 'name': app_globals.domain, 'sep': '|' });
if is_binary:
crumbs.append( { 'url': None, 'name': 'binary package:', 'sep': '' });
@@ -103,11 +103,11 @@ class PackageController(BaseController):
return redirect_to(url)
elif 'cat' in request.params:
try:
- #etag_cache( g.shm.packages_get_etag(self._db()) )
+ #etag_cache( app_globals.shm.packages_get_etag(self._db()) )
set_expires(int(config['app_conf']['expires.package.root_cat']))
start = request.params['cat']
- pkgs = g.shm.packages_get_name_starts_with(self._db(), start)
+ pkgs = app_globals.shm.packages_get_name_starts_with(self._db(), start)
if pkgs is None:
abort(404, 'No source packages in this category.')
c.start = start
@@ -124,10 +124,10 @@ class PackageController(BaseController):
def source(self, source):
self._ensure_ascii(source)
try:
- #etag_cache( g.shm.packages_get_etag(self._db()) )
+ #etag_cache( app_globals.shm.packages_get_etag(self._db()) )
set_expires(int(config['app_conf']['expires.package.source']))
- sourceversions = g.shm.packages_get_source_versions(self._db(), source)
+ sourceversions = app_globals.shm.packages_get_source_versions(self._db(), source)
if len(sourceversions) == 0:
abort(404, 'No such source package')
@@ -146,11 +146,11 @@ class PackageController(BaseController):
def source_version(self, source, version):
self._ensure_ascii(source)
try:
- #etag_cache( g.shm.packages_get_etag(self._db()) )
+ #etag_cache( app_globals.shm.packages_get_etag(self._db()) )
set_expires(int(config['app_conf']['expires.package.source_version']))
- sourcefiles = g.shm.packages_get_source_files(self._db(), source, version)
- binpkgs = g.shm.packages_get_binpkgs_from_source(self._db(), source, version)
+ sourcefiles = app_globals.shm.packages_get_source_files(self._db(), source, version)
+ binpkgs = app_globals.shm.packages_get_binpkgs_from_source(self._db(), source, version)
# we may have binaries without sources.
if len(sourcefiles) == 0 and len(binpkgs) == 0:
@@ -161,12 +161,12 @@ class PackageController(BaseController):
for binpkg in binpkgs:
binpkg['escaped_name'] = self._attribute_escape(binpkg['name'])
binpkg['escaped_version'] = self._attribute_escape(binpkg['version'])
- binpkg['files'] = map(lambda x: x['hash'], g.shm.packages_get_binary_files_from_id(self._db(), binpkg['binpkg_id']))
+ binpkg['files'] = map(lambda x: x['hash'], app_globals.shm.packages_get_binary_files_from_id(self._db(), binpkg['binpkg_id']))
binhashes += binpkg['files']
fileinfo = {}
for hash in sourcefiles + binhashes:
- fileinfo[hash] = g.shm.packages_get_file_info(self._db(), hash)
+ fileinfo[hash] = app_globals.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]:
@@ -193,11 +193,11 @@ class PackageController(BaseController):
return redirect_to(url)
elif 'cat' in request.params:
try:
- #etag_cache( g.shm.packages_get_etag(self._db()) )
+ #etag_cache( app_globals.shm.packages_get_etag(self._db()) )
set_expires(int(config['app_conf']['expires.package.root_cat']))
start = request.params['cat']
- pkgs = g.shm.packages_get_name_starts_with(self._db(), start, get_binary=True)
+ pkgs = app_globals.shm.packages_get_name_starts_with(self._db(), start, get_binary=True)
if pkgs is None:
abort(404, 'No binary packages in this category.')
c.start = start
@@ -215,10 +215,10 @@ class PackageController(BaseController):
self._ensure_ascii(binary)
try:
- #etag_cache( g.shm.packages_get_etag(self._db()) )
+ #etag_cache( app_globals.shm.packages_get_etag(self._db()) )
set_expires(int(config['app_conf']['expires.package.source']))
- binaryversions = g.shm.packages_get_binary_versions_by_name(self._db(), binary)
+ binaryversions = app_globals.shm.packages_get_binary_versions_by_name(self._db(), binary)
if len(binaryversions) == 0:
abort(404, 'No such binary package')
@@ -239,7 +239,7 @@ class PackageController(BaseController):
def _get_fileinfo_for_mr_one(self, hash):
- fileinfo = map(lambda x: dict(x), g.shm.packages_get_file_info(self._db(), hash))
+ fileinfo = map(lambda x: dict(x), app_globals.shm.packages_get_file_info(self._db(), hash))
for fi in fileinfo:
fi['first_seen'] = rfc3339_timestamp(fi['run'])
del fi['run']
@@ -255,7 +255,7 @@ class PackageController(BaseController):
def mr_list(self):
try:
set_expires(int(config['app_conf']['expires.package.mr.list']))
- pkgs = g.shm.packages_get_all(self._db())
+ pkgs = app_globals.shm.packages_get_all(self._db())
return { '_comment': "foo",
'result': map(lambda x: { 'package': x }, pkgs) }
finally:
@@ -265,7 +265,7 @@ class PackageController(BaseController):
def mr_source(self, source):
try:
set_expires(int(config['app_conf']['expires.package.mr.source']))
- sourceversions = g.shm.packages_get_source_versions(self._db(), source)
+ sourceversions = app_globals.shm.packages_get_source_versions(self._db(), source)
if len(sourceversions) == 0: abort(404, 'No such source package')
return { '_comment': "foo",
'package': source,
@@ -277,7 +277,7 @@ class PackageController(BaseController):
def mr_source_version_srcfiles(self, source, version):
try:
set_expires(int(config['app_conf']['expires.package.mr.source_version']))
- sourcefiles = g.shm.packages_get_source_files(self._db(), source, version)
+ sourcefiles = app_globals.shm.packages_get_source_files(self._db(), source, version)
if len(sourcefiles) == 0: abort(404, 'No such source package or no sources found')
r = { '_comment': "foo",
'package': source,
@@ -293,7 +293,7 @@ class PackageController(BaseController):
def mr_source_version_binpackages(self, source, version):
try:
set_expires(int(config['app_conf']['expires.package.mr.source_version']))
- binpkgs = g.shm.packages_get_binpkgs_from_source(self._db(), source, version)
+ binpkgs = app_globals.shm.packages_get_binpkgs_from_source(self._db(), source, version)
if len(binpkgs) == 0: abort(404, 'No such source package or no binary packages found')
binpkgs = map(lambda b: { 'name': b['name'],
'version': b['version'] }, binpkgs)
@@ -308,7 +308,7 @@ class PackageController(BaseController):
def mr_source_version_binfiles(self, source, version, binary, binary_version):
try:
set_expires(int(config['app_conf']['expires.package.mr.source_version']))
- binfiles = g.shm.packages_get_binary_files_from_packagenames(self._db(), source, version, binary, binary_version)
+ binfiles = app_globals.shm.packages_get_binary_files_from_packagenames(self._db(), source, version, binary, binary_version)
if len(binfiles) == 0: abort(404, 'No such package or no binary files found')
binfiles = map(lambda b: dict(b), binfiles)
r = { '_comment': "foo",
@@ -327,8 +327,8 @@ class PackageController(BaseController):
def mr_source_version_allfiles(self, source, version):
try:
set_expires(int(config['app_conf']['expires.package.mr.source_version']))
- sourcefiles = g.shm.packages_get_source_files(self._db(), source, version)
- binpkgs = g.shm.packages_get_binpkgs_from_source(self._db(), source, version)
+ sourcefiles = app_globals.shm.packages_get_source_files(self._db(), source, version)
+ binpkgs = app_globals.shm.packages_get_binpkgs_from_source(self._db(), source, version)
# we may have binaries without sources.
if len(sourcefiles) == 0 and len(binpkgs) == 0:
abort(404, 'No source or binary packages found')
@@ -336,7 +336,7 @@ class PackageController(BaseController):
binhashes = []
for binpkg in binpkgs:
- binpkg['files'] = map(lambda x: dict(x), g.shm.packages_get_binary_files_from_id(self._db(), binpkg['binpkg_id']))
+ binpkg['files'] = map(lambda x: dict(x), app_globals.shm.packages_get_binary_files_from_id(self._db(), binpkg['binpkg_id']))
del binpkg['binpkg_id']
binhashes += map(lambda x: x['hash'], binpkg['files'])
@@ -355,7 +355,7 @@ class PackageController(BaseController):
def mr_binary(self, binary):
try:
set_expires(int(config['app_conf']['expires.package.mr.source']))
- binaryversions = g.shm.packages_get_binary_versions_by_name(self._db(), binary)
+ binaryversions = app_globals.shm.packages_get_binary_versions_by_name(self._db(), binary)
binaryversions = map(lambda b: dict(b), binaryversions)
if len(binaryversions) == 0: abort(404, 'No such binary package')
r = { '_comment': "foo",
diff --git a/web/app/snapshot/controllers/removal.py b/web/app/snapshot/controllers/removal.py
index 9e1f9d8..2ad83c6 100644
--- a/web/app/snapshot/controllers/removal.py
+++ b/web/app/snapshot/controllers/removal.py
@@ -22,7 +22,7 @@
import logging
-from pylons import request, response, session, tmpl_context as c, g, config
+from pylons import request, response, session, tmpl_context as c, app_globals, config
from pylons.controllers.util import abort, redirect_to, etag_cache
from snapshot.lib.base import BaseController, render
@@ -40,7 +40,7 @@ class RemovalController(BaseController):
def _db(self):
if self.db is None:
- self.db = DBInstance(g.pool)
+ self.db = DBInstance(app_globals.pool)
return self.db
def _db_close(self):
@@ -51,7 +51,7 @@ class RemovalController(BaseController):
crumbs = []
url = urllib.quote(request.environ.get('SCRIPT_NAME')) + "/"
- crumbs.append( { 'url': url, 'name': g.domain, 'sep': '|' });
+ crumbs.append( { 'url': url, 'name': app_globals.domain, 'sep': '|' });
url += 'removal/'
crumbs.append( { 'url': url, 'name': 'removal' });
@@ -67,7 +67,7 @@ class RemovalController(BaseController):
def root(self):
try:
set_expires(int(config['app_conf']['expires.removal']))
- removals = g.shm.removal_get_list(self._db())
+ removals = app_globals.shm.removal_get_list(self._db())
c.removals = removals
c.breadcrumbs = self._build_crumbs()
@@ -84,14 +84,14 @@ class RemovalController(BaseController):
set_expires(int(config['app_conf']['expires.removal.one']))
- removal = g.shm.removal_get_one(self._db(), id)
+ removal = app_globals.shm.removal_get_one(self._db(), id)
if not removal:
abort(404, 'No such log.')
- files = g.shm.removal_get_affected(self._db(), id)
+ files = app_globals.shm.removal_get_affected(self._db(), id)
fileinfo = {}
for hash in files:
- fileinfo[hash] = g.shm.packages_get_file_info(self._db(), hash)
+ fileinfo[hash] = app_globals.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]:
diff --git a/web/app/snapshot/controllers/root.py b/web/app/snapshot/controllers/root.py
index 1f1c5d0..4272977 100644
--- a/web/app/snapshot/controllers/root.py
+++ b/web/app/snapshot/controllers/root.py
@@ -22,7 +22,7 @@
import logging
-from pylons import request, response, session, tmpl_context as c, g, config
+from pylons import request, response, session, tmpl_context as c, app_globals, config
from pylons.controllers.util import abort, redirect_to
from snapshot.lib.base import BaseController, render
@@ -36,10 +36,10 @@ class RootController(BaseController):
def index(self):
db = None
try:
- db = DBInstance(g.pool)
- c.names = link_quote_array(g.shm.archives_get_list(db))
- c.srcstarts = link_quote_array(g.shm.packages_get_name_starts(db))
- c.binstarts = link_quote_array(g.shm.packages_get_name_starts(db, get_binary=True))
+ db = DBInstance(app_globals.pool)
+ c.names = link_quote_array(app_globals.shm.archives_get_list(db))
+ c.srcstarts = link_quote_array(app_globals.shm.packages_get_name_starts(db))
+ c.binstarts = link_quote_array(app_globals.shm.packages_get_name_starts(db, get_binary=True))
set_expires(int(config['app_conf']['expires.root']))
return render('/root.mako')
finally:
@@ -50,7 +50,7 @@ class RootController(BaseController):
crumbs = []
url = urllib.quote(request.environ.get('SCRIPT_NAME')) + "/"
- crumbs.append( { 'url': url, 'name': g.domain });
+ crumbs.append( { 'url': url, 'name': app_globals.domain });
if not page is None:
crumbs.append( { 'url': None, 'name': page, 'sep': '' });
diff --git a/web/app/snapshot/templates/page.mako b/web/app/snapshot/templates/page.mako
index 1d38b53..6a42b13 100644
--- a/web/app/snapshot/templates/page.mako
+++ b/web/app/snapshot/templates/page.mako
@@ -3,16 +3,16 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
% if c.title == "":
- <title>${g.domain}</title>
+ <title>${app_globals.domain}</title>
% else:
- <title>${c.title} - ${g.domain}</title>
+ <title>${c.title} - ${app_globals.domain}</title>
% endif
<link rel="stylesheet" type="text/css" href="/static/style.css" />
<link rel="icon" type="image/vnd.microsoft.icon" href="/static/favicon.ico" />
</head>
<body>
<div id="top">
- <a id="logo" href="http://${g.domain}"><img src="/static/images/top.png" alt="${g.domain}" width="644" height="71"/></a>
+ <a id="logo" href="http://${app_globals.domain}"><img src="/static/images/top.png" alt="${app_globals.domain}" width="644" height="71"/></a>
</div>
% if not c.breadcrumbs is UNDEFINED and (len(c.breadcrumbs) != 0):
<div id="pageheader">
@@ -56,7 +56,7 @@ ${self.body()}
import datetime
now = datetime.datetime.now()
%>
- Built at ${now} on ${g.thishost}
+ Built at ${now} on ${app_globals.thishost}
<br />
<a href="http://validator.w3.org/check?uri=referer">validate</a>
</div>
--
1.7.2.5
Reply to: