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,
)
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)

View File

@ -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()

View File

@ -1 +1,2 @@
GitPython
icalendar