本文整理匯總了Python中osc_lib.command.command.Command方法的典型用法代碼示例。如果您正苦於以下問題:Python command.Command方法的具體用法?Python command.Command怎麽用?Python command.Command使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類osc_lib.command.command
的用法示例。
在下文中一共展示了command.Command方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_command_class
# 需要導入模塊: from osc_lib.command import command [as 別名]
# 或者: from osc_lib.command.command import Command [as 別名]
def create_command_class(name, func_module):
"""Dynamically creates subclass of MigratingCommand.
Method takes name of the function, module it is part of
and builds the subclass of :py:class:`MigratingCommand`.
Having a subclass of :py:class:`cliff.command.Command` is mandatory
for the osc-lib integration.
:param name: name of the function
:type name: basestring
:param func_module: the module function is part of
:type func_module: module
:return: command name, subclass of :py:class:`MigratingCommand`
:rtype: tuple(basestring, class)
"""
cmd_name = name[3:].replace('_', '-')
callback = getattr(func_module, name)
desc = callback.__doc__ or ''
help = desc.strip().split('\n')[0]
arguments = getattr(callback, 'arguments', [])
body = {
'_args': arguments,
'_callback': staticmethod(callback),
'_description': desc,
'_epilog': desc,
'_help': help
}
claz = type('%sCommand' % cmd_name.title().replace('-', ''),
(MigratingCommand,), body)
return cmd_name, claz
示例2: run
# 需要導入模塊: from osc_lib.command import command [as 別名]
# 或者: from osc_lib.command.command import Command [as 別名]
def run(self, parsed_args):
utils.store_cli_param(self.cmd_name, parsed_args)
try:
super(Command, self).run(parsed_args)
except (oscexc.CommandError, exceptions.Base):
raise
except Exception:
self.log.exception("Exception occured while running the command")
raise