1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

workflow: less verbose naming

This commit is contained in:
Jan Pochyla 2016-10-06 12:35:05 +02:00
parent 6d5514ac4a
commit 492e71f147

View File

@ -1,37 +1,38 @@
from trezor import log, loop
_started_workflows = []
_default_workflow = None
_default_workflow_genfunc = None
_started = []
_default = None
_default_genfunc = None
def start_default(genfunc):
global _default_workflow
global _default_workflow_genfunc
_default_workflow_genfunc = genfunc
_default_workflow = _default_workflow_genfunc()
log.info(__name__, 'starting default workflow %s', _default_workflow)
loop.schedule_task(_default_workflow)
global _default
global _default_genfunc
_default_genfunc = genfunc
_default = _default_genfunc()
log.info(__name__, 'start default %s', _default)
loop.schedule_task(_default)
def close_default():
global _default
log.info(__name__, 'close default %s', _default)
_default.close()
_default = None
def start_workflow(workflow):
global _default_workflow
if _default_workflow is not None:
log.info(__name__, 'closing default workflow %s', _default_workflow)
_default_workflow.close()
_default_workflow = None
log.info(__name__, 'starting workflow %s', workflow)
_started_workflows.append(workflow)
loop.schedule_task(watch_workflow(workflow))
if _default is not None:
close_default()
_started.append(workflow)
log.info(__name__, 'start %s', workflow)
loop.schedule_task(_watch_workflow(workflow))
async def watch_workflow(workflow):
global _default_workflow
async def _watch_workflow(workflow):
try:
return await workflow
finally:
_started_workflows.remove(workflow)
if not _started_workflows and _default_workflow_genfunc is not None:
start_default(_default_workflow_genfunc)
_started.remove(workflow)
if not _started and _default_genfunc is not None:
start_default(_default_genfunc)