Revision 24d16f76 lib/client/gnt_debug.py

b/lib/client/gnt_debug.py
479 479
  """
480 480
  selected_fields = ParseFields(opts.output, _LIST_LOCKS_DEF_FIELDS)
481 481

  
482
  if not opts.no_headers:
483
    headers = {
484
      "name": "Name",
485
      "mode": "Mode",
486
      "owner": "Owner",
487
      "pending": "Pending",
488
      }
489
  else:
490
    headers = None
482
  def _DashIfNone(fn):
483
    def wrapper(value):
484
      if not value:
485
        return "-"
486
      return fn(value)
487
    return wrapper
488

  
489
  def _FormatPending(value):
490
    """Format pending acquires.
491

  
492
    """
493
    return utils.CommaJoin("%s:%s" % (mode, ",".join(threads))
494
                           for mode, threads in value)
495

  
496
  # Format raw values
497
  fmtoverride = {
498
    "mode": (_DashIfNone(str), False),
499
    "owner": (_DashIfNone(",".join), False),
500
    "pending": (_DashIfNone(_FormatPending), False),
501
    }
491 502

  
492 503
  while True:
493
    # Not reusing client as interval might be too long
494
    output = GetClient().QueryLocks(selected_fields, False)
495

  
496
    # change raw values to nicer strings
497
    for row in output:
498
      for idx, field in enumerate(selected_fields):
499
        val = row[idx]
500

  
501
        if field in ("mode", "owner", "pending") and not val:
502
          val = "-"
503
        elif field == "owner":
504
          val = ",".join(val)
505
        elif field == "pending":
506
          val = utils.CommaJoin("%s:%s" % (mode, ",".join(threads))
507
                                for mode, threads in val)
508

  
509
        row[idx] = str(val)
510

  
511
    data = GenerateTable(separator=opts.separator, headers=headers,
512
                         fields=selected_fields, data=output)
513
    for line in data:
514
      ToStdout(line)
504
    ret = GenericList(constants.QR_LOCK, selected_fields, None, None,
505
                      opts.separator, not opts.no_headers,
506
                      format_override=fmtoverride)
507

  
508
    if ret != constants.EXIT_SUCCESS:
509
      return ret
515 510

  
516 511
    if not opts.interval:
517 512
      break

Also available in: Unified diff