2017-01-03 05:58:52 +01:00
|
|
|
"""Load config file as a singleton."""
|
|
|
|
from configparser import RawConfigParser
|
|
|
|
from os import path
|
2021-07-30 07:41:02 +02:00
|
|
|
from dozo import constants
|
2017-01-03 05:58:52 +01:00
|
|
|
|
|
|
|
|
2021-08-08 12:53:43 +02:00
|
|
|
def write(conf_file, config):
|
|
|
|
with open(conf_file, 'w') as conf_file:
|
|
|
|
config.write(conf_file)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2017-01-03 05:58:52 +01:00
|
|
|
|
2021-08-08 12:53:43 +02:00
|
|
|
def load_config(file):
|
2021-04-16 20:02:14 +02:00
|
|
|
if not path.exists(file):
|
2017-01-03 05:58:52 +01:00
|
|
|
return {}
|
|
|
|
|
2021-08-08 12:53:43 +02:00
|
|
|
config = RawConfigParser()
|
|
|
|
config.read(file)
|
|
|
|
return config
|
2021-07-29 18:42:31 +02:00
|
|
|
|
|
|
|
def get_path_definition(config):
|
|
|
|
"""Returns a list of folder definitions.
|
|
|
|
|
|
|
|
Each element in the list represents a folder.
|
|
|
|
Fallback folders are supported and are nested lists.
|
|
|
|
|
|
|
|
:returns: string
|
|
|
|
"""
|
|
|
|
|
|
|
|
if 'Path' in config:
|
|
|
|
if 'format' in config['Path']:
|
|
|
|
return config['Path']['format']
|
|
|
|
elif 'dirs_path' and 'name' in config['Path']:
|
2021-08-08 12:43:17 +02:00
|
|
|
return config['Path']['dirs_path'] + '/' + config['Path']['name']
|
2021-07-29 18:42:31 +02:00
|
|
|
|
2021-08-08 12:43:17 +02:00
|
|
|
return constants.default_path + '/' + constants.default_name
|
2021-07-29 18:42:31 +02:00
|
|
|
|
2021-07-31 20:11:39 +02:00
|
|
|
def get_geocoder():
|
|
|
|
config = load_config(constants.CONFIG_FILE)
|
|
|
|
if 'Geolocation' in config and 'geocoder' in config['Geolocation']:
|
2021-08-13 19:12:42 +02:00
|
|
|
geocoder = config['Geolocation']['geocoder']
|
|
|
|
if geocoder in ('Nominatim', ):
|
|
|
|
return geocoder
|
2021-07-31 20:11:39 +02:00
|
|
|
|
|
|
|
return constants.default_geocoder
|
|
|
|
|