[yocto] [[PATCH][qa-tools] 07/16] ts/toaster/helpers.py: Add new class ToasterHelper instead functions.
Aníbal Limón
anibal.limon at linux.intel.com
Tue Feb 9 14:43:16 PST 2016
In order to provide a better interface add a ToasterHelper class the
functionality is the same so only modified functions to match method
definitions.
Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
tests/toaster/helpers.py | 62 ++++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 28 deletions(-)
diff --git a/tests/toaster/helpers.py b/tests/toaster/helpers.py
index 5e54723..98b65e0 100644
--- a/tests/toaster/helpers.py
+++ b/tests/toaster/helpers.py
@@ -37,37 +37,43 @@ def _check_output1(*popenargs, **kwargs):
raise subprocess.CalledProcessError(retcode, cmd, output=output)
return output
-def _execute_command(directory, cmd):
- return _check_output1([SHELL_CMD, "-c", "cd %s; %s" % \
- (directory, cmd)], stderr=subprocess.STDOUT)
+class ToasterHelper(object):
+ def __init__(self, directory, repo, repo_ref='master'):
+ self.directory = directory
+ self.repo = repo
+ self.repo_ref = repo_ref
-def _execute_command_venv(directory, venv, cmd):
- return _execute_command(directory, "source %s/%s/bin/activate; %s" % \
- (directory, venv, cmd))
+ def _execute_command(self, cmd):
+ return _check_output1([SHELL_CMD, "-c", "cd %s; %s" % \
+ (self.directory, cmd)], stderr=subprocess.STDOUT)
-def toaster_clone(directory, repo, ref='master', rm=False):
- if os.path.exists(directory):
- if rm:
- shutil.rmtree(directory)
- else:
- raise IOError
+ def _execute_command_venv(self, venv, cmd):
+ return self._execute_command("source %s/%s/bin/activate; %s"\
+ % (self.directory, venv, cmd))
- subprocess.check_output([SHELL_CMD, "-c", "git clone %s %s" % \
- (repo, directory)], stderr=subprocess.STDOUT)
- _execute_command(directory, "git checkout %s -b %s" % \
- (ref, TOASTER_TEST_BRANCH))
+ def clone(self, rm=False):
+ if os.path.exists(self.directory):
+ if rm:
+ shutil.rmtree(self.directory)
+ else:
+ raise IOError
-def toaster_setup(directory):
- _execute_command(directory, "virtualenv %s" % VENV_NAME)
- _execute_command_venv(directory, VENV_NAME, "pip install -r" \
- " bitbake/toaster-requirements.txt")
+ subprocess.check_output([SHELL_CMD, "-c", "git clone %s %s" % \
+ (self.repo, self.directory)], stderr=subprocess.STDOUT)
+ self._execute_command("git checkout %s -b %s" % \
+ (self.repo_ref, TOASTER_TEST_BRANCH))
-def toaster_start(directory):
- return _execute_command_venv(directory, VENV_NAME,
- "source %s/oe-init-build-env; source %s/bitbake/bin/toaster start" % \
- (directory, directory))
+ def setup(self):
+ self._execute_command("virtualenv %s" % VENV_NAME)
+ self._execute_command_venv(VENV_NAME, "pip install -r" \
+ " bitbake/toaster-requirements.txt")
-def toaster_stop(directory):
- return _execute_command_venv(directory, VENV_NAME,
- "source %s/oe-init-build-env; source %s/bitbake/bin/toaster stop" % \
- (directory, directory))
+ def start(self):
+ return self._execute_command_venv(VENV_NAME,
+ "source %s/oe-init-build-env; source %s/bitbake/bin/toaster start" % \
+ (self.directory, self.directory))
+
+ def stop(self):
+ return self._execute_command_venv(VENV_NAME,
+ "source %s/oe-init-build-env; source %s/bitbake/bin/toaster stop" % \
+ (self.directory, self.directory))
--
2.1.4
More information about the yocto
mailing list