Skip to content

Commit 9a1c5ea

Browse files
authored
Merge pull request #41 from pganssle/add_reload_params
Add URL params to update
2 parents 5957892 + 228769b commit 9a1c5ea

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/audio_feeder/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ def run(host, port, config, profile):
9191
is_flag=True,
9292
help="Passed if metadata from all sources should be reloaded if present.",
9393
)
94+
@click.option(
95+
"--check-hashes",
96+
is_flag=True,
97+
help="Passed if the updater should re-check hashes existing in the database",
98+
)
9499
@click.argument("path", metavar="PATH", type=str, required=True)
95-
def update(content_type, reload_metadata, path):
100+
def update(content_type, reload_metadata, check_hashes, path):
96101
"""
97102
Add a specific path to the databases, loading all content and updating the
98103
database where necessary.
@@ -114,6 +119,8 @@ def pbar(msg: str) -> typing.Callable[[_T], _T]:
114119
content_type=content_type,
115120
path=path,
116121
progress_bar=pbar("Loading book metadata:"),
122+
reload_metadata=reload_metadata,
123+
check_hashes=check_hashes,
117124
)
118125

119126

src/audio_feeder/pages.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,33 @@ def update_status():
361361
)
362362

363363

364+
def _evaluate_bool_param(param: str) -> bool:
365+
return param.lower() == "true"
366+
367+
364368
@root.route("/update")
365369
def update():
370+
366371
with UPDATE_LOCK:
367372
if not updater.UPDATE_IN_PROGRESS:
373+
reload_metadata: bool = request.args.get(
374+
"reloadMetadata", type=_evaluate_bool_param, default=False
375+
)
376+
check_hashes: bool = request.args.get(
377+
"checkHashes", type=_evaluate_bool_param, default=False
378+
)
379+
380+
if reload_metadata or check_hashes:
381+
update_func = functools.partial(
382+
updater.update,
383+
reload_metadata=reload_metadata,
384+
check_hashes=check_hashes,
385+
)
386+
else:
387+
update_func = updater.update
388+
368389
updater.UPDATE_IN_PROGRESS = True
369-
background_thread = threading.Thread(target=updater.update, daemon=True)
390+
background_thread = threading.Thread(target=update_func, daemon=True)
370391
background_thread.start()
371392
return flask.redirect(flask.url_for("root.update_status"))
372393

src/audio_feeder/updater.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,10 @@ def _clear_update_output() -> None:
768768

769769

770770
def _update_books(
771-
update_path: str, progress_bar: typing.Optional[_PBar] = None
771+
update_path: str,
772+
progress_bar: typing.Optional[_PBar] = None,
773+
reload_metadata: bool = False,
774+
check_hashes: bool = False,
772775
) -> None:
773776
"""
774777
Trigger an update to the database.
@@ -782,10 +785,19 @@ def _update_books(
782785

783786
OpFunction = typing.Callable[[typing.Any], typing.Any]
784787
ops: typing.Sequence[typing.Tuple[OpFunction, str]] = [
785-
(book_updater.update_db_entries, "Updating database entries."),
788+
(
789+
functools.partial(
790+
book_updater.update_db_entries, check_hashes=check_hashes
791+
),
792+
"Updating database entries.",
793+
),
786794
(book_updater.assign_books_to_entries, "Assigning books to entries"),
787795
(
788-
functools.partial(book_updater.update_book_metadata, pbar=progress_bar),
796+
functools.partial(
797+
book_updater.update_book_metadata,
798+
reload_metadata=reload_metadata,
799+
pbar=progress_bar,
800+
),
789801
"Updating book metadata",
790802
),
791803
(book_updater.update_author_db, "Updating author db"),
@@ -815,13 +827,20 @@ def update(
815827
content_type: typing.Optional[str] = None,
816828
path: typing.Optional[str] = None,
817829
progress_bar: typing.Optional[_PBar] = None,
830+
reload_metadata: bool = False,
831+
check_hashes: bool = False,
818832
) -> None:
819833

820834
if path is None:
821835
path = "."
822836

823837
if content_type is None or content_type == "books":
824-
_update_books(update_path=path, progress_bar=progress_bar)
838+
_update_books(
839+
update_path=path,
840+
progress_bar=progress_bar,
841+
reload_metadata=reload_metadata,
842+
check_hashes=check_hashes,
843+
)
825844
else:
826845
raise ValueError(f"Unknown content type: {content_type}")
827846

0 commit comments

Comments
 (0)