Revision 03298ebe
b/lib/cli.py | ||
---|---|---|
41 | 41 |
from optparse import (OptionParser, make_option, TitledHelpFormatter, |
42 | 42 |
Option, OptionValueError) |
43 | 43 |
|
44 |
|
|
44 | 45 |
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", |
45 | 46 |
"SubmitOpCode", "GetClient", |
46 | 47 |
"cli_option", "ikv_option", "keyval_option", |
... | ... | |
57 | 58 |
NO_PREFIX = "no_" |
58 | 59 |
UN_PREFIX = "-" |
59 | 60 |
|
61 |
|
|
60 | 62 |
def _ExtractTagsObject(opts, args): |
61 | 63 |
"""Extract the tag type object. |
62 | 64 |
|
... | ... | |
122 | 124 |
result = list(result) |
123 | 125 |
result.sort() |
124 | 126 |
for tag in result: |
125 |
print tag
|
|
127 |
ToStdout(tag)
|
|
126 | 128 |
|
127 | 129 |
|
128 | 130 |
def AddTags(opts, args): |
... | ... | |
356 | 358 |
binary = argv[0].split("/")[-1] |
357 | 359 |
|
358 | 360 |
if len(argv) > 1 and argv[1] == "--version": |
359 |
print "%s (ganeti) %s" % (binary, constants.RELEASE_VERSION)
|
|
361 |
ToStdout("%s (ganeti) %s", binary, constants.RELEASE_VERSION)
|
|
360 | 362 |
# Quit right away. That way we don't have to care about this special |
361 | 363 |
# argument. optparse.py does it the same. |
362 | 364 |
sys.exit(0) |
... | ... | |
366 | 368 |
# let's do a nice thing |
367 | 369 |
sortedcmds = commands.keys() |
368 | 370 |
sortedcmds.sort() |
369 |
print ("Usage: %(bin)s {command} [options...] [argument...]" |
|
370 |
"\n%(bin)s <command> --help to see details, or" |
|
371 |
" man %(bin)s\n" % {"bin": binary}) |
|
371 |
|
|
372 |
ToStdout("Usage: %s {command} [options...] [argument...]", binary) |
|
373 |
ToStdout("%s <command> --help to see details, or man %s", binary, binary) |
|
374 |
ToStdout("") |
|
375 |
|
|
372 | 376 |
# compute the max line length for cmd + usage |
373 | 377 |
mlen = max([len(" %s" % cmd) for cmd in commands]) |
374 | 378 |
mlen = min(60, mlen) # should not get here... |
379 |
|
|
375 | 380 |
# and format a nice command list |
376 |
print "Commands:"
|
|
381 |
ToStdout("Commands:")
|
|
377 | 382 |
for cmd in sortedcmds: |
378 | 383 |
cmdstr = " %s" % (cmd,) |
379 | 384 |
help_text = commands[cmd][4] |
380 |
help_lines = textwrap.wrap(help_text, 79-3-mlen)
|
|
381 |
print "%-*s - %s" % (mlen, cmdstr, help_lines.pop(0))
|
|
385 |
help_lines = textwrap.wrap(help_text, 79 - 3 - mlen)
|
|
386 |
ToStdout("%-*s - %s", mlen, cmdstr, help_lines.pop(0))
|
|
382 | 387 |
for line in help_lines: |
383 |
print "%-*s %s" % (mlen, "", line) |
|
384 |
|
|
388 |
ToStdout("%-*s %s", mlen, "", line) |
|
389 |
|
|
390 |
ToStdout("") |
|
391 |
|
|
385 | 392 |
return None, None, None |
386 | 393 |
|
387 | 394 |
# get command, unalias it, and look it up in commands |
... | ... | |
406 | 413 |
options, args = parser.parse_args() |
407 | 414 |
if nargs is None: |
408 | 415 |
if len(args) != 0: |
409 |
print >> sys.stderr, ("Error: Command %s expects no arguments" % cmd)
|
|
416 |
ToStderr("Error: Command %s expects no arguments", cmd)
|
|
410 | 417 |
return None, None, None |
411 | 418 |
elif nargs < 0 and len(args) != -nargs: |
412 |
print >> sys.stderr, ("Error: Command %s expects %d argument(s)" % |
|
413 |
(cmd, -nargs)) |
|
419 |
ToStderr("Error: Command %s expects %d argument(s)", cmd, -nargs) |
|
414 | 420 |
return None, None, None |
415 | 421 |
elif nargs >= 0 and len(args) < nargs: |
416 |
print >> sys.stderr, ("Error: Command %s expects at least %d argument(s)" % |
|
417 |
(cmd, nargs)) |
|
422 |
ToStderr("Error: Command %s expects at least %d argument(s)", cmd, nargs) |
|
418 | 423 |
return None, None, None |
419 | 424 |
|
420 | 425 |
return func, options, args |
... | ... | |
560 | 565 |
feedback_fn(log_entry[1:]) |
561 | 566 |
else: |
562 | 567 |
encoded = utils.SafeEncode(message) |
563 |
print "%s %s" % (time.ctime(utils.MergeTime(timestamp)), encoded)
|
|
568 |
ToStdout("%s %s", time.ctime(utils.MergeTime(timestamp)), encoded)
|
|
564 | 569 |
prev_logmsg_serial = max(prev_logmsg_serial, serial) |
565 | 570 |
|
566 | 571 |
# TODO: Handle canceled and archived jobs |
Also available in: Unified diff