fg
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
nose
2025-12-24 05:34:56 -08:00
parent 3ab96325cc
commit d7fc8c4576

View File

@@ -148,22 +148,27 @@ class Search_Provider(Cmdlet):
log(f" - {name}", file=sys.stderr) log(f" - {name}", file=sys.stderr)
return 1 return 1
from API.folder import API_folder_store
worker_id = str(uuid.uuid4()) worker_id = str(uuid.uuid4())
library_root = get_local_storage_path(config or {}) library_root = get_local_storage_path(config or {}) if get_local_storage_path else None
if not library_root:
log("No library root configured", file=sys.stderr)
return 1
# Use context manager to ensure database is always closed db = None
with API_folder_store(library_root) as db: if library_root:
try: try:
from API.folder import API_folder_store
db = API_folder_store(library_root)
except Exception:
db = None
try:
# Use the worker DB if available; otherwise, run as a stateless one-off.
if db is not None:
db.__enter__()
db.insert_worker( db.insert_worker(
worker_id, worker_id,
"search-provider", "search-provider",
title=f"Search: {query}", title=f"Search: {query}",
description=f"Provider: {provider_name}, Query: {query}", description=f"Provider: {provider_name}, Query: {query}",
pipe=ctx.get_current_command_text() pipe=ctx.get_current_command_text(),
) )
results_list = [] results_list = []
@@ -184,7 +189,7 @@ class Search_Provider(Cmdlet):
table_title = f"{provider_label} Files: {open_id}".strip().rstrip(":") table_title = f"{provider_label} Files: {open_id}".strip().rstrip(":")
else: else:
table_title = f"{provider_label}: {query}".strip().rstrip(":") table_title = f"{provider_label}: {query}".strip().rstrip(":")
preserve_order = provider_name.lower() in ('youtube', 'openlibrary') preserve_order = provider_name.lower() in ("youtube", "openlibrary")
table = ResultTable(table_title).set_preserve_order(preserve_order) table = ResultTable(table_title).set_preserve_order(preserve_order)
table.set_table(provider_name) table.set_table(provider_name)
table.set_source_command("search-provider", list(args)) table.set_source_command("search-provider", list(args))
@@ -203,17 +208,18 @@ class Search_Provider(Cmdlet):
if not results: if not results:
log(f"No results found for query: {query}", file=sys.stderr) log(f"No results found for query: {query}", file=sys.stderr)
if db is not None:
db.append_worker_stdout(worker_id, json.dumps([], indent=2)) db.append_worker_stdout(worker_id, json.dumps([], indent=2))
db.update_worker_status(worker_id, 'completed') db.update_worker_status(worker_id, "completed")
return 0 return 0
# Emit results for pipeline # Emit results for pipeline
for search_result in results: for search_result in results:
item_dict = search_result.to_dict() if hasattr(search_result, 'to_dict') else dict(search_result) item_dict = search_result.to_dict() if hasattr(search_result, "to_dict") else dict(search_result)
# Ensure table field is set (should be by provider, but just in case) # Ensure table field is set (should be by provider, but just in case)
if 'table' not in item_dict: if "table" not in item_dict:
item_dict['table'] = provider_name item_dict["table"] = provider_name
row_index = len(table.rows) row_index = len(table.rows)
table.add_result(search_result) # ResultTable handles SearchResult objects table.add_result(search_result) # ResultTable handles SearchResult objects
@@ -235,21 +241,29 @@ class Search_Provider(Cmdlet):
ctx.set_last_result_table(table, results_list) ctx.set_last_result_table(table, results_list)
# Ensure @N selection expands against this newly displayed table. # Ensure @N selection expands against this newly displayed table.
ctx.set_current_stage_table(table) ctx.set_current_stage_table(table)
if db is not None:
db.append_worker_stdout(worker_id, json.dumps(results_list, indent=2)) db.append_worker_stdout(worker_id, json.dumps(results_list, indent=2))
db.update_worker_status(worker_id, 'completed') db.update_worker_status(worker_id, "completed")
##log(f"Found {len(results)} result(s) from {provider_name}", file=sys.stderr)
return 0 return 0
except Exception as e: except Exception as e:
log(f"Error searching {provider_name}: {e}", file=sys.stderr) log(f"Error searching {provider_name}: {e}", file=sys.stderr)
import traceback import traceback
debug(traceback.format_exc()) debug(traceback.format_exc())
if db is not None:
try: try:
db.update_worker_status(worker_id, 'error') db.update_worker_status(worker_id, "error")
except Exception: except Exception:
pass pass
return 1 return 1
finally:
if db is not None:
try:
db.__exit__(None, None, None)
except Exception:
pass
# Register cmdlet instance (catalog + REPL autocomplete expects module-level CMDLET) # Register cmdlet instance (catalog + REPL autocomplete expects module-level CMDLET)