ADD: --force flag and managed it in the check diferences functions #8

Merged
marc.koch merged 1 commit from force_flag into main 2025-04-01 14:09:43 +02:00
2 changed files with 12 additions and 2 deletions

View file

@ -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__,

View file

@ -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()