diff --git a/etc/config.yaml b/etc/config.yaml new file mode 100644 index 0000000..70fc5a8 --- /dev/null +++ b/etc/config.yaml @@ -0,0 +1,7 @@ +server: + address: "0.0.0.0" + port: 8002 + cache: false # true - results have to be cached in redis + # false - results do not have to be cached locally + # "path" results have to be cached in filesystem + redis: false # redis server hostname of false if no redis server used diff --git a/lib/globals.py b/lib/globals.py index 913ba15..5d9d3ed 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -1,17 +1,23 @@ """ Global configuration of the project. -All hardcoded paths should be (theoretically) here. +All hardcoded pathes and other data should be +(theoretically) here. """ from __future__ import print_function import logging import os +import yaml from pygments.styles import get_all_styles USE_OS_PACKAGES = True # set to False if you pull cheat sheets repositories from GitHub DOCKERIZED = False # set to True if the service is running in a Docker container +SERVER_ADDRESS = '0.0.0.0' +SERVER_PORT = 8002 + MYDIR = os.path.abspath(os.path.join(__file__, '..', '..')) +_CONF_FILE = os.path.join(MYDIR, 'etc/config.yaml') if DOCKERIZED: REDISHOST = 'redis' @@ -39,6 +45,20 @@ else: PATH_CHEAT_SHEETS_SPOOL = os.path.join(MYDIR, "cheatsheets/spool/") PATH_LEARNXINY = os.path.join(MYDIR, "cheatsheets/learnxinyminutes-docs") +# +# Reading configuration from etc/config.yaml +# config overrides default settings +# +if os.path.exists(_CONF_FILE): + _CONFIG = yaml.load(_CONF_FILE) + if 'server' in _CONFIG: + _SERVER_CONFIG = _CONFIG['server'] + if 'address' in _SERVER_CONFIG: + SERVER_ADDRESS = _SERVER_CONFIG['address'] + if 'port' in _SERVER_CONFIG: + SERVER_ADDRESS = _SERVER_CONFIG['port'] + + COLOR_STYLES = sorted(list(get_all_styles())) MALFORMED_RESPONSE_HTML_PAGE = open(os.path.join(STATIC, 'malformed-response.html')).read()