예제 #1
0
def analyze(path, year, out):
    repositories = discover_repositories(os.path.expanduser(path))

    logs = []
    for repo in repositories:
        logs += generate_git_log(repo)

    log_by_year = sort_by_year(logs)

    max_commits = []
    for y in log_by_year:
        data = process_log(log_by_year[y], y)
        max_commits.append(data['max_commits'])

    if not year:
        year = y
    else:
        year = int(year)
    global_max = max(max_commits)
    processed_logs = process_log(log_by_year[year], year)
    logger.info('Generating report for year {}'.format(year))
    if out:
        with open(out, 'w') as fout:
            make_svg_report(processed_logs, global_max, fout)
    else:
        make_svg_report(processed_logs, global_max)
예제 #2
0
def discover_repositories(root_path):
    """Discover git repositories under a given directory, excluding repositores
    that contain a .exclude file."""

    repositories = []
    for root, dirs, files in os.walk(root_path):
        if os.path.exists(os.path.join(root, '.git')) and \
                not os.path.exists(os.path.join(root, '.exclude')):
            logger.info('Git repository discovered: {}'.format(root))
            repositories.append(root)

    return repositories
예제 #3
0
def generate_git_log(path, format='format:%an|%ae|%ad'):
    """Get the entire commit logs in a raw string for a given repository.

    :param path: an absolute or relative path of a git repository
    """
    abs_path = os.path.abspath(path)

    logger.info('Analyzing %s' % abs_path)
    log_rows = subprocess.check_output(
        ['git', 'log', '--pretty={}'.format(format)],
        cwd=abs_path).decode('utf-8')

    return [parse_log_row(row) for row in log_rows.strip().split('\n')]