-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(): def restore():
# todo return # todo
if __name__ == '__main__': if __name__ == '__main__':
backupdir = "/home/lacko/.backup" backupdir = os.path.expanduser("~/.backup")
try: try:
options, values = getopt.getopt(sys.argv[1:], "hd:r", ["help", "backup-dir=", "restore"]) options, values = getopt.getopt(sys.argv[1:], "hd:r", ["help", "backup-dir=", "restore"])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print("Error: ", err.msg) print("Error: ", err.msg)
exit(1) exit(1)
for option, value in options: for option, value in options:
if option in ("h", "help"): if option in ("-h", "help"):
print("usage: <name> [opts]\n\ print("usage: <name> [opts]\n\
Options:\n\ Options:\n\
\t-h --help: show this\n\ \t-h --help: show this\n\
\t-d --backup-dir [directory]: set the directory for the backup/restoration (default is ~/.backups)\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> \t-r --restore: run the restoration (from backupdir)\n") # todo: <name>
exit() exit()
elif option in("d", "backup-dir"): elif option in ("-d", "backup-dir"):
backupdir = value backupdir = os.path.expanduser(value)
elif option in("r", "restore"): elif option in ("-r", "restore"):
restore() restore()
exit() exit()
try: try:
# os.chdir("/run/user/1000/gvfs/smb-share:server=ds_panni.local,share=lacko/Backup/T490")
os.chdir(backupdir) os.chdir(backupdir)
except FileNotFoundError: except FileNotFoundError:
subprocess.call(["mkdir", backupdir]) subprocess.call(["mkdir", backupdir])
os.chdir(backupdir)
run_daily() run_daily()
list_pkgs() list_pkgs()
save_settings() save_settings()