Added configuration file

This commit is contained in:
Blue Fox 2022-07-14 15:18:51 +02:00
parent eafe0706b3
commit ed28ae90a4
2 changed files with 37 additions and 0 deletions

10
pybackup.conf Normal file
View File

@ -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."
}
]}

View File

@ -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)