Don't check if config file exists before loading it

This commit is contained in:
flan 2018-08-28 17:38:50 +02:00
parent 242c423c13
commit 527991beea

View File

@ -3,7 +3,7 @@ import logging
import os.path import os.path
def location(): def load(path=None):
dirname = os.path.dirname dirname = os.path.dirname
realpath = os.path.realpath realpath = os.path.realpath
choices = [ choices = [
@ -13,17 +13,16 @@ def location():
os.path.join(os.path.expanduser("~"), ".config", "ankisyncd", "ankisyncd.conf"), os.path.join(os.path.expanduser("~"), ".config", "ankisyncd", "ankisyncd.conf"),
os.path.join(dirname(dirname(realpath(__file__))), "ankisyncd.conf"), os.path.join(dirname(dirname(realpath(__file__))), "ankisyncd.conf"),
] ]
parser = configparser.ConfigParser()
if path:
choices = [path]
for path in choices: for path in choices:
logging.debug("config.location: trying", path) logging.debug("config.location: trying", path)
if os.path.isfile(path): try:
logging.debug("config.location: choosing", path) parser.read(path)
return path conf = parser['sync_app']
logging.info("Loaded config from {}".format(path))
logging.error("No config found, looked in", ", ".join(choices)) return conf
except KeyError:
pass
def load(path=location()): raise Exception("No config found, looked for {}".format(", ".join(choices)))
logging.info("Loading config from {}".format(path))
parser = configparser.ConfigParser()
parser.read(path)
return parser['sync_app']