本文整理汇总了Python中azure.cli.core._output.OutputProducer.get_formatter方法的典型用法代码示例。如果您正苦于以下问题:Python OutputProducer.get_formatter方法的具体用法?Python OutputProducer.get_formatter怎么用?Python OutputProducer.get_formatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.cli.core._output.OutputProducer
的用法示例。
在下文中一共展示了OutputProducer.get_formatter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from azure.cli.core._output import OutputProducer [as 别名]
# 或者: from azure.cli.core._output.OutputProducer import get_formatter [as 别名]
def main(args, file=sys.stdout): # pylint: disable=redefined-builtin
azlogging.configure_logging(args)
logger.debug('Command arguments %s', args)
if len(args) > 0 and args[0] == '--version':
show_version_info_exit(file)
azure_folder = get_config_dir()
if not os.path.exists(azure_folder):
os.makedirs(azure_folder)
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
CONFIG.load(os.path.join(azure_folder, 'az.json'))
SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)
APPLICATION.initialize(Configuration())
try:
cmd_result = APPLICATION.execute(args)
# Commands can return a dictionary/list of results
# If they do, we print the results.
if cmd_result and cmd_result.result is not None:
from azure.cli.core._output import OutputProducer
formatter = OutputProducer.get_formatter(APPLICATION.configuration.output_format)
OutputProducer(formatter=formatter, file=file).out(cmd_result)
except Exception as ex: # pylint: disable=broad-except
# TODO: include additional details of the exception in telemetry
telemetry.set_exception(ex, 'outer-exception',
'Unexpected exception caught during application execution.')
telemetry.set_failure()
error_code = handle_exception(ex)
return error_code
示例2: main
# 需要导入模块: from azure.cli.core._output import OutputProducer [as 别名]
# 或者: from azure.cli.core._output.OutputProducer import get_formatter [as 别名]
def main(args, file=sys.stdout): #pylint: disable=redefined-builtin
_logging.configure_logging(args)
if len(args) > 0 and args[0] == '--version':
show_version_info_exit(file)
azure_folder = os.path.expanduser('~/.azure')
if not os.path.exists(azure_folder):
os.makedirs(azure_folder)
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
CONFIG.load(os.path.join(azure_folder, 'az.json'))
SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)
config = Configuration(args)
APPLICATION.initialize(config)
try:
cmd_result = APPLICATION.execute(args)
# Commands can return a dictionary/list of results
# If they do, we print the results.
if cmd_result and cmd_result.result:
from azure.cli.core._output import OutputProducer
formatter = OutputProducer.get_formatter(APPLICATION.configuration.output_format)
OutputProducer(formatter=formatter, file=file).out(cmd_result)
except Exception as ex: # pylint: disable=broad-except
from azure.cli.core.telemetry import log_telemetry
log_telemetry('Error', log_type='trace')
error_code = handle_exception(ex)
return error_code
示例3: cli_execute
# 需要导入模块: from azure.cli.core._output import OutputProducer [as 别名]
# 或者: from azure.cli.core._output.OutputProducer import get_formatter [as 别名]
def cli_execute(self, cmd):
""" sends the command to the CLI to be executed """
try:
args = parse_quotes(cmd)
if args and args[0] == 'feedback':
self.config.set_feedback('yes')
self.user_feedback = False
azure_folder = get_config_dir()
if not os.path.exists(azure_folder):
os.makedirs(azure_folder)
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
CONFIG.load(os.path.join(azure_folder, 'az.json'))
SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)
invocation = self.cli_ctx.invocation_cls(cli_ctx=self.cli_ctx,
parser_cls=self.cli_ctx.parser_cls,
commands_loader_cls=self.cli_ctx.commands_loader_cls,
help_cls=self.cli_ctx.help_cls)
if '--progress' in args:
args.remove('--progress')
execute_args = [args]
thread = Thread(target=invocation.execute, args=execute_args)
thread.daemon = True
thread.start()
self.threads.append(thread)
self.curr_thread = thread
progress_args = [self]
thread = Thread(target=progress_view, args=progress_args)
thread.daemon = True
thread.start()
self.threads.append(thread)
result = None
else:
result = invocation.execute(args)
self.last_exit = 0
if result and result.result is not None:
from azure.cli.core._output import OutputProducer
if self.output:
self.output.write(result)
self.output.flush()
else:
formatter = OutputProducer.get_formatter(self.cli_ctx.invocation.data['output'])
OutputProducer(formatter=formatter).out(result)
self.last = result
except Exception as ex: # pylint: disable=broad-except
self.last_exit = handle_exception(ex)
except SystemExit as ex:
self.last_exit = int(ex.code)
示例4: cli_execute
# 需要导入模块: from azure.cli.core._output import OutputProducer [as 别名]
# 或者: from azure.cli.core._output.OutputProducer import get_formatter [as 别名]
def cli_execute(self, cmd):
""" sends the command to the CLI to be executed """
try:
args = parse_quotes(cmd)
azlogging.configure_logging(args)
if len(args) > 0 and args[0] == 'feedback':
SHELL_CONFIGURATION.set_feedback('yes')
self.user_feedback = False
azure_folder = get_config_dir()
if not os.path.exists(azure_folder):
os.makedirs(azure_folder)
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
CONFIG.load(os.path.join(azure_folder, 'az.json'))
SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)
self.app.initialize(Configuration())
if '--progress' in args:
args.remove('--progress')
thread = ExecuteThread(self.app.execute, args)
thread.daemon = True
thread.start()
self.threads.append(thread)
self.curr_thread = thread
thread = ProgressViewThread(progress_view, self)
thread.daemon = True
thread.start()
self.threads.append(thread)
result = None
else:
result = self.app.execute(args)
self.last_exit = 0
if result and result.result is not None:
from azure.cli.core._output import OutputProducer
if self.output:
self.output.write(result)
self.output.flush()
else:
formatter = OutputProducer.get_formatter(
self.app.configuration.output_format)
OutputProducer(formatter=formatter, file=self.output).out(result)
self.last = result
except Exception as ex: # pylint: disable=broad-except
self.last_exit = handle_exception(ex)
except SystemExit as ex:
self.last_exit = int(ex.code)