File size: 1,237 Bytes
fbeebb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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()