From a9265031ba01c3ac7c4fab9fdc921a617d6e2e79 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 8 Feb 2017 11:14:40 +0000 Subject: [PATCH] TimeoutError: moved to devlib.exception Moved TimeoutError from devlib.util.misc to devlib.exception. It was previously defined in misc because it needed to be there when the code was part of WA in order to prevent an import cycle. This is not necessary in devlib, so it is moved to be with the other exception definitions. --- devlib/exception.py | 17 ++++++++++++++--- devlib/utils/misc.py | 19 +++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/devlib/exception.py b/devlib/exception.py index 8bb6d2b..aa41eb4 100644 --- a/devlib/exception.py +++ b/devlib/exception.py @@ -14,9 +14,6 @@ # -from devlib.utils.misc import TimeoutError # NOQA pylint: disable=W0611 - - class DevlibError(Exception): """Base class for all Workload Automation exceptions.""" pass @@ -38,3 +35,17 @@ class HostError(DevlibError): """An error has occured on the host""" pass + +class TimeoutError(DevlibError): + """Raised when a subprocess command times out. This is basically a ``DevlibError``-derived version + of ``subprocess.CalledProcessError``, the thinking being that while a timeout could be due to + programming error (e.g. not setting long enough timers), it is often due to some failure in the + environment, and there fore should be classed as a "user error".""" + + def __init__(self, command, output): + super(TimeoutError, self).__init__('Timed out: {}'.format(command)) + self.command = command + self.output = output + + def __str__(self): + return '\n'.join([self.message, 'OUTPUT:', self.output or '']) diff --git a/devlib/utils/misc.py b/devlib/utils/misc.py index df27a1d..95c660d 100644 --- a/devlib/utils/misc.py +++ b/devlib/utils/misc.py @@ -36,6 +36,9 @@ from functools import partial import wrapt +from devlib.exception import TimeoutError + + # ABI --> architectures list ABI_MAP = { 'armeabi': ['armeabi', 'armv7', 'armv7l', 'armv7el', 'armv7lh'], @@ -120,22 +123,6 @@ def preexec_function(): check_output_logger = logging.getLogger('check_output') -# Defined here rather than in devlib.exceptions due to module load dependencies -class TimeoutError(Exception): - """Raised when a subprocess command times out. This is basically a ``WAError``-derived version - of ``subprocess.CalledProcessError``, the thinking being that while a timeout could be due to - programming error (e.g. not setting long enough timers), it is often due to some failure in the - environment, and there fore should be classed as a "user error".""" - - def __init__(self, command, output): - super(TimeoutError, self).__init__('Timed out: {}'.format(command)) - self.command = command - self.output = output - - def __str__(self): - return '\n'.join([self.message, 'OUTPUT:', self.output or '']) - - def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs): """This is a version of subprocess.check_output that adds a timeout parameter to kill the subprocess if it does not return within the specified time."""