From 4c8b6f79de7b49692ed6a2b75c25b7e5ea6d4dfb Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 10 May 2017 19:09:31 +0200 Subject: [PATCH] Fallback looking for settings file at /etc/umap/umap.conf fix #487 --- docs/ubuntu.md | 19 +++++++--------- umap/settings/__init__.py | 46 ++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/docs/ubuntu.md b/docs/ubuntu.md index fe7602d8..aac93d68 100644 --- a/docs/ubuntu.md +++ b/docs/ubuntu.md @@ -12,9 +12,10 @@ You need sudo grants on this server, and it must be connected to Internet. *Note: uMap also works with python 2.7 and 3.4, so adapt the package names if you work with another version.* -## Create a deployment directory: +## Create deployment directories: sudo mkdir -p /srv/umap + sudo mkdir -p /etc/umap *You can change this path, but then remember to adapt the other steps accordingly.* @@ -27,6 +28,11 @@ You need sudo grants on this server, and it must be connected to Internet. on the various commands and configuration files if you go with your own.* +## Give umap user access to the config folder + + sudo chown umap:users /etc/umap + + ## Create a postgresql user sudo -u postgres createuser umap @@ -65,15 +71,8 @@ you will need to run again this last line.* ## Create a local configuration file - wget https://raw.githubusercontent.com/umap-project/umap/master/umap/settings/local.py.sample -O /srv/umap/local.py + wget https://raw.githubusercontent.com/umap-project/umap/master/umap/settings/local.py.sample -O /etc/umap/umap.conf -Now we need to inform umap about it. -We'll create an environment variable for that: - - export UMAP_SETTINGS=/srv/umap/local.py - -*Note: this variable will not be persistent if you quit your current terminal session, so -remember to rerun this command if you open a new terminal window.* ## Create the tables @@ -147,8 +146,6 @@ chdir = /srv/umap/ module = umap.wsgi # the virtualenv (full path) home = /srv/umap/venv -# the local settings path -env = UMAP_SETTINGS=/srv/umap/local.py # process-related settings # master diff --git a/umap/settings/__init__.py b/umap/settings/__init__.py index 3202af9c..000bffd2 100644 --- a/umap/settings/__init__.py +++ b/umap/settings/__init__.py @@ -9,24 +9,30 @@ from .base import * # NOQA, default values # Allow to override setting from any file, may be out of the PYTHONPATH, # to make it easier for non python people. path = os.environ.get('UMAP_SETTINGS') -if path: - d = imp.new_module('config') - d.__file__ = path - try: - with open(path) as config_file: - exec(compile(config_file.read(), path, 'exec'), d.__dict__) - except IOError as e: - msg = 'Unable to import {} from UMAP_SETTINGS'.format(path) - print(colorize(msg, fg='red')) - sys.exit(e) - else: - print('Loaded local config from', path) - for key in dir(d): - if key.isupper(): - globals()[key] = getattr(d, key) -else: +if not path: # Retrocompat - try: - from .local import * # NOQA - except ImportError: - pass + path = os.path.join('/etc', 'umap', 'umap.conf') + if not os.path.exists(path): + # Retrocompat + path = os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'local.py') + if not os.path.exists(path): + msg = ('You must configure UMAP_SETTINGS or define ' + '/etc/umap/umap.conf') + print(colorize(msg, fg='red')) + sys.exit(1) + +d = imp.new_module('config') +d.__file__ = path +try: + with open(path) as config_file: + exec(compile(config_file.read(), path, 'exec'), d.__dict__) +except IOError as e: + msg = 'Unable to import {} from UMAP_SETTINGS'.format(path) + print(colorize(msg, fg='red')) + sys.exit(e) +else: + print('Loaded local config from', path) + for key in dir(d): + if key.isupper(): + globals()[key] = getattr(d, key)