# HG changeset patch # Parent cd4fd7a02ce26e427fc4fc82be850bea13fcce96 # User Brian Birtles Replace commands.getstatusoutput with cross-platform version diff --git a/build.py b/build.py --- a/build.py +++ b/build.py @@ -32,16 +32,29 @@ def exit(code, *message): sys.stderr.write(message[0] + '\n') sys.exit(code) def native_path(s): if exists("/usr/bin/cygpath.exe"): return commands.getoutput("cygpath -a -w %s" % s) return s +# Multiplatform alternative to commands.getstatusoutput from +# http://stackoverflow.com/questions/1193583/what-is-the-multiplatform-alternative-to-subprocess-getstatusoutput-older-comma +def getstatusoutput(cmd): + """Return (status, output) of executing cmd in a shell.""" + """This new implementation should work on all platforms.""" + import subprocess + pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, + universal_newlines=True) + output = "".join(pipe.stdout.readlines()) + sts = pipe.returncode + if sts is None: sts = 0 + return sts, output + # could allow this to be passed in: repo_dir = os.getcwd() master_dir = join(repo_dir, 'master') build_dir = join(repo_dir, 'build') publish_dir = join(build_dir, 'publish') tools_dir = normpath(join(repo_dir, '..', 'svg2-tools')) publishjs_dir = join(tools_dir, 'publish') @@ -101,17 +114,17 @@ if len(sys.argv) == 2 and sys.argv[1] == os.rmdir(join(parent, dir)) sys.exit(0) new_build = len(sys.argv) == 2 and sys.argv[1] == "-n" # Get all the pages from publish.xml: os.chdir(master_dir) -status, output = commands.getstatusoutput("node \"" + +status, output = getstatusoutput("node \"" + native_path(join(tools_dir, "publish/publish.js")) + "\" --list-pages") os.chdir(repo_dir) if status != 0: exit(1, 'FAIL: could not get list of specification pages') all = output.split() # Build svg.idlx as required: