From f19bb84953c4cd2746e7b79705de99a0bd5744b1 Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Thu, 9 Dec 2021 22:29:53 +0100 Subject: [PATCH] Added argument processing --- main.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 6005795..db978ac 100644 --- a/main.py +++ b/main.py @@ -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: [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: [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: + 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)