diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-04-03 21:22:49 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-04-03 21:25:32 +0200 |
commit | 5b051b9f97892784d281556db3d5f8b01671568d (patch) | |
tree | 43696127254b28ac1aed2c507d7f3bc4e321c046 | |
parent | 7ddf5e685ceff763f309df8d3ba43fb9762265a8 (diff) | |
download | fietsboek-5b051b9f97892784d281556db3d5f8b01671568d.tar.gz fietsboek-5b051b9f97892784d281556db3d5f8b01671568d.tar.bz2 fietsboek-5b051b9f97892784d281556db3d5f8b01671568d.zip |
add a fietsctl hittekaart --delete option
-rw-r--r-- | fietsboek/scripts/fietsctl.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py index 8be226a..7f7170c 100644 --- a/fietsboek/scripts/fietsctl.py +++ b/fietsboek/scripts/fietsctl.py @@ -9,6 +9,7 @@ from pyramid.scripting import AppEnvironment from sqlalchemy import select from .. import __VERSION__, hittekaart, models +from ..data import DataManager from . import config_option EXIT_OKAY = 0 @@ -229,6 +230,7 @@ def cmd_maintenance_mode(ctx: click.Context, config: str, disable: bool, reason: multiple=True, default=["heatmap"], ) +@click.option("--delete", help="Delete the specified heatmap", is_flag=True) @optgroup.group("User selection", cls=RequiredMutuallyExclusiveOptionGroup) @optgroup.option("--id", "-i", "id_", help="database ID of the user", type=int) @optgroup.option("--email", "-e", help="email of the user") @@ -237,6 +239,7 @@ def cmd_hittekaart( ctx: click.Context, config: str, modes: list[str], + delete: bool, id_: Optional[int], email: Optional[str], ): @@ -252,12 +255,23 @@ def cmd_hittekaart( exe_path = env["request"].config.hittekaart_bin with env["request"].tm: dbsession = env["request"].dbsession - data_manager = env["request"].data_manager + data_manager: DataManager = env["request"].data_manager user = dbsession.execute(query).scalar_one_or_none() if user is None: click.echo("Error: No such user found.", err=True) ctx.exit(EXIT_FAILURE) + if delete: + try: + user_manager = data_manager.open_user(user.id) + except FileNotFoundError: + return + if hittekaart.Mode.HEATMAP in modes: + user_manager.heatmap_path().unlink(missing_ok=True) + if hittekaart.Mode.TILEHUNTER in modes: + user_manager.tilehunt_path().unlink(missing_ok=True) + return + click.echo(f"Generating overlay maps for {user.name}...") for mode in modes: |