| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
""" |
| 22 |
CLI utility functions |
| 23 |
""" |
| 24 |
|
| 25 |
from ClusterShell.RangeSet import RangeSet |
| 26 |
|
| 27 |
|
| 28 |
def parse_fold_axis(axis): |
| 29 |
"""Translate a 1-indexed command-line --axis value to a 0-indexed |
| 30 |
fold_axis suitable for NodeSet.fold_axis or Defaults.fold_axis.""" |
| 31 |
if not axis.startswith('-'): |
| 32 |
|
| 33 |
return tuple(x - 1 for x in RangeSet(axis).intiter() if x > 0) |
| 34 |
|
| 35 |
return [int(axis)] |
| 36 |
|
| 37 |
|
| 38 |
(KIBI, MEBI, GIBI, TEBI) = (1024.0, 1024.0 ** 2, 1024.0 ** 3, 1024.0 ** 4) |
| 39 |
|
| 40 |
def human_bi_bytes_unit(value): |
| 41 |
""" |
| 42 |
Format numerical `value` to display it using human readable unit with |
| 43 |
binary prefix like (KiB, MiB, GiB, ...). |
| 44 |
""" |
| 45 |
if value >= TEBI: |
| 46 |
fmt = "%.2f TiB" % (value / TEBI) |
| 47 |
elif value >= GIBI: |
| 48 |
fmt = "%.2f GiB" % (value / GIBI) |
| 49 |
elif value >= MEBI: |
| 50 |
fmt = "%.2f MiB" % (value / MEBI) |
| 51 |
elif value >= KIBI: |
| 52 |
fmt = "%.2f KiB" % (value / KIBI) |
| 53 |
else: |
| 54 |
fmt = "%d B" % value |
| 55 |
return fmt |
| 56 |
|
| 57 |
def nodeset_cmpkey(nodeset): |
| 58 |
"""We want larger nodeset first, then sorted by first node index.""" |
| 59 |
return -len(nodeset), nodeset[0] |
| 60 |
|
| 61 |
def bufnodeset_cmpkey(buf): |
| 62 |
"""Helper to get nodeset compare key from a buffer (buf, nodeset)""" |
| 63 |
return nodeset_cmpkey(buf[1]) |