Tweak kimai check command

This commit is contained in:
3wc 2023-11-01 21:56:08 +00:00
parent 21fc28a14e
commit be1a8a7f7a

View File

@ -347,14 +347,14 @@ def _get_kimai_mapping_file(path, category_search=None):
return open(path)
@kimai.command("sync")
@kimai.command()
@click.option(
"--mapping-path",
help="Mapping file (default ~/.local/share/hamster/mapping.kimai.csv)",
multiple=True,
)
@click.argument("username")
@click.argument("api_key")
@click.argument("api_key", envvar="KIMAI_API_KEY")
@click.option("--just-errors", "just_errors", is_flag=True, help="Only display errors")
@click.option("--ignore-activities", is_flag=True, help="Ignore missing activities")
def check(username, api_key, just_errors, ignore_activities, mapping_path=None):
@ -364,18 +364,19 @@ def check(username, api_key, just_errors, ignore_activities, mapping_path=None):
kimai_api_url = "https://kimai.autonomic.zone/api"
if type(mapping_path) == tuple:
if len(mapping_path) == 0:
mapping_path = (HAMSTER_DIR / "mapping.kimai.csv",)
mapping_files = []
for mapping_path_item in mapping_path:
if not Path(mapping_path_item).exists():
raise click.UsageError(f'{mapping_path_item} does not exist')
mapping_file = _get_kimai_mapping_file(mapping_path_item)
next(mapping_file)
mapping_files.append(mapping_file)
mapping_reader = csv.reader(chain(*mapping_files))
else:
if mapping_path is None:
mapping_path = HAMSTER_DIR / "mapping.kimai.csv"
mapping_file = _get_kimai_mapping_file(mapping_path)
mapping_reader = csv.reader(mapping_file)
next(mapping_reader)
@ -401,7 +402,6 @@ def check(username, api_key, just_errors, ignore_activities, mapping_path=None):
for row in mapping_data:
# Check if each mapping still exists in Kimai
matching_customers = list(filter(lambda x: x["name"] == row[0], customers))
if row[0] in found_customers:
just_errors or click.secho(