diff options
author | Josh Smith <joshsmith@codethink.co.uk> | 2018-07-25 12:42:18 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-07-27 13:41:26 +0900 |
commit | 4986527fd2f434cd7d71864689093a9c4f802f24 (patch) | |
tree | d464405c37d2912eb8caaa96696bd0542518a13f | |
parent | 9b2bc78fca5701c058d397abac16e284a31c76a4 (diff) | |
download | buildstream-4986527fd2f434cd7d71864689093a9c4f802f24.tar.gz |
plugin.py: Extend Plugin.call() API
Plugin.call() now takes fail_temporarily as an optional parameter,
when supplied it will cause subsequent failures to trigger temporary
errors as opposed to permanent errors.
This also extends Plugin.check_output() which makes use of Plugin.call()
-rw-r--r-- | buildstream/_exceptions.py | 4 | ||||
-rw-r--r-- | buildstream/plugin.py | 17 |
2 files changed, 13 insertions, 8 deletions
diff --git a/buildstream/_exceptions.py b/buildstream/_exceptions.py index 2b1d379c4..c86b6780c 100644 --- a/buildstream/_exceptions.py +++ b/buildstream/_exceptions.py @@ -136,8 +136,8 @@ class BstError(Exception): # or by the base :class:`.Plugin` element itself. # class PluginError(BstError): - def __init__(self, message, reason=None): - super().__init__(message, domain=ErrorDomain.PLUGIN, reason=reason) + def __init__(self, message, reason=None, temporary=False): + super().__init__(message, domain=ErrorDomain.PLUGIN, reason=reason, temporary=False) # LoadErrorReason diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 3e1d89052..9823ddbf2 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -478,13 +478,15 @@ class Plugin(): silent_nested=silent_nested): yield - def call(self, *popenargs, fail=None, **kwargs): + def call(self, *popenargs, fail=None, fail_temporarily=False, **kwargs): """A wrapper for subprocess.call() Args: popenargs (list): Popen() arguments fail (str): A message to display if the process returns a non zero exit code + fail_temporarily (bool): Whether any exceptions should + be raised as temporary. (*Since: 1.4*) rest_of_args (kwargs): Remaining arguments to subprocess.call() Returns: @@ -507,16 +509,18 @@ class Plugin(): "Failed to download ponies from {}".format( self.mirror_directory)) """ - exit_code, _ = self.__call(*popenargs, fail=fail, **kwargs) + exit_code, _ = self.__call(*popenargs, fail=fail, fail_temporarily=fail_temporarily, **kwargs) return exit_code - def check_output(self, *popenargs, fail=None, **kwargs): + def check_output(self, *popenargs, fail=None, fail_temporarily=False, **kwargs): """A wrapper for subprocess.check_output() Args: popenargs (list): Popen() arguments fail (str): A message to display if the process returns a non zero exit code + fail_temporarily (bool): Whether any exceptions should + be raised as temporary. (*Since: 1.4*) rest_of_args (kwargs): Remaining arguments to subprocess.call() Returns: @@ -555,7 +559,7 @@ class Plugin(): raise SourceError( fmt.format(plugin=self, track=tracking)) from e """ - return self.__call(*popenargs, collect_stdout=True, fail=fail, **kwargs) + return self.__call(*popenargs, collect_stdout=True, fail=fail, fail_temporarily=fail_temporarily **kwargs) ############################################################# # Private Methods used in BuildStream # @@ -619,7 +623,7 @@ class Plugin(): # Internal subprocess implementation for the call() and check_output() APIs # - def __call(self, *popenargs, collect_stdout=False, fail=None, **kwargs): + def __call(self, *popenargs, collect_stdout=False, fail=None, fail_temporarily=False, **kwargs): with self._output_file() as output_file: if 'stdout' not in kwargs: @@ -634,7 +638,8 @@ class Plugin(): exit_code, output = utils._call(*popenargs, **kwargs) if fail and exit_code: - raise PluginError("{plugin}: {message}".format(plugin=self, message=fail)) + raise PluginError("{plugin}: {message}".format(plugin=self, message=fail), + temporary=fail_temporarily) return (exit_code, output) |