Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -54,7 +54,8 @@ class Delete_Url(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 +63,22 @@ class Delete_Url(Cmdlet):
|
||||
return 1
|
||||
|
||||
# Extract hash and store from result or args
|
||||
file_hash = query_hash or (get_field(result, "hash") if result is not None else None)
|
||||
file_hash = query_hash or (
|
||||
get_field(result,
|
||||
"hash") if result is not None else None
|
||||
)
|
||||
store_name = parsed.get("store") or (
|
||||
get_field(result, "store") if result is not None else None
|
||||
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")
|
||||
@@ -110,7 +117,8 @@ class Delete_Url(Cmdlet):
|
||||
current = [str(u).strip() for u in existing if str(u).strip()]
|
||||
except Exception:
|
||||
current = []
|
||||
remove_set = {u for u in (remove or []) if u}
|
||||
remove_set = {u
|
||||
for u in (remove or []) if u}
|
||||
new_urls = [u for u in current if u not in remove_set]
|
||||
if len(new_urls) == 1:
|
||||
return new_urls[0]
|
||||
@@ -127,7 +135,9 @@ class Delete_Url(Cmdlet):
|
||||
return
|
||||
|
||||
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:
|
||||
@@ -146,14 +156,16 @@ class Delete_Url(Cmdlet):
|
||||
normalized = normalize_hash(raw_hash)
|
||||
if not normalized:
|
||||
ctx.print_if_visible(
|
||||
"[delete-url] Warning: Item has invalid hash; skipping", file=sys.stderr
|
||||
"[delete-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(
|
||||
"[delete-url] Warning: Item has empty store; skipping", file=sys.stderr
|
||||
"[delete-url] Warning: Item has empty store; skipping",
|
||||
file=sys.stderr
|
||||
)
|
||||
continue
|
||||
if not storage.is_available(store_text):
|
||||
@@ -169,15 +181,14 @@ class Delete_Url(Cmdlet):
|
||||
item_urls = list(urls_from_cli)
|
||||
if not item_urls:
|
||||
item_urls = [
|
||||
u.strip()
|
||||
for u in normalize_urls(
|
||||
u.strip() for u in normalize_urls(
|
||||
get_field(item, "url") or get_field(item, "source_url")
|
||||
)
|
||||
if str(u).strip()
|
||||
) if str(u).strip()
|
||||
]
|
||||
if not item_urls:
|
||||
ctx.print_if_visible(
|
||||
"[delete-url] Warning: Item has no url field; skipping", file=sys.stderr
|
||||
"[delete-url] Warning: Item has no url field; skipping",
|
||||
file=sys.stderr
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -189,7 +200,8 @@ class Delete_Url(Cmdlet):
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
merged: Dict[str, List[str]] = {}
|
||||
merged: Dict[str,
|
||||
List[str]] = {}
|
||||
for h, ulist in pairs:
|
||||
merged.setdefault(h, [])
|
||||
for u in ulist or []:
|
||||
@@ -220,11 +232,9 @@ class Delete_Url(Cmdlet):
|
||||
remove_set = urls_from_cli
|
||||
if not remove_set:
|
||||
remove_set = [
|
||||
u.strip()
|
||||
for u in normalize_urls(
|
||||
u.strip() for u in normalize_urls(
|
||||
get_field(item, "url") or get_field(item, "source_url")
|
||||
)
|
||||
if str(u).strip()
|
||||
) if str(u).strip()
|
||||
]
|
||||
_set_item_url(item, _remove_urls(existing, list(remove_set)))
|
||||
ctx.emit(item)
|
||||
@@ -233,11 +243,9 @@ class Delete_Url(Cmdlet):
|
||||
# Single-item mode
|
||||
if not urls_from_cli:
|
||||
urls_from_cli = [
|
||||
u.strip()
|
||||
for u in normalize_urls(
|
||||
u.strip() for u in normalize_urls(
|
||||
get_field(result, "url") or get_field(result, "source_url")
|
||||
)
|
||||
if str(u).strip()
|
||||
) if str(u).strip()
|
||||
]
|
||||
if not urls_from_cli:
|
||||
log("Error: No URL provided")
|
||||
@@ -246,7 +254,8 @@ class Delete_Url(Cmdlet):
|
||||
backend = storage[str(store_name)]
|
||||
backend.delete_url(str(file_hash), list(urls_from_cli), config=config)
|
||||
ctx.print_if_visible(
|
||||
f"✓ delete-url: {len(urls_from_cli)} url(s) removed", file=sys.stderr
|
||||
f"✓ delete-url: {len(urls_from_cli)} url(s) removed",
|
||||
file=sys.stderr
|
||||
)
|
||||
if result is not None:
|
||||
existing = get_field(result, "url")
|
||||
|
||||
Reference in New Issue
Block a user