reuse environment variable

This commit is contained in:
Martin Zimmermann 2014-06-15 16:53:33 +02:00
parent fb28eb85c5
commit 4c697c50fd

View File

@ -1,9 +1,12 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from glob import glob import sys
import os import os
import os.path
import logging import logging
from glob import glob
from werkzeug.wsgi import DispatcherMiddleware from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.wrappers import Response from werkzeug.wrappers import Response
@ -44,20 +47,19 @@ class Dispatcher(DispatcherMiddleware):
resp = Response("\n".join(self.isso.keys()), 404, content_type="text/plain") resp = Response("\n".join(self.isso.keys()), 404, content_type="text/plain")
return resp(environ, start_response) return resp(environ, start_response)
settings = os.environ.get("ISSO_SETTINGS")
if "ISSO_SETTINGS" in os.environ: if settings:
if os.path.isdir(settings):
conf_glob = os.path.join(os.environ["ISSO_SETTINGS"], '*.cfg')
confs = glob(conf_glob)
application = wsgi.SubURI(Dispatcher(*confs))
else:
confs = os.environ["ISSO_SETTINGS"].split(";") confs = os.environ["ISSO_SETTINGS"].split(";")
for path in confs: for path in confs:
if not os.path.isfile(path): if not os.path.isfile(path):
logger.fatal("%s: no such file", path) logger.fatal("%s: no such file", path)
break sys.exit(1)
else:
application = wsgi.SubURI(Dispatcher(*confs)) application = wsgi.SubURI(Dispatcher(*confs))
elif "ISSO_SETTINGS_DIR" in os.environ:
conf_glob = os.path.join(os.environ["ISSO_SETTINGS_DIR"], '*.cfg')
confs = glob(conf_glob)
application = wsgi.SubURI(Dispatcher(*confs))
else: else:
logger.fatal('environment variable ISSO_SETTINGS or ISSO_SETTINGS_DIR must be set') logger.fatal('environment variable ISSO_SETTINGS or ISSO_SETTINGS_DIR must be set')