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.

45 lines
1017 B

5 years ago
import os.path
from configparser import ConfigParser
import yaml
APP_NAME = 'autogestionale'
5 years ago
CONFIG_PATHS = [
'conf/',
'~/.config/autogestionale',
'/usr/local/etc/autogestionale',
'/etc/autogestionale'
]
5 years ago
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'))