From 827d0771a6d862a7089ab575138276353fbd38c9 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 27 Aug 2024 21:04:37 +0200 Subject: [PATCH] Remember icalendar dependency --- git_time_tracker/__init__.py | 44 +++++++++++++++++++++++----- git_time_tracker/format/icalendar.py | 14 +++++---- requirements.txt | 1 + 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index ece2e8a..ac47b11 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -39,7 +39,7 @@ from .data import ( WorkSample, ) from .format import cli, icalendar -from .source import git_repo +from .source import git_repo, csv_file logger = logging.getLogger(__name__) @@ -94,6 +94,15 @@ def parse_arguments(): nargs='+', type=Path, dest='repositories', + default=[], + ) + parser.add_argument( + '--csv-file', + action='extend', + nargs='+', + type=Path, + dest='csv_files', + default=[], ) parser.add_argument( '--filter', @@ -113,31 +122,52 @@ def parse_arguments(): ) return parser.parse_args() +def load_samples(args): + shared_time_stamps_set: set[WorkSample] = set() + + # Git repositories + for repo_path in args.repositories: + logger.warning('Determine commits from %s', repo_path) + shared_time_stamps_set |= set( + git_repo.iterate_samples_from_git_repository(repo_path), + ) + del repo_path + + # CSV Files + for csv_path in args.csv_files: + logger.warning('Load samples from %s', csv_path) + shared_time_stamps_set |= set( + csv_file.iterate_samples_from_csv_file(csv_path), + ) + del csv_path + + + return shared_time_stamps_set def main(): logging.basicConfig() args = parse_arguments() - shared_time_stamps_set: set[WorkSample] = set() - for repo_path in args.repositories: - logger.warning('Visit %s', repo_path) - shared_time_stamps_set |= set( - git_repo.iterate_samples_from_git_repository(repo_path), - ) + # Determine samples + shared_time_stamps_set = load_samples(args) + # Sort samples shared_time_stamps = sorted(shared_time_stamps_set, key=lambda s: s.end_at) del shared_time_stamps_set + # Filter samples sample_filter = args.sample_filter if len(sample_filter) != 0: logger.warning('Filtering %s samples', len(shared_time_stamps)) shared_time_stamps = filter_samples(shared_time_stamps, sample_filter) logger.warning('Filtered down to %s samples', len(shared_time_stamps)) + # Heuristic samples logger.warning('Realizing %s samples', len(shared_time_stamps)) shared_time_stamps = list(heuristically_realize_samples(shared_time_stamps)) + # Output format if args.format_mode == 'cli_report': for t in cli.generate_report(shared_time_stamps): sys.stdout.write(t) diff --git a/git_time_tracker/format/icalendar.py b/git_time_tracker/format/icalendar.py index 8d1e265..ccfab78 100644 --- a/git_time_tracker/format/icalendar.py +++ b/git_time_tracker/format/icalendar.py @@ -9,15 +9,19 @@ HOUR = datetime.timedelta(hours=1) MINUTE = datetime.timedelta(minutes=1) -def create_title(sample: RealizedWorkSample) -> str: +def create_title(sample: RealizedWorkSample) -> tuple[str,str]: ls = [] + desc = [] for label_and_type in sample.labels: if label_and_type.startswith(HIDDEN_LABEL_PREFIX): continue if label_and_type.startswith('author:'): continue - ls.append(label_and_type) - return ' '.join(ls) + if len(ls) == 0: + ls.append(label_and_type.split(':')[1]) + else: + desc.append(label_and_type) + return ' '.join(ls), '\n'.join(desc) def generate_calendar( @@ -30,9 +34,7 @@ def generate_calendar( cal.add('version', '2.0') for sample in samples: - title = create_title(sample) - - description = '' + title, description = create_title(sample) # Create event event = icalendar.Event() diff --git a/requirements.txt b/requirements.txt index 64b1ada..dacab06 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ GitPython +icalendar