Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -36,7 +36,9 @@ class Get_Url(Cmdlet):
name="get-url",
summary="List url associated with a file, or search urls by pattern",
usage='@1 | get-url OR get-url -url "https://www.youtube.com/watch?v=xx"',
arg=[SharedArgs.QUERY, SharedArgs.STORE, SharedArgs.URL],
arg=[SharedArgs.QUERY,
SharedArgs.STORE,
SharedArgs.URL],
detail=[
"- Get url for file: @1 | get-url (requires hash+store from result)",
'- Search url across stores: get-url -url "www.google.com" (strips protocol & www prefix)',
@@ -79,9 +81,11 @@ class Get_Url(Cmdlet):
# Use fnmatch for wildcard matching (* and ?)
return fnmatch(normalized_url, normalized_pattern)
def _search_urls_across_stores(
self, pattern: str, config: Dict[str, Any]
) -> Tuple[List[UrlItem], List[str]]:
def _search_urls_across_stores(self,
pattern: str,
config: Dict[str,
Any]) -> Tuple[List[UrlItem],
List[str]]:
"""Search for URLs matching pattern across all stores.
Returns:
@@ -92,7 +96,8 @@ class Get_Url(Cmdlet):
try:
storage = Store(config)
store_names = storage.list_backends() if hasattr(storage, "list_backends") else []
store_names = storage.list_backends() if hasattr(storage,
"list_backends") else []
if not store_names:
log("Error: No stores configured", file=sys.stderr)
@@ -111,7 +116,8 @@ class Get_Url(Cmdlet):
search_results = backend.search("*", limit=1000)
if search_results:
for result in search_results:
file_hash = result.get("hash") or result.get("file_hash")
file_hash = result.get("hash"
) or result.get("file_hash")
if not file_hash:
continue
@@ -119,7 +125,8 @@ class Get_Url(Cmdlet):
urls = backend.get_url(file_hash)
if urls:
for url in urls:
if self._match_url_pattern(str(url), pattern):
if self._match_url_pattern(str(url),
pattern):
items.append(
UrlItem(
url=str(url),
@@ -137,7 +144,10 @@ class Get_Url(Cmdlet):
except KeyError:
continue
except Exception as exc:
debug(f"Error searching store '{store_name}': {exc}", file=sys.stderr)
debug(
f"Error searching store '{store_name}': {exc}",
file=sys.stderr
)
continue
return items, list(found_stores)
@@ -165,15 +175,16 @@ class Get_Url(Cmdlet):
from result_table import ResultTable
table = (
ResultTable("URL Search Results", max_columns=3)
.set_preserve_order(True)
.set_table("urls")
.set_value_case("preserve")
ResultTable(
"URL Search Results",
max_columns=3
).set_preserve_order(True).set_table("urls").set_value_case("preserve")
)
table.set_source_command("get-url", ["-url", search_pattern])
# Group by store for display
by_store: Dict[str, List[UrlItem]] = {}
by_store: Dict[str,
List[UrlItem]] = {}
for item in items:
if item.store not in by_store:
by_store[item.store] = []
@@ -195,7 +206,9 @@ class Get_Url(Cmdlet):
ctx.emit(item)
ctx.set_last_result_table(table if items else None, items, subject=result)
log(f"Found {len(items)} matching url(s) in {len(stores_searched)} store(s)")
log(
f"Found {len(items)} matching url(s) in {len(stores_searched)} store(s)"
)
return 0
# Original mode: Get URLs for a specific file by hash+store
@@ -209,7 +222,9 @@ class Get_Url(Cmdlet):
store_name = parsed.get("store") or get_field(result, "store")
if not file_hash:
log('Error: No file hash provided (pipe an item or use -query "hash:<sha256>")')
log(
'Error: No file hash provided (pipe an item or use -query "hash:<sha256>")'
)
return 1
if not store_name:
@@ -237,10 +252,10 @@ class Get_Url(Cmdlet):
table_title = f"Title: {title}"
table = (
ResultTable(table_title, max_columns=1)
.set_preserve_order(True)
.set_table("url")
.set_value_case("preserve")
ResultTable(
table_title,
max_columns=1
).set_preserve_order(True).set_table("url").set_value_case("preserve")
)
table.set_source_command("get-url", [])