forked from pvx/litsimaja
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
from dotenv import dotenv_values |
|
import pathlib |
|
|
|
|
|
def populate_values(load: {}): |
|
conf = load |
|
conf['IS_DEV']: bool = str.lower(load['ENVIRONMENT']) == 'dev' |
|
conf['USE_EMULATOR']: bool = str.lower(load['USE_EMULATOR']) == 'true' |
|
conf['BIND_PORT']: int = int(load['BIND_PORT']) |
|
|
|
conf['STRIP_PIXELS']: int = int(load['STRIP_PIXELS']) |
|
conf['STRIP_GPIO_PIN']: int = int(load['STRIP_GPIO_PIN']) |
|
conf['STRIP_HZ']: int = int(load['STRIP_HZ']) |
|
conf['STRIP_DMA']: int = int(load['STRIP_DMA']) |
|
conf['STRIP_INVERT']: bool = str.lower(load['STRIP_INVERT']) == 'true' |
|
conf['STRIP_BRIGHTNESS']: int = int(load['STRIP_BRIGHTNESS']) |
|
conf['STRIP_CHANNEL']: int = int(load['STRIP_CHANNEL']) |
|
conf['STRIP_TYPE']: int = int(load['STRIP_TYPE']) |
|
|
|
conf['REGIONS']: [] = [int(x) for x in load['REGIONS'].split(',')] |
|
conf['BPM_DEFAULT']: int = int(load['BPM_DEFAULT']) |
|
|
|
return conf |
|
|
|
|
|
class Config(object): |
|
_config: {} = {} |
|
|
|
def __init__(self): |
|
rp = str(pathlib.Path(__file__).parent.parent.absolute()) |
|
load_conf = { |
|
**dotenv_values(rp + "/.env.defaults"), |
|
**dotenv_values(rp + "/.env"), |
|
} |
|
self._config = populate_values(load_conf) |
|
|
|
def get(self, key: str): |
|
return self._config[key]
|
|
|