Commit fc50150
committed
refactor(tools): modernise basket-* helpers around a shared _basket module
Bring basket-compare, basket-join and basket-remove-uuids onto
the same shape as the rest of the tools/ tree, and introduce
`tools/_basket.py` for the load / save / duplicate-key plumbing
that each of the three previously rolled on its own.
_common.py:
- Add `dummy` to SKIP_PLUGINS. The `check-plugins/dummy` plugin
is the minimal argparse-plus-output skeleton and should never
have been picked up by tools that walk check-plugins/.
- Generalise `iter_check_plugins()` into `iter_plugin_dirs(subdir)`
so tools that also walk notification-plugins/ can reuse the
same sorted, SKIP_PLUGINS-aware iterator.
_basket.py (new):
- DuplicateKeyError + _raise_on_duplicate_keys (previously
duplicated as private helpers inside each basket-* tool).
- load_basket(path) / save_basket(path, data). Both abort via
`_common.die()` on unrecoverable errors (missing file, invalid
JSON, duplicate keys) so callers never grow the same
`if not success: sys.exit()` dance again.
basket-remove-uuids:
- Drop the unused colorama warn_print / err_print wrappers, the
dead `skip_plugins` list, the BasketUUIDRemover class wrapper
(there were only two meaningful methods) and the leftover
plugin-style `sys.exit(3)` path.
- Use `_basket.load_basket` / `_basket.save_basket`, keep only
the pure `remove_uuids()` walker.
basket-join:
- Replace the `os.listdir('check-plugins')` / `os.listdir(
'notification-plugins')` pair with the sorted
`_common.iter_plugin_dirs()` iterator, which additionally
respects the SKIP_PLUGINS set. This is a deterministic ordering
change: the old version's per-plugin order depended on the
file system (ext4/xfs hash order), so datafield numeric IDs in
the merged output used to shift between machines; the new
version always produces the same IDs given the same inputs.
The set of merged objects is unchanged (same 1938 Datafields,
293 Commands, 96 DataLists, etc. with identical uuids).
- Replace the colorama err_print / warn_print wrappers with
`_common.err` / `_common.die` plain-stderr output.
- Drop the skip_plugins hardcoded list now that SKIP_PLUGINS
lives in _common.
basket-compare:
- Replace the plugin-style `try: parse_args() except SystemExit:
sys.exit(STATE_UNKNOWN)` / `lib.base.cu()` / `lib.base.oao('')`
scaffolding with a plain main() that uses `_common.die()` for
real errors.
- Replace the `exit()` builtin call in `get_service_sets_diff`
with a proper `_common.die()` so the "unhandled deepdiff
category" branch actually says what went wrong.
- Clean up `get_val()` so the `d is None` case is handled on the
first line instead of being overwritten after the type check.
- Fold the five identical "normalise-compare-get_diff-print_table"
blocks in `main()` into a SECTIONS tuple + loop. 175 lines of
near-duplicated code drop to ~20, and adding a new Director
object class is now one SECTIONS entry.
build-basket:
- Drive-by fix caught by the linter sweep: rename the unused
`*args` / `**kwargs` parameters on `_return_parser_as_tuple`
to `*_args` / `*_kwargs` so vulture stops flagging them at
100% confidence. Phase-6 cleanup will touch this tool properly;
this commit only silences the warning.
Verified:
- `tools/run-linter-checks`: ruff, bandit, vulture all green.
- `tools/basket-join --output-file /tmp/basket-new.json`: exits
clean, 293 Commands, 1938 Datafields, 96 DataLists - identical
set and uuids to the pre-refactor run.
- `tools/basket-compare /tmp/basket-new.json /tmp/basket-new.json`:
exits 0 with no output (self-diff is empty).1 parent 2360883 commit fc50150
File tree
6 files changed
+425
-487
lines changed- tools
6 files changed
+425
-487
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
| |||
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
64 | | - | |
65 | | - | |
| 68 | + | |
| 69 | + | |
66 | 70 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
0 commit comments