scripts: csv.py: Added explicit z field, reusing -Z/--children

In an effort to move away from magic usage of -i/--enumerate, this adds
an explicit z field for differentiating -r/--hot results (and for normal
recursive results).

Instead of trying to think of a new flag to control this, this just
piggybacks on -Z/--children, which now accepts a tuple:

- ./scripts/csv.py -z3 -Z
- ./scripts/csv.py -z3 -Zchildren
- ./scripts/csv.py -z3 -Zz,children

The only tricky bit was needing to insert z in front of the by fields,
otherwise it was mostly a simplification from the enumerate mess.

Another positive side-effect: -r/--hot (and -z/--depth) now implies
-Zz,children, removing the annoying/confusing behavior of hotify folding
results by default.
This commit is contained in:
Christopher Haster
2026-01-23 01:00:22 -06:00
parent 078a1fb4c6
commit ac338e66f0
6 changed files with 71 additions and 65 deletions
+6 -9
View File
@@ -150,6 +150,7 @@ class CtxResult(co.namedtuple('CtxResult', [
_fields = ['off', 'size']
_sort = ['size']
_types = {'off': CsvInt, 'size': CsvInt}
_z = 'z'
_children = 'children'
_notes = 'notes'
@@ -814,14 +815,14 @@ def fold(Result, results, *,
return folded
def hotify(Result, results, *,
enumerates=None,
depth=1,
hot=None,
**_):
# note! hotifying risks confusion if you don't enumerate/have a
# z field, since it will allow folding across recursive boundaries
# note! hotifying risks confusion if you don't have a z field, since
# it will allow folding across recursive boundaries
# hotify only makes sense for recursive results
assert hasattr(Result, '_z')
assert hasattr(Result, '_children')
results_ = []
@@ -843,12 +844,8 @@ def hotify(Result, results, *,
for k_ in ([k] if k else Result._sort)))
for k, reverse in it.chain(hot, [(None, False)])))
hot_.append(r._replace(**(
# enumerate?
({e: len(hot_) for e in enumerates}
if enumerates is not None
else {})
| {Result._children: []})))
# flatten, dropping children
hot_.append(r._replace(**{Result._children: []}))
# recurse?
if depth_ > 1: