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

@@ -20,7 +20,9 @@ class Add_Url(sh.Cmdlet):
arg=[
sh.SharedArgs.QUERY,
sh.SharedArgs.STORE,
sh.CmdletArg("url", required=True, description="URL to associate"),
sh.CmdletArg("url",
required=True,
description="URL to associate"),
],
detail=[
"- Associates URL with file identified by hash+store",
@@ -54,7 +56,8 @@ class Add_Url(sh.Cmdlet):
# Bulk input is common in pipelines; treat a list of PipeObjects as a batch.
results: List[Any] = (
result if isinstance(result, list) else ([result] if result is not None else [])
result if isinstance(result,
list) else ([result] if result is not None else [])
)
if query_hash and len(results) > 1:
@@ -62,16 +65,22 @@ class Add_Url(sh.Cmdlet):
return 1
# Extract hash and store from result or args
file_hash = query_hash or (sh.get_field(result, "hash") if result is not None else None)
file_hash = query_hash or (
sh.get_field(result,
"hash") if result is not None else None
)
store_name = parsed.get("store") or (
sh.get_field(result, "store") if result is not None else None
sh.get_field(result,
"store") if result is not None else None
)
url_arg = parsed.get("url")
# If we have multiple piped items, we will resolve hash/store per item below.
if not results:
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:
log("Error: No store name provided")
@@ -102,7 +111,9 @@ class Add_Url(sh.Cmdlet):
out: List[str] = []
try:
if isinstance(existing, str):
out.extend([p.strip() for p in existing.split(",") if p.strip()])
out.extend(
[p.strip() for p in existing.split(",") if p.strip()]
)
elif isinstance(existing, (list, tuple)):
out.extend([str(u).strip() for u in existing if str(u).strip()])
except Exception:
@@ -131,7 +142,9 @@ class Add_Url(sh.Cmdlet):
# Build batches per store.
store_override = parsed.get("store")
batch: Dict[str, List[Tuple[str, List[str]]]] = {}
batch: Dict[str,
List[Tuple[str,
List[str]]]] = {}
pass_through: List[Any] = []
if results:
@@ -142,21 +155,24 @@ class Add_Url(sh.Cmdlet):
raw_store = store_override or sh.get_field(item, "store")
if not raw_hash or not raw_store:
ctx.print_if_visible(
"[add-url] Warning: Item missing hash/store; skipping", file=sys.stderr
"[add-url] Warning: Item missing hash/store; skipping",
file=sys.stderr
)
continue
normalized = sh.normalize_hash(raw_hash)
if not normalized:
ctx.print_if_visible(
"[add-url] Warning: Item has invalid hash; skipping", file=sys.stderr
"[add-url] Warning: Item has invalid hash; skipping",
file=sys.stderr
)
continue
store_text = str(raw_store).strip()
if not store_text:
ctx.print_if_visible(
"[add-url] Warning: Item has empty store; skipping", file=sys.stderr
"[add-url] Warning: Item has empty store; skipping",
file=sys.stderr
)
continue
@@ -178,7 +194,8 @@ class Add_Url(sh.Cmdlet):
continue
# Coalesce duplicates per hash before passing to backend.
merged: Dict[str, List[str]] = {}
merged: Dict[str,
List[str]] = {}
for h, ulist in pairs:
merged.setdefault(h, [])
for u in ulist or []:
@@ -210,7 +227,10 @@ class Add_Url(sh.Cmdlet):
# Single-item mode
backend = storage[str(store_name)]
backend.add_url(str(file_hash), urls, config=config)
ctx.print_if_visible(f"✓ add-url: {len(urls)} url(s) added", file=sys.stderr)
ctx.print_if_visible(
f"✓ add-url: {len(urls)} url(s) added",
file=sys.stderr
)
if result is not None:
existing = sh.get_field(result, "url")
merged = _merge_urls(existing, list(urls))