diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-12-12 18:48:21 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-12-13 12:36:41 -0500 |
commit | 3c79914e8288553f289d5b07621e37e170bf429b (patch) | |
tree | 4f7d99367725d34d284fae80718d4ae142514fb0 /buildstream/plugin.py | |
parent | 98f0f3881082589fe4bf995dbf5b09a88dd55f8f (diff) | |
download | buildstream-3c79914e8288553f289d5b07621e37e170bf429b.tar.gz |
plugin.py: Implement Plugin.timed_activity() using Context._timed_activity()
Diffstat (limited to 'buildstream/plugin.py')
-rw-r--r-- | buildstream/plugin.py | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py index fa1cb03a1..a6baff804 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -67,7 +67,6 @@ Class Reference --------------- """ -import datetime import os import subprocess from contextlib import contextmanager @@ -75,7 +74,7 @@ from weakref import WeakValueDictionary from . import _yaml, _signals from . import utils -from ._exceptions import PluginError, ImplError, BstError +from ._exceptions import PluginError, ImplError from ._message import Message, MessageType @@ -449,37 +448,10 @@ class Plugin(): # This will raise SourceError on its own self.call(... command which takes time ...) """ - starttime = datetime.datetime.now() - stopped_time = None - - def stop_time(): - nonlocal stopped_time - stopped_time = datetime.datetime.now() - - def resume_time(): - nonlocal stopped_time - nonlocal starttime - sleep_time = datetime.datetime.now() - stopped_time - starttime += sleep_time - - with _signals.suspendable(stop_time, resume_time): - try: - # Push activity depth for status messages - self.__message(MessageType.START, activity_name, detail=detail) - self.__context._push_message_depth(silent_nested) - yield - - except BstError as e: - # Note the failure in status messages and reraise, the scheduler - # expects an error when there is an error. - elapsed = datetime.datetime.now() - starttime - self.__context._pop_message_depth() - self.__message(MessageType.FAIL, activity_name, elapsed=elapsed) - raise - - elapsed = datetime.datetime.now() - starttime - self.__context._pop_message_depth() - self.__message(MessageType.SUCCESS, activity_name, elapsed=elapsed) + with self.__context._timed_activity(activity_name, + detail=detail, + silent_nested=silent_nested): + yield def call(self, *popenargs, fail=None, **kwargs): """A wrapper for subprocess.call() |