This commit is contained in:
2026-05-16 21:55:40 +02:00
parent 173d734d04
commit 045763576b
10 changed files with 116 additions and 220 deletions

View File

@@ -113,6 +113,47 @@ def choose_index(label: str, options: list[str]) -> int | None:
return idx - 1
def _task_id_set(value) -> set[str]:
if value is None:
return set()
if isinstance(value, str):
values = [value]
elif isinstance(value, (list, tuple, set)):
values = value
else:
return set()
return {str(item).strip() for item in values if str(item).strip()}
def all_selection_skip_task_ids(client) -> set[str]:
return _task_id_set(client.skip_in_all)
def tasks_for_all_selection(tasks, client):
skipped_ids = all_selection_skip_task_ids(client)
if not skipped_ids:
return list(tasks), []
selected = []
skipped = []
for task in tasks:
if task.id in skipped_ids:
skipped.append(task)
else:
selected.append(task)
return selected, skipped
def print_all_selection_skips(client, skipped_tasks) -> None:
if not skipped_tasks:
return
print()
print("Pominieto w wyborze ALL zgodnie z config/clients.toml:")
print_table(
["Nr", "Task ID", "Zadanie"],
[[task.selection, task.id, task.name] for task in skipped_tasks],
)
def main() -> None:
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
@@ -307,9 +348,17 @@ def main() -> None:
if args.select:
selected = args.select.strip()
if selected.upper() == "ALL":
run_task_sequence(
selected_tasks, skipped_tasks = tasks_for_all_selection(
tasks,
cfg.clients[selected_domain],
)
print_all_selection_skips(cfg.clients[selected_domain], skipped_tasks)
if not selected_tasks:
print("Brak zadan do uruchomienia po zastosowaniu pominiec dla ALL.")
return
run_task_sequence(
selected_tasks,
cfg.clients[selected_domain],
cfg.global_rules,
plan_only=args.plan_only,
)
@@ -365,9 +414,17 @@ def main() -> None:
return
if args.all_groups:
run_task_sequence(
selected_tasks, skipped_tasks = tasks_for_all_selection(
tasks,
cfg.clients[selected_domain],
)
print_all_selection_skips(cfg.clients[selected_domain], skipped_tasks)
if not selected_tasks:
print("Brak zadan do uruchomienia po zastosowaniu pominiec dla ALL.")
return
run_task_sequence(
selected_tasks,
cfg.clients[selected_domain],
cfg.global_rules,
plan_only=args.plan_only,
)
@@ -419,10 +476,12 @@ def main() -> None:
return
selected_tasks = []
respect_all_skips = False
if args.select:
selected = args.select.strip()
if selected.upper() == "ALL":
selected_tasks = tasks
respect_all_skips = True
else:
selected_tasks = tasks_by_selection_group(tasks, groups, selected)
if not selected_tasks:
@@ -438,6 +497,7 @@ def main() -> None:
return
elif args.all_groups:
selected_tasks = tasks
respect_all_skips = True
elif args.task:
selected_tasks = [task for task in tasks if task.id == args.task]
if not selected_tasks:
@@ -456,6 +516,7 @@ def main() -> None:
domains,
plan_only=True,
pause_after_client=True,
respect_all_skips=respect_all_skips,
)
return
@@ -1762,6 +1823,7 @@ def run_tasks_for_all_clients(
domains: list[str],
plan_only: bool = True,
pause_after_client: bool = True,
respect_all_skips: bool = False,
) -> None:
total_clients = len(domains)
total_tasks = len(tasks)
@@ -1782,10 +1844,22 @@ def run_tasks_for_all_clients(
print("#" * 72)
print(f"Klient {client_index}/{total_clients}: {domain}")
print("#" * 72)
for task_index, task in enumerate(tasks, 1):
client_tasks = list(tasks)
skipped_tasks = []
if respect_all_skips:
client_tasks, skipped_tasks = tasks_for_all_selection(
tasks,
cfg.clients[domain],
)
print_all_selection_skips(cfg.clients[domain], skipped_tasks)
total_client_tasks = len(client_tasks)
if not client_tasks:
print("Brak zadan do uruchomienia po zastosowaniu pominiec dla ALL.")
continue
for task_index, task in enumerate(client_tasks, 1):
print()
print("-" * 72)
print(f"Zadanie {task_index}/{total_tasks}: {task.group_name} / {task.name}")
print(f"Zadanie {task_index}/{total_client_tasks}: {task.group_name} / {task.name}")
print("-" * 72)
try:
run_task(

View File

@@ -27,6 +27,7 @@ class ClientConfig:
domain: str
google_ads_customer_id: str
adspro_client_id: str | None = None
skip_in_all: tuple[str, ...] = ()
rules: dict | None = None
@property
@@ -45,6 +46,18 @@ class AppConfig:
global_rules: dict
def _string_tuple(value) -> tuple[str, ...]:
if value is None:
return ()
if isinstance(value, str):
values = [value]
elif isinstance(value, (list, tuple, set)):
values = value
else:
return ()
return tuple(str(item).strip() for item in values if str(item).strip())
def load_config(path: Path | None = None) -> AppConfig:
config_path = path or ROOT / "config" / "clients.toml"
if not config_path.exists():
@@ -59,6 +72,7 @@ def load_config(path: Path | None = None) -> AppConfig:
domain=domain,
google_ads_customer_id=str(row["google_ads_customer_id"]),
adspro_client_id=str(row.get("adspro_client_id")) if row.get("adspro_client_id") else None,
skip_in_all=_string_tuple(row.get("skip_in_all")),
rules={key: value for key, value in row.items() if isinstance(value, dict)},
)
return AppConfig(clients=clients, global_rules=data.get("global_rules", {}))