fdf
This commit is contained in:
@@ -18,8 +18,6 @@ normalize_hash = sh.normalize_hash
|
||||
parse_cmdlet_args = sh.parse_cmdlet_args
|
||||
normalize_result_input = sh.normalize_result_input
|
||||
should_show_help = sh.should_show_help
|
||||
from Store import Store
|
||||
from SYS.utils import sha256_file
|
||||
|
||||
|
||||
class Add_Note(Cmdlet):
|
||||
@@ -171,14 +169,6 @@ class Add_Note(Cmdlet):
|
||||
|
||||
return tokens
|
||||
|
||||
def _resolve_hash(
|
||||
self,
|
||||
raw_hash: Optional[str],
|
||||
raw_path: Optional[str],
|
||||
override_hash: Optional[str],
|
||||
) -> Optional[str]:
|
||||
return sh.resolve_hash_for_cmdlet(raw_hash, raw_path, override_hash)
|
||||
|
||||
def run(self, result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
if should_show_help(args):
|
||||
log(f"Cmdlet: {self.name}\nSummary: {self.summary}\nUsage: {self.usage}")
|
||||
@@ -217,8 +207,12 @@ class Add_Note(Cmdlet):
|
||||
# Direct targeting mode: apply note once to the explicit target and
|
||||
# pass through any piped items unchanged.
|
||||
try:
|
||||
store_registry = Store(config)
|
||||
backend = store_registry[str(store_override)]
|
||||
backend, _store_registry, exc = sh.get_store_backend(
|
||||
config,
|
||||
str(store_override),
|
||||
)
|
||||
if backend is None:
|
||||
raise exc or KeyError(store_override)
|
||||
ok = bool(
|
||||
backend.set_note(
|
||||
str(hash_override),
|
||||
@@ -262,7 +256,7 @@ class Add_Note(Cmdlet):
|
||||
)
|
||||
return 1
|
||||
|
||||
store_registry = Store(config)
|
||||
store_registry = None
|
||||
planned_ops = 0
|
||||
|
||||
# Batch write plan: store -> [(hash, name, text), ...]
|
||||
@@ -307,9 +301,12 @@ class Add_Note(Cmdlet):
|
||||
ctx.emit(res)
|
||||
continue
|
||||
|
||||
store_name = str(store_override or res.get("store") or "").strip()
|
||||
raw_hash = res.get("hash")
|
||||
raw_path = res.get("path")
|
||||
store_name, resolved_hash = sh.resolve_item_store_hash(
|
||||
res,
|
||||
override_store=str(store_override) if store_override else None,
|
||||
override_hash=str(hash_override) if hash_override else None,
|
||||
path_fields=("path",),
|
||||
)
|
||||
|
||||
if not store_name:
|
||||
log(
|
||||
@@ -318,11 +315,6 @@ class Add_Note(Cmdlet):
|
||||
)
|
||||
continue
|
||||
|
||||
resolved_hash = self._resolve_hash(
|
||||
raw_hash=str(raw_hash) if raw_hash else None,
|
||||
raw_path=str(raw_path) if raw_path else None,
|
||||
override_hash=str(hash_override) if hash_override else None,
|
||||
)
|
||||
if not resolved_hash:
|
||||
log(
|
||||
"[add_note] Warning: Item missing usable hash; skipping",
|
||||
@@ -343,23 +335,23 @@ class Add_Note(Cmdlet):
|
||||
|
||||
|
||||
# Execute batch operations
|
||||
success_count = 0
|
||||
for store_name, ops in note_ops.items():
|
||||
try:
|
||||
backend = store_registry[store_name]
|
||||
if not hasattr(backend, "set_note"):
|
||||
log(f"[add_note] Store '{store_name}' does not support notes", file=sys.stderr)
|
||||
continue
|
||||
|
||||
for (h, name, text) in ops:
|
||||
try:
|
||||
if backend.set_note(h, name, text, config=config):
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
log(f"[add_note] Write failed {store_name}:{h} ({name}): {e}", file=sys.stderr)
|
||||
|
||||
except Exception as e:
|
||||
log(f"[add_note] Store access failed '{store_name}': {e}", file=sys.stderr)
|
||||
def _on_store_error(store_name: str, exc: Exception) -> None:
|
||||
log(f"[add_note] Store access failed '{store_name}': {exc}", file=sys.stderr)
|
||||
|
||||
def _on_unsupported_store(store_name: str) -> None:
|
||||
log(f"[add_note] Store '{store_name}' does not support notes", file=sys.stderr)
|
||||
|
||||
def _on_item_error(store_name: str, hash_value: str, note_name_value: str, exc: Exception) -> None:
|
||||
log(f"[add_note] Write failed {store_name}:{hash_value} ({note_name_value}): {exc}", file=sys.stderr)
|
||||
|
||||
store_registry, success_count = sh.run_store_note_batches(
|
||||
config,
|
||||
note_ops,
|
||||
store_registry=store_registry,
|
||||
on_store_error=_on_store_error,
|
||||
on_unsupported_store=_on_unsupported_store,
|
||||
on_item_error=_on_item_error,
|
||||
)
|
||||
|
||||
if planned_ops > 0:
|
||||
msg = f"✓ add-note: Updated {success_count}/{planned_ops} notes across {len(note_ops)} stores"
|
||||
|
||||
Reference in New Issue
Block a user