Skip to content

Commit 5d5d796

Browse files
committed
python: move AltField class to flux.util
Problem: The AltField class is only present in flux-resource.py, but this class could be useful in other commands. Move it to flux.util.
1 parent 26697a5 commit 5d5d796

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/bindings/python/flux/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,24 @@ def format_field(self, value, spec):
535535
return retval
536536

537537

538+
class AltField:
539+
"""
540+
Convenient wrapper for fields that have an ascii and non-ascii
541+
representation. Allows the ascii representation to be selected with
542+
{field.ascii}.
543+
"""
544+
545+
def __init__(self, default, ascii):
546+
self.default = default
547+
self.ascii = ascii
548+
549+
def __str__(self):
550+
return self.default
551+
552+
def __format__(self, fmt):
553+
return str(self).__format__(fmt)
554+
555+
538556
class OutputFormat:
539557
"""
540558
Store a parsed version of the program's output format,

src/cmd/flux-resource.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
resource_status,
2828
)
2929
from flux.rpc import RPC
30-
from flux.util import Deduplicator, FilterActionSetUpdate, UtilConfig
30+
from flux.util import AltField, Deduplicator, FilterActionSetUpdate, UtilConfig
3131

3232

3333
class FluxResourceConfig(UtilConfig):
@@ -203,24 +203,6 @@ def ranks_by_queue(resource_set, config, queues):
203203
return ranks
204204

205205

206-
class AltField:
207-
"""
208-
Convenient wrapper for fields that have an ascii and non-ascii
209-
representation. Allows the ascii representation to be selected with
210-
{field.ascii}.
211-
"""
212-
213-
def __init__(self, default, ascii):
214-
self.default = default
215-
self.ascii = ascii
216-
217-
def __str__(self):
218-
return self.default
219-
220-
def __format__(self, fmt):
221-
return str(self).__format__(fmt)
222-
223-
224206
class ResourceStatusLine:
225207
"""Information specific to a given flux resource status line"""
226208

0 commit comments

Comments
 (0)