Added configuration file
This commit is contained in:
parent
eafe0706b3
commit
ed28ae90a4
10
pybackup.conf
Normal file
10
pybackup.conf
Normal 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."
|
||||
}
|
||||
]}
|
27
pybackup.py
27
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user