45 lines
1017 B
Python
45 lines
1017 B
Python
import os.path
|
|
from configparser import ConfigParser
|
|
import yaml
|
|
|
|
|
|
APP_NAME = 'autogestionale'
|
|
|
|
CONFIG_PATHS = [
|
|
'conf/',
|
|
'~/.config/autogestionale',
|
|
'/usr/local/etc/autogestionale',
|
|
'/etc/autogestionale'
|
|
]
|
|
CONFIG_FILES = {
|
|
'core': 'core.ini',
|
|
'logging': 'logging.yaml'
|
|
}
|
|
|
|
|
|
def get_default_path():
|
|
for p in CONFIG_PATHS:
|
|
if all([
|
|
os.path.isfile(os.path.join(p, f))
|
|
for f in CONFIG_FILES.values()
|
|
]):
|
|
return p
|
|
else:
|
|
raise Exception('Unable to find a configuration folder.')
|
|
|
|
|
|
class Config:
|
|
def __init__(self):
|
|
self.basedir = get_default_path()
|
|
self.path_core = os.path.join(self.basedir, CONFIG_FILES['core'])
|
|
self.path_logging = os.path.join(self.basedir, CONFIG_FILES['logging'])
|
|
|
|
self.core = ConfigParser()
|
|
self.logging = None
|
|
|
|
self.read()
|
|
|
|
def read(self):
|
|
self.core.read(self.path_core)
|
|
self.logging = yaml.load(open(self.path_logging, 'r'))
|