Skip to content

Commit 90ac8e6

Browse files
committed
python: support no_header in OutputFormat filter()
Problem: In the future the header may be needed in calculations within the OutputFormat filter() function. There is no way to inform the filter() function that the header should not be considered (for example, if the header fill not be output). Add a no_header flag to the filter() function in OutputFormat(). This parameter currently does nothing. Update all callers as needed.
1 parent 44e9999 commit 90ac8e6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/bindings/python/flux/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def format(self, obj):
948948
raise KeyError(f"Invalid format field {exc} for {typestr}")
949949
return retval
950950

951-
def filter(self, items):
951+
def filter(self, items, no_header=False):
952952
"""
953953
Check for format fields that are prefixed with `?:` (e.g. "?:{name}"),
954954
and filter them out of the current format string if they result in an
@@ -963,6 +963,7 @@ def filter(self, items):
963963
964964
Args:
965965
items (iterable): list of items to consider for output
966+
no_header (boolean): do not use header in calculations (default: False)
966967
"""
967968

968969
# Build a list of all format strings that have one of the width
@@ -1132,7 +1133,7 @@ def print_items(self, items, no_header=False, pre=None, post=None):
11321133
post (callable): Function to call after printing each item
11331134
"""
11341135
# Preprocess original format by processing with filter():
1135-
newfmt = self.filter(items)
1136+
newfmt = self.filter(items, no_header=no_header)
11361137
# Get the current class for creating a new formatter instance:
11371138
cls = self.__class__
11381139
# Create new instance of the current class from filtered format:

src/cmd/flux-jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def main():
545545
formatter.set_sort_keys(args.sort)
546546

547547
(jobs, truncated) = fetch_jobs(args, formatter.fields)
548-
sformatter = JobInfoFormat(formatter.filter(jobs))
548+
sformatter = JobInfoFormat(formatter.filter(jobs, no_header=args.no_header))
549549

550550
if not args.no_header:
551551
print(sformatter.header())

src/cmd/flux-pgrep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def main():
274274
if PROGRAM == "flux-pkill":
275275
pkill(fh, args, jobs)
276276

277-
sformatter = JobInfoFormat(formatter.filter(jobs))
277+
sformatter = JobInfoFormat(formatter.filter(jobs, args.no_header))
278278

279279
# "default" can be overridden by environment variable, so check if
280280
# it's different than the builtin default

0 commit comments

Comments
 (0)