"""# Git-based Time Tracker. Quick and dirty time tracker on git histories. Uses the simple heuristics that each commit takes precisely one hour of work. It will automatically trim commits below one hour if another commit occurred less than an hour ago. Usage: ``` python -m git_time_tracker REPO1 REPO2... ``` # Obligatory This tool reports: ``` project Jmaa/git-time-tracker.git 3h 33m (2024) ``` And the ([Hamster](https://github.com/projecthamster/hamster)) manual time tracker reports: ![](docs/obligatory-hamster.png) """ import argparse import datetime import logging import sys from pathlib import Path from .data import HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, WorkSample from .format import cli from .source import git_repo logger = logging.getLogger(__name__) DEFAULT_EST_TIME = datetime.timedelta(hours=1) ZERO_DURATION = datetime.timedelta(seconds=0) HOUR = datetime.timedelta(hours=1) MINUTE = datetime.timedelta(minutes=1) def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument( '--git-repo', action='extend', nargs='+', type=Path, dest='repositories', ) parser.add_argument( '--filter', action='extend', nargs='+', type=str, dest='sample_filter', default=[], ) return parser.parse_args() def main(): logging.basicConfig() args = parse_arguments() shared_time_stamps: set[WorkSample] = set() for repo_path in args.repositories: logger.warning('Visit %s', repo_path) shared_time_stamps |= set( git_repo.iterate_samples_from_git_repository(repo_path), ) shared_time_stamps = sorted(shared_time_stamps) for t in cli.generate_report(shared_time_stamps, sample_filter=args.sample_filter): sys.stdout.write(t)