Revision d0c8c01d lib/cli.py
b/lib/cli.py | ||
---|---|---|
517 | 517 |
|
518 | 518 |
""" |
519 | 519 |
if ":" not in value: |
520 |
ident, rest = value, ''
|
|
520 |
ident, rest = value, ""
|
|
521 | 521 |
else: |
522 | 522 |
ident, rest = value.split(":", 1) |
523 | 523 |
|
... | ... | |
621 | 621 |
" (defaults to one space)")) |
622 | 622 |
|
623 | 623 |
USEUNITS_OPT = cli_option("--units", default=None, |
624 |
dest="units", choices=('h', 'm', 'g', 't'),
|
|
624 |
dest="units", choices=("h", "m", "g", "t"),
|
|
625 | 625 |
help="Specify units for output (one of h/m/g/t)") |
626 | 626 |
|
627 | 627 |
FIELDS_OPT = cli_option("-o", "--output", dest="output", action="store", |
... | ... | |
1417 | 1417 |
"""Splits the value of a --node option. |
1418 | 1418 |
|
1419 | 1419 |
""" |
1420 |
if value and ':' in value:
|
|
1421 |
return value.split(':', 1)
|
|
1420 |
if value and ":" in value:
|
|
1421 |
return value.split(":", 1)
|
|
1422 | 1422 |
else: |
1423 | 1423 |
return (value, None) |
1424 | 1424 |
|
... | ... | |
1435 | 1435 |
|
1436 | 1436 |
""" |
1437 | 1437 |
if os_variants: |
1438 |
return ['%s+%s' % (os_name, v) for v in os_variants]
|
|
1438 |
return ["%s+%s" % (os_name, v) for v in os_variants]
|
|
1439 | 1439 |
else: |
1440 | 1440 |
return [os_name] |
1441 | 1441 |
|
... | ... | |
1477 | 1477 |
|
1478 | 1478 |
""" |
1479 | 1479 |
if choices is None: |
1480 |
choices = [('y', True, 'Perform the operation'),
|
|
1481 |
('n', False, 'Do not perform the operation')]
|
|
1480 |
choices = [("y", True, "Perform the operation"),
|
|
1481 |
("n", False, "Do not perform the operation")]
|
|
1482 | 1482 |
if not choices or not isinstance(choices, list): |
1483 | 1483 |
raise errors.ProgrammerError("Invalid choices argument to AskUser") |
1484 | 1484 |
for entry in choices: |
1485 |
if not isinstance(entry, tuple) or len(entry) < 3 or entry[0] == '?':
|
|
1485 |
if not isinstance(entry, tuple) or len(entry) < 3 or entry[0] == "?":
|
|
1486 | 1486 |
raise errors.ProgrammerError("Invalid choices element to AskUser") |
1487 | 1487 |
|
1488 | 1488 |
answer = choices[-1][1] |
... | ... | |
1497 | 1497 |
try: |
1498 | 1498 |
chars = [entry[0] for entry in choices] |
1499 | 1499 |
chars[-1] = "[%s]" % chars[-1] |
1500 |
chars.append('?')
|
|
1500 |
chars.append("?")
|
|
1501 | 1501 |
maps = dict([(entry[0], entry[1]) for entry in choices]) |
1502 | 1502 |
while True: |
1503 | 1503 |
f.write(text) |
1504 |
f.write('\n')
|
|
1504 |
f.write("\n")
|
|
1505 | 1505 |
f.write("/".join(chars)) |
1506 | 1506 |
f.write(": ") |
1507 | 1507 |
line = f.readline(2).strip().lower() |
1508 | 1508 |
if line in maps: |
1509 | 1509 |
answer = maps[line] |
1510 | 1510 |
break |
1511 |
elif line == '?':
|
|
1511 |
elif line == "?":
|
|
1512 | 1512 |
for entry in choices: |
1513 | 1513 |
f.write(" %s - %s\n" % (entry[0], entry[2])) |
1514 | 1514 |
f.write("\n") |
... | ... | |
1965 | 1965 |
retcode = 0 |
1966 | 1966 |
else: |
1967 | 1967 |
obuf.write("Unhandled exception: %s" % msg) |
1968 |
return retcode, obuf.getvalue().rstrip('\n')
|
|
1968 |
return retcode, obuf.getvalue().rstrip("\n")
|
|
1969 | 1969 |
|
1970 | 1970 |
|
1971 | 1971 |
def GenericMain(commands, override=None, aliases=None): |
... | ... | |
2381 | 2381 |
|
2382 | 2382 |
if separator is None: |
2383 | 2383 |
mlens = [0 for name in fields] |
2384 |
format_str = ' '.join(format_fields)
|
|
2384 |
format_str = " ".join(format_fields)
|
|
2385 | 2385 |
else: |
2386 | 2386 |
format_str = separator.replace("%", "%%").join(format_fields) |
2387 | 2387 |
|
... | ... | |
2420 | 2420 |
for line in data: |
2421 | 2421 |
args = [] |
2422 | 2422 |
if line is None: |
2423 |
line = ['-' for _ in fields]
|
|
2423 |
line = ["-" for _ in fields]
|
|
2424 | 2424 |
for idx in range(len(fields)): |
2425 | 2425 |
if separator is None: |
2426 | 2426 |
args.append(mlens[idx]) |
... | ... | |
2826 | 2826 |
|
2827 | 2827 |
""" |
2828 | 2828 |
if not isinstance (ts, (tuple, list)) or len(ts) != 2: |
2829 |
return '?'
|
|
2829 |
return "?"
|
|
2830 | 2830 |
sec, usec = ts |
2831 | 2831 |
return time.strftime("%F %T", time.localtime(sec)) + ".%06d" % usec |
2832 | 2832 |
|
... | ... | |
2849 | 2849 |
if not value: |
2850 | 2850 |
raise errors.OpPrereqError("Empty time specification passed") |
2851 | 2851 |
suffix_map = { |
2852 |
's': 1,
|
|
2853 |
'm': 60,
|
|
2854 |
'h': 3600,
|
|
2855 |
'd': 86400,
|
|
2856 |
'w': 604800,
|
|
2852 |
"s": 1,
|
|
2853 |
"m": 60,
|
|
2854 |
"h": 3600,
|
|
2855 |
"d": 86400,
|
|
2856 |
"w": 604800,
|
|
2857 | 2857 |
} |
2858 | 2858 |
if value[-1] not in suffix_map: |
2859 | 2859 |
try: |
... | ... | |
2966 | 2966 |
stream.write(txt % args) |
2967 | 2967 |
else: |
2968 | 2968 |
stream.write(txt) |
2969 |
stream.write('\n')
|
|
2969 |
stream.write("\n")
|
|
2970 | 2970 |
stream.flush() |
2971 | 2971 |
except IOError, err: |
2972 | 2972 |
if err.errno == errno.EPIPE: |
Also available in: Unified diff