Implemented error catching

This commit is contained in:
Kevin Veen-Birkenbach
2025-04-11 16:29:40 +02:00
parent 0957ee2972
commit b4d76483f8

View File

@@ -2,14 +2,32 @@ import os
from pkgmgr.get_repo_identifier import get_repo_identifier from pkgmgr.get_repo_identifier import get_repo_identifier
from pkgmgr.get_repo_dir import get_repo_dir from pkgmgr.get_repo_dir import get_repo_dir
from pkgmgr.run_command import run_command from pkgmgr.run_command import run_command
import sys
def exec_proxy_command(proxy_prefix:str,selected_repos, repositories_base_dir, all_repos, proxy_command:str, extra_args, preview:bool): def exec_proxy_command(proxy_prefix: str, selected_repos, repositories_base_dir, all_repos, proxy_command: str, extra_args, preview: bool):
"""Execute a given proxy command with extra arguments for each repository.""" """Execute a given proxy command with extra arguments for each repository."""
error_repos = []
max_exit_code = 0
for repo in selected_repos: for repo in selected_repos:
repo_identifier = get_repo_identifier(repo, all_repos) repo_identifier = get_repo_identifier(repo, all_repos)
repo_dir = get_repo_dir(repositories_base_dir,repo) repo_dir = get_repo_dir(repositories_base_dir, repo)
if os.path.exists(repo_dir):
full_cmd = f"{proxy_prefix} {proxy_command} {' '.join(extra_args)}" if not os.path.exists(repo_dir):
print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.")
continue
full_cmd = f"{proxy_prefix} {proxy_command} {' '.join(extra_args)}"
try:
run_command(full_cmd, cwd=repo_dir, preview=preview) run_command(full_cmd, cwd=repo_dir, preview=preview)
else: except SystemExit as e:
print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.") print(f"[ERROR] Command failed in {repo_identifier} with exit code {e.code}.")
error_repos.append((repo_identifier, e.code))
max_exit_code = max(max_exit_code, e.code)
if error_repos:
print("\nSummary of failed commands:")
for repo_identifier, exit_code in error_repos:
print(f"- {repo_identifier} failed with exit code {exit_code}")
sys.exit(max_exit_code)