-d and --backup-dir options completed

This commit is contained in:
2021-12-09 22:50:37 +01:00
parent f19bb84953
commit ab5b874051

15
main.py
View File

@@ -31,35 +31,36 @@ def save_settings():
def restore():
# todo
return # todo
if __name__ == '__main__':
backupdir = "/home/lacko/.backup"
backupdir = os.path.expanduser("~/.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"):
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"):
elif option in ("-d", "backup-dir"):
backupdir = os.path.expanduser(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)
except FileNotFoundError:
subprocess.call(["mkdir", backupdir])
os.chdir(backupdir)
run_daily()
list_pkgs()
save_settings()