autobuild: Avoid unnecessary chdir() calls.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 1 Oct 2010 15:45:47 +0000 (17:45 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 1 Oct 2010 16:49:42 +0000 (18:49 +0200)
script/autobuild.py

index 48ac15028a25a187ae8ea4d0bab952bf0655770d..be8006c3245d80ae516bd5f91cf43f2c1dcaa5a4 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright Andrew Tridgell 2010
 # released under GNU GPL v3 or later
 
-from subprocess import Popen, PIPE
+from subprocess import call, check_call,Popen, PIPE
 import os, tarfile, sys, time
 from optparse import OptionParser
 import smtplib
@@ -71,21 +71,17 @@ retry_task = [ '''set -e
                ''' % samba_master]
 
 def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True):
-    cwd = os.getcwd()
-    os.chdir(dir)
     if show is None:
         show = options.verbose
     if show:
         print("Running: '%s' in '%s'" % (cmd, dir))
     if output:
-        ret = Popen([cmd], shell=True, stdout=PIPE).communicate()[0]
-        os.chdir(cwd)
-        return ret
-    ret = os.system(cmd)
-    os.chdir(cwd)
-    if checkfail and ret != 0:
-        raise Exception("FAILED %s: %d" % (cmd, ret))
-    return ret
+        return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0]
+    elif checkfail:
+        return check_call(cmd, shell=True)
+    else:
+        return call(cmd, shell=True)
+
 
 class builder(object):
     '''handle build of one directory'''