Revision 73b90123

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",
......
55 56
           ]
56 57

  
57 58

  
59

  
58 60
def _ExtractTagsObject(opts, args):
59 61
  """Extract the tag type object.
60 62

  
......
120 122
  result = list(result)
121 123
  result.sort()
122 124
  for tag in result:
123
    print tag
125
    ToStdout(tag)
124 126

  
125 127

  
126 128
def AddTags(opts, args):
......
335 337
    binary = argv[0].split("/")[-1]
336 338

  
337 339
  if len(argv) > 1 and argv[1] == "--version":
338
    print "%s (ganeti) %s" % (binary, constants.RELEASE_VERSION)
340
    ToStdout("%s (ganeti) %s", binary, constants.RELEASE_VERSION)
339 341
    # Quit right away. That way we don't have to care about this special
340 342
    # argument. optparse.py does it the same.
341 343
    sys.exit(0)
......
345 347
    # let's do a nice thing
346 348
    sortedcmds = commands.keys()
347 349
    sortedcmds.sort()
348
    print ("Usage: %(bin)s {command} [options...] [argument...]"
349
           "\n%(bin)s <command> --help to see details, or"
350
           " man %(bin)s\n" % {"bin": binary})
350

  
351
    ToStdout("Usage: %s {command} [options...] [argument...]", binary)
352
    ToStdout("%s <command> --help to see details, or man %s", binary, binary)
353
    ToStdout("")
354

  
351 355
    # compute the max line length for cmd + usage
352 356
    mlen = max([len(" %s" % cmd) for cmd in commands])
353 357
    mlen = min(60, mlen) # should not get here...
358

  
354 359
    # and format a nice command list
355
    print "Commands:"
360
    ToStdout("Commands:")
356 361
    for cmd in sortedcmds:
357 362
      cmdstr = " %s" % (cmd,)
358 363
      help_text = commands[cmd][4]
359
      help_lines = textwrap.wrap(help_text, 79-3-mlen)
360
      print "%-*s - %s" % (mlen, cmdstr, help_lines.pop(0))
364
      help_lines = textwrap.wrap(help_text, 79 - 3 - mlen)
365
      ToStdout("%-*s - %s", mlen, cmdstr, help_lines.pop(0))
361 366
      for line in help_lines:
362
        print "%-*s   %s" % (mlen, "", line)
363
    print
367
        ToStdout("%-*s   %s", mlen, "", line)
368

  
369
    ToStdout("")
370

  
364 371
    return None, None, None
365 372

  
366 373
  # get command, unalias it, and look it up in commands
......
385 392
  options, args = parser.parse_args()
386 393
  if nargs is None:
387 394
    if len(args) != 0:
388
      print >> sys.stderr, ("Error: Command %s expects no arguments" % cmd)
395
      ToStderr("Error: Command %s expects no arguments", cmd)
389 396
      return None, None, None
390 397
  elif nargs < 0 and len(args) != -nargs:
391
    print >> sys.stderr, ("Error: Command %s expects %d argument(s)" %
392
                         (cmd, -nargs))
398
    ToStderr("Error: Command %s expects %d argument(s)", cmd, -nargs)
393 399
    return None, None, None
394 400
  elif nargs >= 0 and len(args) < nargs:
395
    print >> sys.stderr, ("Error: Command %s expects at least %d argument(s)" %
396
                         (cmd, nargs))
401
    ToStderr("Error: Command %s expects at least %d argument(s)", cmd, nargs)
397 402
    return None, None, None
398 403

  
399 404
  return func, options, args
......
539 544
          feedback_fn(log_entry[1:])
540 545
        else:
541 546
          encoded = utils.SafeEncode(message)
542
          print "%s %s" % (time.ctime(utils.MergeTime(timestamp)), encoded)
547
          ToStdout("%s %s", time.ctime(utils.MergeTime(timestamp)), encoded)
543 548
        prev_logmsg_serial = max(prev_logmsg_serial, serial)
544 549

  
545 550
    # TODO: Handle canceled and archived jobs

Also available in: Unified diff