Reduce accidental complexity across three files

sitecustomize.py:
- Replace _PATCHES dispatch dict with if/elif in exec_module; removes
  coupling between dispatch and _record_status's count barrier
- Drop _record_status count barrier entirely; both patches fire within
  milliseconds during the same import sequence, write-on-every-call is safe
- Replace _broken_url regex with str.partition + startswith checks; same
  semantics, no regex knowledge required to read
- Replace @staticmethod decorator inside plain function with explicit
  staticmethod() assignment; decorator form creates a descriptor object,
  not a callable, which confuses readers expecting class-body usage

apply.sh:
- Inline warn/ok helpers; each was one echo with a prefix, the indirection
  cost more than the abstraction saved
- Collapse patch_ui.py if/else (whose if branch was a no-op comment) to
  a single || fallback line

create_task.py:
- Remove vestigial (_client, _args) params from cmd_verify; it was pulled
  out of dispatch, the params were never used
- Replace 3-entry dispatch dict with if/elif; dict implied a uniform calling
  convention that verify already broke
This commit is contained in:
2026-06-15 03:08:52 +00:00
parent 4b07ce459a
commit ebca3f99cc
3 changed files with 28 additions and 53 deletions
+8 -8
View File
@@ -83,7 +83,7 @@ def make_client(host, api_key, insecure=False):
# ── Sub-commands ──────────────────────────────────────────────────────────────
def cmd_verify(_client, _args):
def cmd_verify():
"""Print the hook status written by sitecustomize.py at middlewared startup."""
if not os.path.exists(_STATUS_FILE):
print("No hook status file found.")
@@ -233,19 +233,19 @@ def main():
args = p.parse_args()
if args.cmd == "verify":
cmd_verify(None, args)
cmd_verify()
return
if not args.host or not args.api_key:
p.error("--host and --api-key are required for this command")
client = make_client(args.host, args.api_key, args.insecure)
dispatch = {
"list-credentials": cmd_list_credentials,
"list-tasks": cmd_list_tasks,
"create": cmd_create,
}
dispatch[args.cmd](client, args)
if args.cmd == "list-credentials":
cmd_list_credentials(client, args)
elif args.cmd == "list-tasks":
cmd_list_tasks(client, args)
elif args.cmd == "create":
cmd_create(client, args)
if __name__ == "__main__":