Skip to content

Commit cc09c3f

Browse files
committed
configuration file initial support
1 parent 29f839e commit cc09c3f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

etc/config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server:
2+
address: "0.0.0.0"
3+
port: 8002
4+
cache: false # true - results have to be cached in redis
5+
# false - results do not have to be cached locally
6+
# "path" results have to be cached in filesystem
7+
redis: false # redis server hostname of false if no redis server used

lib/globals.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
"""
22
Global configuration of the project.
3-
All hardcoded paths should be (theoretically) here.
3+
All hardcoded pathes and other data should be
4+
(theoretically) here.
45
"""
56
from __future__ import print_function
67

78
import logging
89
import os
10+
import yaml
911
from pygments.styles import get_all_styles
1012

1113
USE_OS_PACKAGES = True # set to False if you pull cheat sheets repositories from GitHub
1214
DOCKERIZED = False # set to True if the service is running in a Docker container
1315

16+
SERVER_ADDRESS = '0.0.0.0'
17+
SERVER_PORT = 8002
18+
1419
MYDIR = os.path.abspath(os.path.join(__file__, '..', '..'))
20+
_CONF_FILE = os.path.join(MYDIR, 'etc/config.yaml')
1521

1622
if DOCKERIZED:
1723
REDISHOST = 'redis'
@@ -39,6 +45,20 @@
3945
PATH_CHEAT_SHEETS_SPOOL = os.path.join(MYDIR, "cheatsheets/spool/")
4046
PATH_LEARNXINY = os.path.join(MYDIR, "cheatsheets/learnxinyminutes-docs")
4147

48+
#
49+
# Reading configuration from etc/config.yaml
50+
# config overrides default settings
51+
#
52+
if os.path.exists(_CONF_FILE):
53+
_CONFIG = yaml.load(_CONF_FILE)
54+
if 'server' in _CONFIG:
55+
_SERVER_CONFIG = _CONFIG['server']
56+
if 'address' in _SERVER_CONFIG:
57+
SERVER_ADDRESS = _SERVER_CONFIG['address']
58+
if 'port' in _SERVER_CONFIG:
59+
SERVER_ADDRESS = _SERVER_CONFIG['port']
60+
61+
4262
COLOR_STYLES = sorted(list(get_all_styles()))
4363

4464
MALFORMED_RESPONSE_HTML_PAGE = open(os.path.join(STATIC, 'malformed-response.html')).read()

0 commit comments

Comments
 (0)