From a85b324102ae78c1f291ee5d3b20ef07f021f5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Leiva?= Date: Tue, 1 Apr 2025 13:02:32 +0200 Subject: [PATCH] ADD: --force flag and managed it in the check diferences functions --- src/adgroupsync/__main__.py | 5 +++-- src/adgroupsync/conf.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/adgroupsync/__main__.py b/src/adgroupsync/__main__.py index cfa94dc..15ed3ff 100644 --- a/src/adgroupsync/__main__.py +++ b/src/adgroupsync/__main__.py @@ -23,6 +23,7 @@ from .conf import ( NTFY_URL, NTFY_TOPIC, NTFY_ACCESS_TOKEN, + FORCE_FLAG ) from .exceptions import ScriptAlreadyRunningError from .logger import setup_logging @@ -134,7 +135,7 @@ def find_changed(all_groups, level_dict, recent_run): changed_users = set() for group in level_dict.keys(): - if check_group_changes(group, level_dict, recent_run, set()): + if (FORCE_FLAG or check_group_changes(group, level_dict, recent_run, set())): changed_groups.add(group) logger.debug(f"Group '{group.name}' has changed", extra={ 'group': group.__dict__, @@ -144,7 +145,7 @@ def find_changed(all_groups, level_dict, recent_run): for group, members in all_groups.items(): for user in members: if isinstance(user, ADUser) and not is_user_disabled( - user) and has_changed(user, recent_run): + user) and (FORCE_FLAG or has_changed(user, recent_run)): changed_users.add(user) logger.debug(f"User '{user.name}' has changed", extra={ 'user': user.__dict__, diff --git a/src/adgroupsync/conf.py b/src/adgroupsync/conf.py index 2e73fc7..371efbf 100644 --- a/src/adgroupsync/conf.py +++ b/src/adgroupsync/conf.py @@ -165,6 +165,12 @@ try: help="Create a cron job", ) + argparser.add_argument( + "--force", + action="store_true", + help="Forces the script execution skipping recent run checking", + ) + args = argparser.parse_args() # If a path to a config file was provided @@ -187,6 +193,9 @@ try: cron_job = args.create_cron create_cron_job(cron_job, config_file) exit(0) + + # Saving the force flag + FORCE_FLAG=args.force # Load configuration file config = TOMLFile(config_file).read()