#!/usr/bin/env python from pathlib import Path import subprocess import argparse from utils.logging_utils import setup_logger import logging logger = setup_logger("update_repos") def update_repositories(base_dir: Path): """Updates all git repositories in the given directory.""" logger.info(f"Scanning for git repositories in: {base_dir}") for repo_dir in base_dir.iterdir(): if not (repo_dir / ".git").exists(): logger.debug(f"Skipping non-git directory: {repo_dir}") continue logger.info(f"Processing repository: {repo_dir}") try: subprocess.run(["git", "-C", str(repo_dir), "pull"], check=True) logger.info(f"Successfully updated {repo_dir}") except subprocess.CalledProcessError as e: logger.error(f"Failed to update {repo_dir}: {e}") def main(): parser = argparse.ArgumentParser() parser.add_argument("--dir", type=Path, default=Path.home()) parser.add_argument("--debug", action="store_true", help="Enable debug logging") args = parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) update_repositories(args.dir) if __name__ == "__main__": main()