#!/usr/bin/python3 import sys import json #CONFIGURATION_PATH = "/etc/pybackup.conf" # for "production" CONFIGURATION_PATH = "pybackup.conf" # for testing def log(message: str, log_level: int) -> bool: assignments = {0: "DEBUG", 1: "VERBOSE", 2: "INFO", 3: "ERROR", 4: "FATAL"} if(log_level not in assignments): return False # show that something went wrong print(f"[{assignments[log_level]}] {message}") return True if not __name__ == "__main__": # just to make sure this program isn't used as a module print(f"[{sys.argv[0]}]: THIS BACKUP PROGRAM IS NOT A PYTHON MODULE!") exit(0) conf_f = open(CONFIGURATION_PATH, "r") try: conf = json.load(conf_f) except json.decoder.JSONDecodeError: log("The configuration file is corrupted", 3) exit(1) conf_f.close() print(conf)