Clone of official tools

Revision:
17:04753e1e329d
Parent:
13:ab47a20b66f0
Child:
19:3604ee113e2d
diff -r a6285a7e5cc6 -r 04753e1e329d utils.py
--- a/utils.py	Thu Jul 14 21:29:46 2016 +0100
+++ b/utils.py	Fri Jul 15 12:33:09 2016 +0100
@@ -33,10 +33,22 @@
         raise Exception('ERROR %d: "%s"' % (rc, text))
 
 
-def run_cmd(command, wd=None, redirect=False):
+def run_cmd(command, work_dir=None, chroot=None, redirect=False):
+    if chroot:
+        # Conventions managed by the web team for the mbed.org build system
+        chroot_cmd = [
+            '/usr/sbin/chroot', '--userspec=33:33', chroot
+        ]
+        for c in command:
+            chroot_cmd += [c.replace(chroot, '')]
+
+        logging.debug("Running command %s"%' '.join(chroot_cmd))
+        command = chroot_cmd
+        work_dir = chroot
+
     assert is_cmd_valid(command[0])
     try:
-        p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=wd)
+        p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=work_dir)
         _stdout, _stderr = p.communicate()
     except OSError as e:
         print "[OS ERROR] Command: "+(' '.join(command))