Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -23,11 +23,13 @@ from SYS.utils import sha256_file
|
||||
|
||||
|
||||
class Add_Note(Cmdlet):
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
name="add-note",
|
||||
summary="Add file store note",
|
||||
usage='add-note (-query "title:<title>,text:<text>[,store:<store>][,hash:<sha256>]") [ -store <store> | <piped> ]',
|
||||
usage=
|
||||
'add-note (-query "title:<title>,text:<text>[,store:<store>][,hash:<sha256>]") [ -store <store> | <piped> ]',
|
||||
alias=[""],
|
||||
arg=[
|
||||
SharedArgs.STORE,
|
||||
@@ -38,16 +40,15 @@ class Add_Note(Cmdlet):
|
||||
type="string",
|
||||
required=False,
|
||||
handler=normalize_hash,
|
||||
description="(Optional) Specific file hash target, provided via -query as hash:<sha256>. When omitted, uses piped item hash.",
|
||||
description=
|
||||
"(Optional) Specific file hash target, provided via -query as hash:<sha256>. When omitted, uses piped item hash.",
|
||||
query_only=True,
|
||||
),
|
||||
SharedArgs.QUERY,
|
||||
],
|
||||
detail=[
|
||||
"""
|
||||
detail=["""
|
||||
dde
|
||||
"""
|
||||
],
|
||||
"""],
|
||||
exec=self.run,
|
||||
)
|
||||
# Populate dynamic store choices for autocomplete
|
||||
@@ -97,7 +98,7 @@ class Add_Note(Cmdlet):
|
||||
return None, None
|
||||
|
||||
try:
|
||||
from cli_syntax import parse_query, get_field
|
||||
from SYS.cli_syntax import parse_query, get_field
|
||||
except Exception:
|
||||
parse_query = None # type: ignore
|
||||
get_field = None # type: ignore
|
||||
@@ -113,16 +114,24 @@ class Add_Note(Cmdlet):
|
||||
return (name_s or None, text_s or None)
|
||||
|
||||
# Fallback: best-effort regex.
|
||||
name_match = re.search(r"\btitle\s*:\s*([^,\s]+)", normalized, flags=re.IGNORECASE)
|
||||
name_match = re.search(
|
||||
r"\btitle\s*:\s*([^,\s]+)",
|
||||
normalized,
|
||||
flags=re.IGNORECASE
|
||||
)
|
||||
text_match = re.search(r"\btext\s*:\s*(.+)$", normalized, flags=re.IGNORECASE)
|
||||
note_name = name_match.group(1).strip() if name_match else ""
|
||||
note_text = text_match.group(1).strip() if text_match else ""
|
||||
return (note_name or None, note_text or None)
|
||||
|
||||
def _resolve_hash(
|
||||
self, raw_hash: Optional[str], raw_path: Optional[str], override_hash: Optional[str]
|
||||
self,
|
||||
raw_hash: Optional[str],
|
||||
raw_path: Optional[str],
|
||||
override_hash: Optional[str]
|
||||
) -> Optional[str]:
|
||||
resolved = normalize_hash(override_hash) if override_hash else normalize_hash(raw_hash)
|
||||
resolved = normalize_hash(override_hash
|
||||
) if override_hash else normalize_hash(raw_hash)
|
||||
if resolved:
|
||||
return resolved
|
||||
|
||||
@@ -130,7 +139,8 @@ class Add_Note(Cmdlet):
|
||||
try:
|
||||
p = Path(str(raw_path))
|
||||
stem = p.stem
|
||||
if len(stem) == 64 and all(c in "0123456789abcdef" for c in stem.lower()):
|
||||
if len(stem) == 64 and all(c in "0123456789abcdef"
|
||||
for c in stem.lower()):
|
||||
return stem.lower()
|
||||
if p.exists() and p.is_file():
|
||||
return sha256_file(p)
|
||||
@@ -171,10 +181,18 @@ class Add_Note(Cmdlet):
|
||||
try:
|
||||
store_registry = Store(config)
|
||||
backend = store_registry[str(store_override)]
|
||||
ok = bool(backend.set_note(str(hash_override), note_name, note_text, config=config))
|
||||
ok = bool(
|
||||
backend.set_note(
|
||||
str(hash_override),
|
||||
note_name,
|
||||
note_text,
|
||||
config=config
|
||||
)
|
||||
)
|
||||
if ok:
|
||||
ctx.print_if_visible(
|
||||
f"✓ add-note: 1 item in '{store_override}'", file=sys.stderr
|
||||
f"✓ add-note: 1 item in '{store_override}'",
|
||||
file=sys.stderr
|
||||
)
|
||||
except Exception as exc:
|
||||
log(f"[add_note] Error: Failed to set note: {exc}", file=sys.stderr)
|
||||
@@ -187,7 +205,10 @@ class Add_Note(Cmdlet):
|
||||
if not results:
|
||||
if explicit_target:
|
||||
# Allow standalone use (no piped input) and enable piping the target forward.
|
||||
results = [{"store": str(store_override), "hash": hash_override}]
|
||||
results = [{
|
||||
"store": str(store_override),
|
||||
"hash": hash_override
|
||||
}]
|
||||
else:
|
||||
log(
|
||||
'[add_note] Error: Requires piped item(s) from add-file, or explicit targeting via store/hash (e.g., -query "store:<store> hash:<sha256> ...")',
|
||||
@@ -199,7 +220,10 @@ class Add_Note(Cmdlet):
|
||||
updated = 0
|
||||
|
||||
# Batch write plan: store -> [(hash, name, text), ...]
|
||||
note_ops: Dict[str, List[Tuple[str, str, str]]] = {}
|
||||
note_ops: Dict[str,
|
||||
List[Tuple[str,
|
||||
str,
|
||||
str]]] = {}
|
||||
|
||||
for res in results:
|
||||
if not isinstance(res, dict):
|
||||
@@ -213,7 +237,10 @@ class Add_Note(Cmdlet):
|
||||
raw_path = res.get("path")
|
||||
|
||||
if not store_name:
|
||||
log("[add_note] Error: Missing -store and item has no store field", file=sys.stderr)
|
||||
log(
|
||||
"[add_note] Error: Missing -store and item has no store field",
|
||||
file=sys.stderr
|
||||
)
|
||||
return 1
|
||||
|
||||
resolved_hash = self._resolve_hash(
|
||||
@@ -222,19 +249,28 @@ class Add_Note(Cmdlet):
|
||||
override_hash=str(hash_override) if hash_override else None,
|
||||
)
|
||||
if not resolved_hash:
|
||||
log("[add_note] Warning: Item missing usable hash; skipping", file=sys.stderr)
|
||||
log(
|
||||
"[add_note] Warning: Item missing usable hash; skipping",
|
||||
file=sys.stderr
|
||||
)
|
||||
ctx.emit(res)
|
||||
continue
|
||||
|
||||
try:
|
||||
backend = store_registry[store_name]
|
||||
except Exception as exc:
|
||||
log(f"[add_note] Error: Unknown store '{store_name}': {exc}", file=sys.stderr)
|
||||
log(
|
||||
f"[add_note] Error: Unknown store '{store_name}': {exc}",
|
||||
file=sys.stderr
|
||||
)
|
||||
return 1
|
||||
|
||||
# Queue for bulk write per store. We still emit items immediately;
|
||||
# the pipeline only advances after this cmdlet returns.
|
||||
note_ops.setdefault(store_name, []).append((resolved_hash, note_name, item_note_text))
|
||||
note_ops.setdefault(store_name,
|
||||
[]).append((resolved_hash,
|
||||
note_name,
|
||||
item_note_text))
|
||||
updated += 1
|
||||
|
||||
ctx.emit(res)
|
||||
@@ -255,7 +291,8 @@ class Add_Note(Cmdlet):
|
||||
ok = bool(bulk_fn(list(ops), config=config))
|
||||
wrote_any = wrote_any or ok or True
|
||||
ctx.print_if_visible(
|
||||
f"✓ add-note: {len(ops)} item(s) in '{store_name}'", file=sys.stderr
|
||||
f"✓ add-note: {len(ops)} item(s) in '{store_name}'",
|
||||
file=sys.stderr
|
||||
)
|
||||
continue
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user