Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=028f0bba7... Commit: 028f0bba76b2171a3c25f5d755209ecb29c8053d Parent: 17100edb3fe29f4992b225676bb4a32db7a53310 Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Mon Dec 15 16:19:34 2014 +0100 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Mon Dec 15 16:19:34 2014 +0100
[refactor] Function _get_opts_with_invalid_choices(...)
--- fence/agents/lib/fencing.py.py | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 41770a4..a8ea448 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -1141,17 +1141,9 @@ def _validate_input(options): options.has_key("--method") and options["--method"] == "cycle": fail_usage("Failed: Cannot use --method cycle for more than 1 plug")
- for opt in device_opt: - if all_opt[opt].has_key("choices"): - longopt = "--" + all_opt[opt]["longopt"] - possible_values_upper = [y.upper() for y in all_opt[opt]["choices"]] - if options.has_key(longopt): - options[longopt] = options[longopt].upper() - if not options["--" + all_opt[opt]["longopt"]] in possible_values_upper: - fail_usage("Failed: You have to enter a valid choice " + \ - "for %s from the valid values: %s" % \ - ("--" + all_opt[opt]["longopt"], str(all_opt[opt]["choices"]))) - + for failed_opt in _get_opts_with_invalid_choices(options): + fail_usage("Failed: You have to enter a valid choice for %s from the valid values: %s" % \ + ("--" + all_opt[failed_opt]["longopt"], str(all_opt[failed_opt]["choices"])))
def _encode_html_entities(text): return text.replace("&", "&").replace('"', """).replace('<', "<"). \ @@ -1221,3 +1213,17 @@ def _join2(words, normal_separator=", ", last_separator=" and "): return "".join(words) else: return last_separator.join([normal_separator.join(words[:-1]), words[-1]]) + +def _get_opts_with_invalid_choices(options): + options_failed = [] + device_opt = options["device_opt"] + + for opt in device_opt: + if all_opt[opt].has_key("choices"): + longopt = "--" + all_opt[opt]["longopt"] + possible_values_upper = [y.upper() for y in all_opt[opt]["choices"]] + if options.has_key(longopt): + options[longopt] = options[longopt].upper() + if not options["--" + all_opt[opt]["longopt"]] in possible_values_upper: + options_failed.append(opt) + return options_failed
cluster-commits@lists.fedorahosted.org