|
a |
|
b/echonet/config.py |
|
|
1 |
"""Sets paths based on configuration files.""" |
|
|
2 |
|
|
|
3 |
import configparser |
|
|
4 |
import os |
|
|
5 |
import types |
|
|
6 |
|
|
|
7 |
_FILENAME = None |
|
|
8 |
_PARAM = {} |
|
|
9 |
for filename in ["echonet.cfg", |
|
|
10 |
".echonet.cfg", |
|
|
11 |
os.path.expanduser("~/echonet.cfg"), |
|
|
12 |
os.path.expanduser("~/.echonet.cfg"), |
|
|
13 |
]: |
|
|
14 |
if os.path.isfile(filename): |
|
|
15 |
_FILENAME = filename |
|
|
16 |
config = configparser.ConfigParser() |
|
|
17 |
with open(filename, "r") as f: |
|
|
18 |
config.read_string("[config]\n" + f.read()) |
|
|
19 |
_PARAM = config["config"] |
|
|
20 |
break |
|
|
21 |
|
|
|
22 |
CONFIG = types.SimpleNamespace( |
|
|
23 |
FILENAME=_FILENAME, |
|
|
24 |
DATA_DIR=_PARAM.get("data_dir", "a4c-video-dir/")) |