1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-11-23 10:35:29 +03:00

configuration file initial support

This commit is contained in:
Igor Chubin 2018-08-16 19:44:01 +00:00
parent 29f839eb78
commit cc09c3f7a3
2 changed files with 28 additions and 1 deletions

7
etc/config.yaml Normal file
View File

@ -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 File

@ -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()