def _find_actions(self, subparsers, actions_module, version, do_help): msg = _(" (Supported by API versions '%(start)s' - '%(end)s')") for attr in (a for a in dir(actions_module) if a.startswith('do_')): # I prefer to be hyphen-separated instead of underscores. command = attr[3:].replace('_', '-') callback = getattr(actions_module, attr) desc = callback.__doc__ or '' if hasattr(callback, "versioned"): subs = api_versions.get_substitutions(callback) if do_help: desc += msg % {'start': subs[0].start_version.get_string(), 'end': subs[-1].end_version.get_string()} else: for versioned_method in subs: if version.matches(versioned_method.start_version, versioned_method.end_version): callback = versioned_method.func break else: continue action_help = desc.strip() arguments = getattr(callback, 'arguments', []) subparser = ( subparsers.add_parser(command, help=action_help, description=desc, add_help=False, formatter_class=OpenStackHelpFormatter) ) subparser.add_argument('-h', '--help', action='help', help=argparse.SUPPRESS,) self.subcommands[command] = subparser for (args, kwargs) in arguments: start_version = kwargs.get("start_version", None) if start_version: start_version = api_versions.APIVersion(start_version) end_version = kwargs.get("end_version", None) if end_version: end_version = api_versions.APIVersion(end_version) else: end_version = api_versions.APIVersion( "%s.latest" % start_version.ver_major) if do_help: kwargs["help"] = kwargs.get("help", "") + (msg % { "start": start_version.get_string(), "end": end_version.get_string()}) else: if not version.matches(start_version, end_version): continue kw = kwargs.copy() kw.pop("start_version", None) kw.pop("end_version", None) subparser.add_argument(*args, **kwargs) subparser.set_defaults(func=callback)
def _find_actions(self, subparsers, actions_module, version, do_help): msg = _(" (Supported by API versions '%(start)s' - '%(end)s')") for attr in (a for a in dir(actions_module) if a.startswith('do_')): # I prefer to be hyphen-separated instead of underscores. command = attr[3:].replace('_', '-') callback = getattr(actions_module, attr) desc = callback.__doc__ or '' if hasattr(callback, "versioned"): subs = api_versions.get_substitutions(callback) if do_help: desc += msg % { 'start': subs[0].start_version.get_string(), 'end': subs[-1].end_version.get_string() } else: for versioned_method in subs: if version.matches(versioned_method.start_version, versioned_method.end_version): callback = versioned_method.func break else: continue action_help = desc.strip() exclusive_args = getattr(callback, 'exclusive_args', {}) arguments = getattr(callback, 'arguments', []) subparser = (subparsers.add_parser( command, help=action_help, description=desc, add_help=False, formatter_class=OpenStackHelpFormatter)) subparser.add_argument( '-h', '--help', action='help', help=argparse.SUPPRESS, ) self.subcommands[command] = subparser self._add_subparser_args(subparser, arguments, version, do_help, msg) self._add_subparser_exclusive_args(subparser, exclusive_args, version, do_help, msg) subparser.set_defaults(func=callback)
def _find_actions(self, subparsers, actions_module, version, do_help): msg = _(" (Supported by API versions '%(start)s' - '%(end)s')") for attr in (a for a in dir(actions_module) if a.startswith('do_')): # I prefer to be hyphen-separated instead of underscores. command = attr[3:].replace('_', '-') callback = getattr(actions_module, attr) desc = callback.__doc__ or '' if hasattr(callback, "versioned"): subs = api_versions.get_substitutions(callback) if do_help: desc += msg % {'start': subs[0].start_version.get_string(), 'end': subs[-1].end_version.get_string()} else: for versioned_method in subs: if version.matches(versioned_method.start_version, versioned_method.end_version): callback = versioned_method.func break else: continue action_help = desc.strip() exclusive_args = getattr(callback, 'exclusive_args', {}) arguments = getattr(callback, 'arguments', []) subparser = ( subparsers.add_parser(command, help=action_help, description=desc, add_help=False, formatter_class=OpenStackHelpFormatter) ) subparser.add_argument('-h', '--help', action='help', help=argparse.SUPPRESS,) self.subcommands[command] = subparser self._add_subparser_args(subparser, arguments, version, do_help, msg) self._add_subparser_exclusive_args(subparser, exclusive_args, version, do_help, msg) subparser.set_defaults(func=callback)
def _add_subparser_args(self, subparser, arguments, version, do_help, msg): for (args, kwargs) in arguments: start_version = kwargs.get("start_version", None) if start_version: start_version = api_versions.APIVersion(start_version) end_version = kwargs.get("end_version", None) if end_version: end_version = api_versions.APIVersion(end_version) else: end_version = api_versions.APIVersion( "%s.latest" % start_version.ver_major) if do_help: kwargs["help"] = kwargs.get("help", "") + (msg % { "start": start_version.get_string(), "end": end_version.get_string()}) else: if not version.matches(start_version, end_version): continue kw = kwargs.copy() kw.pop("start_version", None) kw.pop("end_version", None) subparser.add_argument(*args, **kwargs)