[yocto] [[PATCH][autobuilder] 1/8] autobuilder/lib: Add buildsteps module for provide helpers

Aníbal Limón anibal.limon at linux.intel.com
Fri Feb 19 08:14:42 PST 2016


Add ShellCommandCleanEnv helper for run command in a clean
enviroment a shell for run the command can be specified also
the variables to preserve in the new enviroment.

Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
 .../site-packages/autobuilder/lib/buildsteps.py    | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 lib/python2.7/site-packages/autobuilder/lib/buildsteps.py

diff --git a/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py b/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py
new file mode 100644
index 0000000..8b719fa
--- /dev/null
+++ b/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py
@@ -0,0 +1,41 @@
+'''
+Created on Feb 15, 2016
+
+__author__ = "Anibal (alimon) Limon"
+__copyright__ = "Copyright 2016, Intel Corp."
+__credits__ = ["Anibal Limon"]
+__license__ = "GPL"
+__version__ = "2.0"
+__maintainer__ = "Anibal Limon"
+__email__ = "anibal.limon at linux.intel.com"
+'''
+
+import os
+from buildbot.steps.shell import ShellCommand
+
+DEFAULT_SHELL = 'bash'
+
+class ShellCommandCleanEnv(ShellCommand):
+    def __init__(self, factory, argdict=None, **kwargs):
+        shell = DEFAULT_SHELL
+        if 'SHELL' in kwargs:
+            shell = kwargs['SHELL']
+            del kwargs['SHELL']
+
+        if 'PENV' in kwargs:
+            preserve_env = kwargs['PENV']
+            del kwargs['PENV']
+        else:
+            preserve_env = ['HOME', 'PWD', 'http_proxy', 'https_proxy',
+                            'ftp_proxy', 'no_proxy', 'GIT_PROXY_COMMAND']
+
+        env_command = self._get_env_cleaned_command(shell, preserve_env)
+        self.command = "%s \'%s\'" % (env_command, self.command)
+        ShellCommand.__init__(self, **kwargs)
+
+    def _get_env_cleaned_command(self, shell, preserve_env):
+        pe_cmd = ''
+        for pe in preserve_env:
+            pe_cmd += "%s=\"$%s\" " % (pe, pe)
+
+        return "env -i %s %s -c " % (pe_cmd, shell)
-- 
2.1.4




More information about the yocto mailing list