Commit 30bbda45 authored by Lynn Cyrin's avatar Lynn Cyrin

parse env strings into ints or bools

parent d76399d6
Pipeline #89666 failed with stage
......@@ -6,6 +6,7 @@ Import from here with `from quirell.config import *`
'''
import os
import re
import sys
import dotenv
import logging
......@@ -25,7 +26,7 @@ CONFIG={
#
'CLOUDINARY_CDN': 'http://res.cloudinary.com/',
'THE_PASSWORD': '3',
'DEBUG': True,
'DEBUG': False,
'PORT': 5000,
}
......@@ -33,6 +34,20 @@ try: CONFIG.update(dotenv.parse_dotenv(BASE_PATH+'/.env'))
except FileNotFoundError: pass
for k, v in CONFIG.items(): os.environ[k] = str(v)
# format config types
for k, v in CONFIG.items():
if not type(v) == str:
continue
# if string formatted as boolean false
if re.match(r'(?i)^(false)$', v):
CONFIG[k] = False
# if string formatted as boolean true
if re.match(r'(?i)^(true)$', v):
CONFIG[k] = True
# if string formatted as integer
if re.match(r'^(-)*[0-9]+$', v):
CONFIG[k] = int(v)
logging.basicConfig(stream=sys.stdout)
LOG = logging.getLogger('quirell')
LOG.setLevel(logging.INFO)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment