Improved resilience
This commit is contained in:
parent
2ca01d21b3
commit
6f42fe09b4
|
@ -7,6 +7,10 @@ import datetime
|
||||||
from collections.abc import Iterator, Sequence
|
from collections.abc import Iterator, Sequence
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('repositories', action='extend', nargs='+', type=Path)
|
parser.add_argument('repositories', action='extend', nargs='+', type=Path)
|
||||||
|
@ -28,9 +32,17 @@ def determine_default(repo: git.Repo):
|
||||||
HIDDEN_LABEL_PREFIX = '__'
|
HIDDEN_LABEL_PREFIX = '__'
|
||||||
HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL'
|
HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL'
|
||||||
|
|
||||||
|
def determine_project_name(repo: git.Repo) -> str:
|
||||||
|
remotes = repo.remotes
|
||||||
|
if len(remotes) > 0:
|
||||||
|
return remotes.origin.url.removeprefix('git@gitfub.space:')
|
||||||
|
return Path(repo.working_tree_dir).name
|
||||||
|
|
||||||
def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
|
def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
|
||||||
labels = [HIDDEN_LABEL_TOTAL]
|
labels = [HIDDEN_LABEL_TOTAL]
|
||||||
labels.append(repo.remotes.origin.url.removeprefix('git@gitfub.space:'))
|
name = determine_project_name(repo)
|
||||||
|
assert name is not None
|
||||||
|
labels.append(name)
|
||||||
|
|
||||||
# TODO: Branch on main or master or default
|
# TODO: Branch on main or master or default
|
||||||
|
|
||||||
|
@ -79,11 +91,18 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
|
||||||
yield ' {label:40} {hours:-4.0f} hours\n'.format(label='TOTAL', hours = time_per_label[HIDDEN_LABEL_TOTAL] / HOUR)
|
yield ' {label:40} {hours:-4.0f} hours\n'.format(label='TOTAL', hours = time_per_label[HIDDEN_LABEL_TOTAL] / HOUR)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logging.basicConfig()
|
||||||
|
|
||||||
args = parse_arguments()
|
args = parse_arguments()
|
||||||
|
|
||||||
shared_time_stamps: set[WorkSample] = set()
|
shared_time_stamps: set[WorkSample] = set()
|
||||||
for repo_path in args.repositories:
|
for repo_path in args.repositories:
|
||||||
|
try:
|
||||||
repo = git.Repo(repo_path)
|
repo = git.Repo(repo_path)
|
||||||
|
except git.exc.InvalidGitRepositoryError:
|
||||||
|
logger.warning('Ignoring non-repo %s', repo_path)
|
||||||
|
continue
|
||||||
|
logger.warning('Visit %s', repo_path)
|
||||||
shared_time_stamps |= set(get_samples_from_project(repo))
|
shared_time_stamps |= set(get_samples_from_project(repo))
|
||||||
|
|
||||||
shared_time_stamps = sorted(shared_time_stamps)
|
shared_time_stamps = sorted(shared_time_stamps)
|
||||||
|
|
Reference in New Issue
Block a user