Added argument processing

This commit is contained in:
2021-12-09 22:29:53 +01:00
parent 9aa7f6864d
commit f19bb84953

30
main.py
View File

@@ -2,6 +2,7 @@ import os
import subprocess
import datetime
import sys
import getopt
def run_daily():
@@ -29,14 +30,31 @@ def save_settings():
f.close()
def restore():
# todo
if __name__ == '__main__':
for i in sys.argv:
if i == "--help" or i == "-h":
print("usage: <name> [opts]\n\
Options:\n\
\t-h --help: show this\n\
\t-d --backup-dir [directory]: set the directory the backups go to")
backupdir = "/home/lacko/.backup"
try:
options, values = getopt.getopt(sys.argv[1:], "hd:r", ["help", "backup-dir=", "restore"])
except getopt.GetoptError as err:
print("Error: ", err.msg)
exit(1)
for option, value in options:
if option in ("h", "help"):
print("usage: <name> [opts]\n\
Options:\n\
\t-h --help: show this\n\
\t-d --backup-dir [directory]: set the directory for the backup/restoration (default is ~/.backups)\n\
\t-r --restore: run the restoration (from backupdir)\n") # todo: <name>
exit()
elif option in("d", "backup-dir"):
backupdir = value
elif option in("r", "restore"):
restore()
exit()
try:
# os.chdir("/run/user/1000/gvfs/smb-share:server=ds_panni.local,share=lacko/Backup/T490")
os.chdir(backupdir)