1
0

Remember icalendar dependency

This commit is contained in:
Jon Michael Aanes 2024-08-27 21:04:37 +02:00
parent 9656b884e0
commit 827d0771a6
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 46 additions and 13 deletions

View File

@ -39,7 +39,7 @@ from .data import (
WorkSample, WorkSample,
) )
from .format import cli, icalendar from .format import cli, icalendar
from .source import git_repo from .source import git_repo, csv_file
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -94,6 +94,15 @@ def parse_arguments():
nargs='+', nargs='+',
type=Path, type=Path,
dest='repositories', dest='repositories',
default=[],
)
parser.add_argument(
'--csv-file',
action='extend',
nargs='+',
type=Path,
dest='csv_files',
default=[],
) )
parser.add_argument( parser.add_argument(
'--filter', '--filter',
@ -113,31 +122,52 @@ def parse_arguments():
) )
return parser.parse_args() 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(): def main():
logging.basicConfig() logging.basicConfig()
args = parse_arguments() args = parse_arguments()
shared_time_stamps_set: set[WorkSample] = set() # Determine samples
for repo_path in args.repositories: shared_time_stamps_set = load_samples(args)
logger.warning('Visit %s', repo_path)
shared_time_stamps_set |= set(
git_repo.iterate_samples_from_git_repository(repo_path),
)
# Sort samples
shared_time_stamps = sorted(shared_time_stamps_set, key=lambda s: s.end_at) shared_time_stamps = sorted(shared_time_stamps_set, key=lambda s: s.end_at)
del shared_time_stamps_set del shared_time_stamps_set
# Filter samples
sample_filter = args.sample_filter sample_filter = args.sample_filter
if len(sample_filter) != 0: if len(sample_filter) != 0:
logger.warning('Filtering %s samples', len(shared_time_stamps)) logger.warning('Filtering %s samples', len(shared_time_stamps))
shared_time_stamps = filter_samples(shared_time_stamps, sample_filter) shared_time_stamps = filter_samples(shared_time_stamps, sample_filter)
logger.warning('Filtered down to %s samples', len(shared_time_stamps)) logger.warning('Filtered down to %s samples', len(shared_time_stamps))
# Heuristic samples
logger.warning('Realizing %s samples', len(shared_time_stamps)) logger.warning('Realizing %s samples', len(shared_time_stamps))
shared_time_stamps = list(heuristically_realize_samples(shared_time_stamps)) shared_time_stamps = list(heuristically_realize_samples(shared_time_stamps))
# Output format
if args.format_mode == 'cli_report': if args.format_mode == 'cli_report':
for t in cli.generate_report(shared_time_stamps): for t in cli.generate_report(shared_time_stamps):
sys.stdout.write(t) sys.stdout.write(t)

View File

@ -9,15 +9,19 @@ HOUR = datetime.timedelta(hours=1)
MINUTE = datetime.timedelta(minutes=1) MINUTE = datetime.timedelta(minutes=1)
def create_title(sample: RealizedWorkSample) -> str: def create_title(sample: RealizedWorkSample) -> tuple[str,str]:
ls = [] ls = []
desc = []
for label_and_type in sample.labels: for label_and_type in sample.labels:
if label_and_type.startswith(HIDDEN_LABEL_PREFIX): if label_and_type.startswith(HIDDEN_LABEL_PREFIX):
continue continue
if label_and_type.startswith('author:'): if label_and_type.startswith('author:'):
continue continue
ls.append(label_and_type) if len(ls) == 0:
return ' '.join(ls) ls.append(label_and_type.split(':')[1])
else:
desc.append(label_and_type)
return ' '.join(ls), '\n'.join(desc)
def generate_calendar( def generate_calendar(
@ -30,9 +34,7 @@ def generate_calendar(
cal.add('version', '2.0') cal.add('version', '2.0')
for sample in samples: for sample in samples:
title = create_title(sample) title, description = create_title(sample)
description = ''
# Create event # Create event
event = icalendar.Event() event = icalendar.Event()

View File

@ -1 +1,2 @@
GitPython GitPython
icalendar