#!/usr/bin/python3 from json import load from os import environ def import_from_default_path(): """ Import the configuration JSON from the default path (config/config.json) Returns: dict -- Configuration dictionary object """ try: with open('config/config.json') as config_file: return load(config_file) config_file.close() except Exception as e: print("Couldn't find the config file.") exit(1) def import_config_file(): """ Import the configuration JSON from the path specified in TMT_CONFIG_PATH, otherwise default path (i.e. call import_from_default_path()) Returns: dict -- Configuration dictionary object """ if('TMT_CONFIG_PATH' in environ.keys()): try: with open(f'{environ["TMT_CONFIG_PATH"]}') as config_file: return load(config_file) config_file.close() except: return import_from_default_path() else: return import_from_default_path()