Revision f0b1bafe lib/cli.py

b/lib/cli.py
2382 2382
  """Callable class for formatting fields of a query.
2383 2383

  
2384 2384
  """
2385
  def __init__(self, fn, status_fn):
2385
  def __init__(self, fn, status_fn, verbose):
2386 2386
    """Initializes this class.
2387 2387

  
2388 2388
    @type fn: callable
2389 2389
    @param fn: Formatting function
2390 2390
    @type status_fn: callable
2391 2391
    @param status_fn: Function to report fields' status
2392
    @type verbose: boolean
2393
    @param verbose: whether to use verbose field descriptions or not
2392 2394

  
2393 2395
    """
2394 2396
    self._fn = fn
2395 2397
    self._status_fn = status_fn
2398
    if verbose:
2399
      self._desc_index = 0
2400
    else:
2401
      self._desc_index = 1
2396 2402

  
2397 2403
  def __call__(self, data):
2398 2404
    """Returns a field's string representation.
......
2409 2415
    assert value is None, \
2410 2416
           "Found value %r for abnormal status %s" % (value, status)
2411 2417

  
2412
    if status == constants.RS_UNKNOWN:
2413
      return "(unknown)"
2414

  
2415
    if status == constants.RS_NODATA:
2416
      return "(nodata)"
2417

  
2418
    if status == constants.RS_UNAVAIL:
2419
      return "(unavail)"
2420

  
2421
    if status == constants.RS_OFFLINE:
2422
      return "(offline)"
2418
    if status in constants.RSS_DESCRIPTION:
2419
      return constants.RSS_DESCRIPTION[status][self._desc_index]
2423 2420

  
2424 2421
    raise NotImplementedError("Unknown status %s" % status)
2425 2422

  
2426 2423

  
2427 2424
def FormatQueryResult(result, unit=None, format_override=None, separator=None,
2428
                      header=False):
2425
                      header=False, verbose=False):
2429 2426
  """Formats data in L{objects.QueryResponse}.
2430 2427

  
2431 2428
  @type result: L{objects.QueryResponse}
......
2440 2437
  @param separator: String used to separate fields
2441 2438
  @type header: bool
2442 2439
  @param header: Whether to output header row
2440
  @type verbose: boolean
2441
  @param verbose: whether to use verbose field descriptions or not
2443 2442

  
2444 2443
  """
2445 2444
  if unit is None:
......
2462 2461
    assert fdef.title and fdef.name
2463 2462
    (fn, align_right) = _GetColumnFormatter(fdef, format_override, unit)
2464 2463
    columns.append(TableColumn(fdef.title,
2465
                               _QueryColumnFormatter(fn, _RecordStatus),
2464
                               _QueryColumnFormatter(fn, _RecordStatus,
2465
                                                     verbose),
2466 2466
                               align_right))
2467 2467

  
2468 2468
  table = FormatTable(result.data, columns, header, separator)
......
2511 2511

  
2512 2512

  
2513 2513
def GenericList(resource, fields, names, unit, separator, header, cl=None,
2514
                format_override=None):
2514
                format_override=None, verbose=False):
2515 2515
  """Generic implementation for listing all items of a resource.
2516 2516

  
2517 2517
  @param resource: One of L{constants.QR_OP_LUXI}
......
2530 2530
  @type format_override: dict
2531 2531
  @param format_override: Dictionary for overriding field formatting functions,
2532 2532
    indexed by field name, contents like L{_DEFAULT_FORMAT_QUERY}
2533
  @type verbose: boolean
2534
  @param verbose: whether to use verbose field descriptions or not
2533 2535

  
2534 2536
  """
2535 2537
  if cl is None:
......
2544 2546

  
2545 2547
  (status, data) = FormatQueryResult(response, unit=unit, separator=separator,
2546 2548
                                     header=header,
2547
                                     format_override=format_override)
2549
                                     format_override=format_override,
2550
                                     verbose=verbose)
2548 2551

  
2549 2552
  for line in data:
2550 2553
    ToStdout(line)

Also available in: Unified diff