-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathconfig.py
37 lines (30 loc) · 1008 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import os
from configparser import ConfigParser
def get_config(local: bool = True) -> ConfigParser:
"""Reads config.ini and returns a configuration parser for it."""
# later files in the list can be used to overwrite settings in the primary config file
if local:
config_files = [
"config.ini",
"config-local.ini"
]
else:
config_files = [
"config.ini"
]
if any([os.path.isfile(f) for f in config_files]):
config = ConfigParser()
config.read(config_files)
return config
raise ValueError(f"Config file(s) not found! Searched files: {config_files}")
def get_version() -> tuple:
"""Reads version.txt and returns its values in a tuple."""
try:
with open("version.txt") as file:
split = file.read().splitlines()
commit_hash = split[0]
commit_date = split[1]
return commit_hash, commit_date
except:
return ()