Make config paths easier to override

This commit is contained in:
flan 2018-08-28 18:04:35 +02:00
parent 92d6579c83
commit c68fd12d67

View File

@ -1,18 +1,19 @@
import configparser import configparser
import logging import logging
import os.path import os
from os.path import dirname, realpath
paths = [
def load(path=None):
dirname = os.path.dirname
realpath = os.path.realpath
choices = [
"/etc/ankisyncd/ankisyncd.conf", "/etc/ankisyncd/ankisyncd.conf",
os.environ.get("XDG_CONFIG_DIR") and os.environ.get("XDG_CONFIG_HOME") and
(os.path.join(os.environ['XDG_CONFIG_DIR'], "ankisyncd", "ankisyncd.conf")) or (os.path.join(os.environ['XDG_CONFIG_HOME'], "ankisyncd", "ankisyncd.conf")) or
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"),
] ]
def load(path=None):
choices = paths
parser = configparser.ConfigParser() parser = configparser.ConfigParser()
if path: if path:
choices = [path] choices = [path]