зеркало из
1
0
Форкнуть 0
This commit is contained in:
Troy Dai 2018-04-26 16:27:32 -07:00
Родитель 11e515d2ad
Коммит 6424daf2f9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9608535492BEDAC8
3 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -1,4 +1,5 @@
import argparse import argparse
import asyncio
import inspect import inspect
from typing import Callable, Collection from typing import Callable, Collection
@ -145,7 +146,10 @@ class CommandDefinition(object):
logger.info(f'execute [{self.name}] -> {self.func}') logger.info(f'execute [{self.name}] -> {self.func}')
kwargs = {parameter: getattr(args, parameter) for parameter in self.signature.parameters} kwargs = {parameter: getattr(args, parameter) for parameter in self.signature.parameters}
return self.func(**kwargs) if inspect.iscoroutinefunction(self.func):
return asyncio.get_event_loop().run_until_complete(self.func(**kwargs))
else:
return self.func(**kwargs)
def setup(self, parser: argparse.ArgumentParser) -> None: def setup(self, parser: argparse.ArgumentParser) -> None:
parser.description = self.description parser.description = self.description

Просмотреть файл

@ -8,7 +8,7 @@ import colorama
from a01.cli import cmd, arg from a01.cli import cmd, arg
from a01.output import output_in_table from a01.output import output_in_table
from a01.models import TaskCollection from a01.models import TaskCollection
from a01.operations import query_tasks_by_run, query_run from a01.operations import query_tasks_by_run_async, query_run_async
@cmd('get run', desc='Retrieve a run') @cmd('get run', desc='Retrieve a run')
@ -23,12 +23,13 @@ from a01.operations import query_tasks_by_run, query_run
help='When download the recording files the files are arranged in directory structure mimic Azure CLI ' help='When download the recording files the files are arranged in directory structure mimic Azure CLI '
'source code.') 'source code.')
@arg('raw', help='For debug.') @arg('raw', help='For debug.')
def get_run(run_id: str, log: bool = False, recording: bool = False, recording_az_mode: bool = False, async def get_run(run_id: str, log: bool = False, recording: bool = False, recording_az_mode: bool = False,
show_all: bool = False, raw: bool = False) -> None: show_all: bool = False, raw: bool = False) -> None:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try: try:
tasks = TaskCollection(query_tasks_by_run(run_id), run_id) tasks = await query_tasks_by_run_async(run_id)
tasks = TaskCollection(tasks, run_id)
output_in_table(tasks.get_table_view(failed=not show_all), headers=tasks.get_table_header()) output_in_table(tasks.get_table_view(failed=not show_all), headers=tasks.get_table_header())
output_in_table(tasks.get_summary(), tablefmt='plain') output_in_table(tasks.get_summary(), tablefmt='plain')
@ -46,7 +47,7 @@ def get_run(run_id: str, log: bool = False, recording: bool = False, recording_a
task.download_recording(recording_az_mode) task.download_recording(recording_az_mode)
if raw: if raw:
run = query_run(run_id=run_id) run = await query_run_async(run_id=run_id)
print(json.dumps(run.to_dict(), indent=2)) print(json.dumps(run.to_dict(), indent=2))
except ValueError as err: except ValueError as err:
logger.error(err) logger.error(err)

Просмотреть файл

@ -1,3 +1,3 @@
# pylint: disable=unused-import # pylint: disable=unused-import
from .query_tasks import query_tasks, query_tasks_by_run from .query_tasks import query_tasks, query_tasks_by_run, query_tasks_by_run_async, query_tasks_async
from .query_runs import query_run, query_runs from .query_runs import query_run, query_runs, query_run_async, query_runs_async