Permalink
Browse files

configuration file initial support

  • Loading branch information...
chubin committed Aug 16, 2018
1 parent 29f839e commit cc09c3f7a314ebd4565be078c02c605e10f0ff36
Showing with 28 additions and 1 deletion.
  1. +7 −0 etc/config.yaml
  2. +21 −1 lib/globals.py
View
@@ -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
View
@@ -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 @@
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()

0 comments on commit cc09c3f

Please sign in to comment.