Revision 16be8703
b/lib/cli.py | ||
---|---|---|
37 | 37 |
Option, OptionValueError, SUPPRESS_HELP) |
38 | 38 |
|
39 | 39 |
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", "SubmitOpCode", |
40 |
"cli_option", "OutputTable",
|
|
40 |
"cli_option", "GenerateTable",
|
|
41 | 41 |
"ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE", |
42 | 42 |
"USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT"] |
43 | 43 |
|
... | ... | |
280 | 280 |
return result |
281 | 281 |
|
282 | 282 |
|
283 |
def OutputTable(headers, fields, separator, data,
|
|
284 |
numfields=None, unitfields=None): |
|
283 |
def GenerateTable(headers, fields, separator, data,
|
|
284 |
numfields=None, unitfields=None):
|
|
285 | 285 |
"""Prints a table with headers and different fields. |
286 | 286 |
|
287 | 287 |
Args: |
... | ... | |
325 | 325 |
if separator is None: |
326 | 326 |
mlens[idx] = max(mlens[idx], len(val)) |
327 | 327 |
|
328 |
result = [] |
|
328 | 329 |
if headers: |
329 | 330 |
args = [] |
330 | 331 |
for idx, name in enumerate(fields): |
... | ... | |
333 | 334 |
mlens[idx] = max(mlens[idx], len(hdr)) |
334 | 335 |
args.append(mlens[idx]) |
335 | 336 |
args.append(hdr) |
336 |
logger.ToStdout(format % tuple(args))
|
|
337 |
result.append(format % tuple(args))
|
|
337 | 338 |
|
338 | 339 |
for line in data: |
339 | 340 |
args = [] |
... | ... | |
341 | 342 |
if separator is None: |
342 | 343 |
args.append(mlens[idx]) |
343 | 344 |
args.append(line[idx]) |
344 |
logger.ToStdout(format % tuple(args)) |
|
345 |
result.append(format % tuple(args)) |
|
346 |
|
|
347 |
return result |
b/scripts/gnt-instance | ||
---|---|---|
61 | 61 |
|
62 | 62 |
numfields = ["admin_ram", "oper_ram"] |
63 | 63 |
|
64 |
OutputTable(separator=opts.separator, headers=headers, |
|
65 |
fields=selected_fields, unitfields=unitfields, |
|
66 |
numfields=numfields, data=output) |
|
64 |
data = GenerateTable(separator=opts.separator, headers=headers, |
|
65 |
fields=selected_fields, unitfields=unitfields, |
|
66 |
numfields=numfields, data=output) |
|
67 |
|
|
68 |
for line in data: |
|
69 |
logger.ToStdout(line) |
|
67 | 70 |
|
68 | 71 |
return 0 |
69 | 72 |
|
b/scripts/gnt-node | ||
---|---|---|
63 | 63 |
|
64 | 64 |
numfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree", "pinst", "sinst"] |
65 | 65 |
|
66 |
OutputTable(separator=opts.separator, headers=headers, |
|
67 |
fields=selected_fields, unitfields=unitfields, |
|
68 |
numfields=numfields, data=output) |
|
66 |
data = GenerateTable(separator=opts.separator, headers=headers, |
|
67 |
fields=selected_fields, unitfields=unitfields, |
|
68 |
numfields=numfields, data=output) |
|
69 |
for line in data: |
|
70 |
logger.ToStdout(line) |
|
69 | 71 |
|
70 | 72 |
return 0 |
71 | 73 |
|
... | ... | |
130 | 132 |
|
131 | 133 |
numfields = ["size"] |
132 | 134 |
|
133 |
OutputTable(separator=opts.separator, headers=headers, |
|
134 |
fields=selected_fields, unitfields=unitfields, |
|
135 |
numfields=numfields, data=output) |
|
135 |
data = GenerateTable(separator=opts.separator, headers=headers, |
|
136 |
fields=selected_fields, unitfields=unitfields, |
|
137 |
numfields=numfields, data=output) |
|
138 |
|
|
139 |
for line in data: |
|
140 |
logger.ToStdout(line) |
|
136 | 141 |
|
137 | 142 |
return 0 |
138 | 143 |
|
b/scripts/gnt-os | ||
---|---|---|
58 | 58 |
else: |
59 | 59 |
headers = None |
60 | 60 |
|
61 |
OutputTable(separator=None, headers=headers, fields=["name"], |
|
62 |
data=[[os] for os in os_set]) |
|
61 |
data = GenerateTable(separator=None, headers=headers, fields=["name"], |
|
62 |
data=[[os] for os in os_set]) |
|
63 |
|
|
64 |
for line in data: |
|
65 |
logger.ToStdout(line) |
|
63 | 66 |
|
64 | 67 |
return 0 |
65 | 68 |
|
Also available in: Unified diff