From ed28ae90a4532623561f75153ba5008440fb64c8 Mon Sep 17 00:00:00 2001 From: Blue Fox Date: Thu, 14 Jul 2022 15:18:51 +0200 Subject: [PATCH] Added configuration file --- pybackup.conf | 10 ++++++++++ pybackup.py | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 pybackup.conf diff --git a/pybackup.conf b/pybackup.conf new file mode 100644 index 0000000..fefe6a6 --- /dev/null +++ b/pybackup.conf @@ -0,0 +1,10 @@ +{"locations": [ + { + "name": "testlocation1", + "path": "/path/to/the/testlocation/folder", + "backup_path": "/path/to/backup/folder", + "frequency": 1, + "expire": 31, + "__COMMENT__": "The Frequency/Expire is given in days. The program should be started as often as selected, e.g. with 2, the program has to be started at least every two days." + } +]} \ No newline at end of file diff --git a/pybackup.py b/pybackup.py index ecf7241..23661df 100644 --- a/pybackup.py +++ b/pybackup.py @@ -1,2 +1,29 @@ #!/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)