Revision 25bd815c lib/cli.py

b/lib/cli.py
161 161
  "VG_NAME_OPT",
162 162
  "YES_DOIT_OPT",
163 163
  # Generic functions for CLI programs
164
  "ConfirmOperation",
164 165
  "GenericMain",
165 166
  "GenericInstanceCreate",
166 167
  "GenericList",
......
2974 2975
  for key in sorted(actual):
2975 2976
    val = param_dict.get(key, "default (%s)" % actual[key])
2976 2977
    buf.write("%s- %s: %s\n" % (indent, key, val))
2978

  
2979

  
2980
def ConfirmOperation(names, list_type, text, extra=""):
2981
  """Ask the user to confirm an operation on a list of list_type.
2982

  
2983
  This function is used to request confirmation for doing an operation
2984
  on a given list of list_type.
2985

  
2986
  @type names: list
2987
  @param names: the list of names that we display when
2988
      we ask for confirmation
2989
  @type list_type: str
2990
  @param list_type: Human readable name for elements in the list (e.g. nodes)
2991
  @type text: str
2992
  @param text: the operation that the user should confirm
2993
  @rtype: boolean
2994
  @return: True or False depending on user's confirmation.
2995

  
2996
  """
2997
  count = len(names)
2998
  msg = ("The %s will operate on %d %s.\n%s"
2999
         "Do you want to continue?" % (text, count, list_type, extra))
3000
  affected = (("\nAffected %s:\n" % list_type) +
3001
              "\n".join(["  %s" % name for name in names]))
3002

  
3003
  choices = [("y", True, "Yes, execute the %s" % text),
3004
             ("n", False, "No, abort the %s" % text)]
3005

  
3006
  if count > 20:
3007
    choices.insert(1, ("v", "v", "View the list of affected %s" % list_type))
3008
    question = msg
3009
  else:
3010
    question = msg + affected
3011

  
3012
  choice = AskUser(question, choices)
3013
  if choice == "v":
3014
    choices.pop(1)
3015
    choice = AskUser(msg + affected, choices)
3016
  return choice

Also available in: Unified diff