#!/usr/bin/env python import argparse import datetime import jinja2 import logging import os import pprint import re import subprocess import teamanalysis.git import teamanalysis.repos import teamanalysis.time import webbrowser LOGGER = logging.getLogger('overview-by-date') def _get_abspath(repo): return '/Users/eliribble/src/teamanalysis/repos/{}/'.format(repo) def _get_commit_count(repo, start, end): abspath = _get_abspath(repo) os.chdir(abspath) command = ['git', 'checkout', 'master'] subprocess.check_output(command, stderr=subprocess.STDOUT) command = [ 'git', 'log', '--pretty=format:"%h %aI"', '--after={}'.format(start.isoformat()), '--before={}'.format(end.isoformat())] LOGGER.debug(" ".join(command)) output = subprocess.check_output(command) lines = output.split('\n') result = len(lines) if output else 0 return result def _get_commit_sha_by_date(repo, timepoint): abspath = _get_abspath(repo) os.chdir(abspath) command = [ 'git', 'rev-list', '-n', '1', '--before="{}"'.format(timepoint.date().isoformat()), 'master', '--', ] LOGGER.debug("%s", ' '.join(command)) output = subprocess.check_output(command) output = output.strip() LOGGER.debug("%s: %s", ' '.join(command), output) return output def _git_checkout_by_date(repo, timepoint): abspath = _get_abspath(repo) commit = _get_commit_sha_by_date(repo, timepoint) os.chdir(abspath) command = [ 'git', 'checkout', commit, ] output = subprocess.check_output(command, stderr=subprocess.STDOUT) LOGGER.debug("Checked out %s at %s", repo, timepoint.date().isoformat()) return output TEST_FUNCTION_PATTERN = re.compile(r'\s+