From a30d7ef0deb997b65ecea3d988e35a8335bdb122 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 16 Dec 2020 23:01:41 +0100 Subject: [PATCH] outsource setting of flags into own function --- backup.py | 7 ++----- restore.py | 7 ++----- upgrade.py | 7 ++----- utils.py | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/backup.py b/backup.py index 31ea54f..1636fa6 100644 --- a/backup.py +++ b/backup.py @@ -15,11 +15,8 @@ from models import Log def backup(): backup_status = True - # Fetch arguments - utils.all_containers = "--all" in sys.argv - utils.quiet_mode = "--quiet" in sys.argv - utils.no_log = "--nolog" in sys.argv - utils.no_cleanup = "--nocleanup" in sys.argv + # Set flags + utils.set_flags(sys.argv) # Load settings settings = Path(__file__).parent / "settings.yaml" diff --git a/restore.py b/restore.py index 80b5418..4e901ec 100644 --- a/restore.py +++ b/restore.py @@ -20,11 +20,8 @@ from simple_term_menu import TerminalMenu def restore(): restore_status = True - # Fetch arguments - utils.all_containers = "--all" in sys.argv - utils.quiet_mode = "--quiet" in sys.argv - utils.no_log = "--nolog" in sys.argv - utils.no_confirm = "--yes" in sys.argv + # Set flags + utils.set_flags(sys.argv) # Load settings settings = Path(__file__).parent / "settings.yaml" diff --git a/upgrade.py b/upgrade.py index 3d00862..5bb27d2 100644 --- a/upgrade.py +++ b/upgrade.py @@ -15,11 +15,8 @@ from models import Log def upgrade(): upgrade_status = True - # Fetch arguments - utils.all_containers = "--all" in sys.argv - utils.quiet_mode = "--quiet" in sys.argv - utils.no_log = "--nolog" in sys.argv - utils.no_cleanup = "--nocleanup" in sys.argv + # Set flags + utils.set_flags(sys.argv) # Load settings settings = Path(__file__).parent / "settings.yaml" diff --git a/utils.py b/utils.py index 302138d..acf07ee 100644 --- a/utils.py +++ b/utils.py @@ -6,7 +6,24 @@ all_containers = False no_confirm = False + +def set_flags(flags=list): + global quiet_mode + global no_log + global no_cleanup + global all_containers + global no_confirm + global no_backup + + quiet_mode = "--quiet" in flags + no_log = "--nolog" in flags + all_containers = "--all" in flags + no_cleanup = "--nocleanup" in flags + no_confirm = "--yes" in flags + + def _print(text=None): + global quiet_mode if not quiet_mode: if not text is None: print(text)