isolate code to get package versions from wsgi mechanics
This commit is contained in:
parent
b16fd40cb8
commit
1b2c8806c5
|
@ -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
|
||||
|
|
Reference in New Issue