| Index: scripts/common/annotator.py
|
| diff --git a/scripts/common/annotator.py b/scripts/common/annotator.py
|
| index 8fcb5ebc02ba7e2aa3554c2c54cafb7ae9155f85..ddac1f2ce4c6ba3498071ccf054fc0c36674af08 100755
|
| --- a/scripts/common/annotator.py
|
| +++ b/scripts/common/annotator.py
|
| @@ -6,6 +6,7 @@
|
|
|
| import os
|
| import sys
|
| +import time
|
| import traceback
|
|
|
| # These are maps of annotation key -> number of expected arguments.
|
| @@ -32,6 +33,14 @@ CONTROL_ANNOTATIONS = {
|
| }
|
|
|
| STREAM_ANNOTATIONS = {
|
| + # CURRENT_TIMESTAMP has one parameter, current Unix timestamp, which in
|
| + # practice specifies timestamp of the following annotation.
|
| + # The following annotation MUST be emitted immediately,
|
| + # however there is no requirement for the annotation after the next one
|
| + # to be emitted immediately. Annotation parsers must not consider
|
| + # CURRENT_TIMESTAMP for annotations that follow the annotation which is next
|
| + # after the CURRENT_TIMESTAMP.
|
| + 'CURRENT_TIMESTAMP': 1,
|
| 'HALT_ON_FAILURE': 0,
|
| 'HONOR_ZERO_RETURN_CODE': 0,
|
| 'SEED_STEP': 1,
|
| @@ -197,11 +206,11 @@ class StructuredAnnotationStep(StepCommands, StepControlCommands):
|
| self.control = StepControlCommands(self.stream, self.flush_before)
|
| self.emitted_logs = set()
|
|
|
| -
|
| def __enter__(self):
|
| return self.step_started()
|
|
|
| def step_started(self):
|
| + self.annotation_stream.emit_current_timestamp()
|
| self.control.step_started()
|
| return self
|
|
|
| @@ -211,6 +220,7 @@ class StructuredAnnotationStep(StepCommands, StepControlCommands):
|
| if exc_type:
|
| self.step_exception_occured(exc_type, exc_value, tb)
|
|
|
| + self.annotation_stream.emit_current_timestamp()
|
| self.control.step_closed()
|
| self.annotation_stream.current_step = ''
|
| return not exc_type
|
| @@ -223,6 +233,7 @@ class StructuredAnnotationStep(StepCommands, StepControlCommands):
|
|
|
| def step_ended(self):
|
| self.annotation_stream.step_cursor(self.annotation_stream.current_step)
|
| + self.annotation_stream.emit_current_timestamp()
|
| self.control.step_closed()
|
| self.annotation_stream.current_step = ''
|
|
|
| @@ -253,10 +264,15 @@ class StructuredAnnotationStream(AnnotationPrinter):
|
|
|
| def __init__(self, stream=sys.stdout,
|
| flush_before=sys.stderr,
|
| - seed_steps=None): # pylint: disable=W0613
|
| + seed_steps=None, # pylint: disable=W0613
|
| + time_fn=None):
|
| super(StructuredAnnotationStream, self).__init__(stream=stream,
|
| flush_before=flush_before)
|
| self.current_step = ''
|
| + self.time_fn = time_fn or time.time
|
| +
|
| + def emit_current_timestamp(self):
|
| + self.current_timestamp(self.time_fn())
|
|
|
| def step(self, name):
|
| """Provide a context with which to execute a step."""
|
|
|