From e1c7c9dde5b4cbae29d64e45026c6e912229cee7 Mon Sep 17 00:00:00 2001 From: Sebastian Robinson Date: Mon, 16 Mar 2020 20:52:25 +0000 Subject: [PATCH] search for config file --- PDMameUpdate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 1cc25cd..e7ab545 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -48,6 +48,7 @@ import os import re import requests import time +import pathlib from clutch.core import Client from tabulate import tabulate from collections import defaultdict @@ -58,8 +59,16 @@ from urllib.parse import quote def open_config_file(): """Reads configuration from config.json file""" - logging.info('Opening config file: config.json') - with open('config.json') as config_file: + for loc in os.environ.get("PDMAMEUPDATE_CONF"), "/etc", os.path.expanduser("~"), os.curdir: + if loc is not None: + config_path = loc + '/config.json' + if pathlib.Path(config_path).is_file(): + config_file_loc = config_path + break + + logging.info('Opening config file: '+config_file_loc) + config_file = None; + with open(config_file_loc, 'r') as config_file: config = json.load(config_file) return config