forked from pvx/litsimaja
Merge pull request 'dotenv' (#7) from feature/dotenv into master
Reviewed-on: pvx/litsimaja#7feature/absolute-paths
commit
103e04a1b4
7 changed files with 85 additions and 28 deletions
@ -0,0 +1,17 @@ |
||||
ENVIRONMENT=prod |
||||
USE_EMULATOR=false |
||||
BIND_ADDR=127.0.0.1 |
||||
BIND_PORT=8080 |
||||
|
||||
# Strip configuration |
||||
STRIP_PIXELS=290 |
||||
STRIP_GPIO_PIN=18 |
||||
STRIP_HZ=800000 |
||||
STRIP_DMA=10 |
||||
STRIP_INVERT=false |
||||
STRIP_BRIGHTNESS=255 |
||||
STRIP_CHANNEL=0 |
||||
STRIP_TYPE=4104 |
||||
|
||||
REGIONS=46,96,191,241 |
||||
BPM_DEFAULT=60 |
@ -0,0 +1,2 @@ |
||||
ENVIRONMENT=dev |
||||
USE_EMULATOR=true |
@ -1 +1,2 @@ |
||||
.env |
||||
litsimaja.log |
||||
|
@ -0,0 +1,36 @@ |
||||
from dotenv import dotenv_values |
||||
|
||||
|
||||
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): |
||||
load_conf = { |
||||
**dotenv_values(".env.defaults"), |
||||
**dotenv_values(".env"), |
||||
} |
||||
self._config = populate_values(load_conf) |
||||
|
||||
def get(self, key: str): |
||||
return self._config[key] |
Loading…
Reference in new issue