isolate code to get package versions from wsgi mechanics

This commit is contained in:
Frédéric Péters 2013-04-26 08:59:13 +02:00
parent b16fd40cb8
commit 1b2c8806c5
1 changed files with 10 additions and 6 deletions

View File

@ -24,12 +24,16 @@ class VersionMiddleware(object):
path += quote(environ.get('PATH_INFO', ''))
method = environ.get('REQUEST_METHOD', 'GET')
if method == 'GET' and path == '/__version__':
packages_version = {}
for distribution in tuple(pkg_resources.WorkingSet()):
project_name = distribution.project_name
version = distribution.version
if project_name in self.ENTROUVERT_PACKAGES:
packages_version[project_name] = version
packages_version = self.get_packages_version()
start_response('200 Ok', [('content-type', 'text/json')])
return [json.dumps(packages_version)]
return self.application(environ, start_response)
def get_packages_version(self):
packages_version = {}
for distribution in tuple(pkg_resources.WorkingSet()):
project_name = distribution.project_name
version = distribution.version
if project_name in self.ENTROUVERT_PACKAGES:
packages_version[project_name] = version
return packages_version