svg2-tools: Check whether node should be called as "node" or "nodejs".

details:   https://svgwg.org/hg/svg2-tools/rev/63ffebec495a
branches:  
changeset: 84:63ffebec495a
user:      Cameron McCormack <cam@mcc.id.au>
date:      Tue Apr 01 11:14:13 2014 +1100
description:
Check whether node should be called as "node" or "nodejs".

diffstat:

 build.py |  22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diffs (104 lines):

diff --git a/build.py b/build.py
--- a/build.py
+++ b/build.py
@@ -36,16 +36,20 @@ def getstatusoutput(cmd):
   import subprocess
   pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True,
                           universal_newlines=True)  
   output = "".join(pipe.stdout.readlines()) 
   sts = pipe.wait()
   if sts is None: sts = 0
   return sts, output
 
+def getstatus(cmd):
+    status, output = getstatusoutput(cmd)
+    return status
+
 # 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'))
 
@@ -104,29 +108,39 @@ if len(sys.argv) == 2 and sys.argv[1] ==
     for file in files[:]:
       file = join(parent, file)
       if file != readme:
         os.remove(file)
     for dir in dirs[:]:
       os.rmdir(join(parent, dir))
   sys.exit(0)
 
+# See if we should call "node" or "nodejs":
+
+status, output = getstatusoutput("which nodejs")
+if getstatus("which nodejs") == 0:
+    node = "nodejs"
+elif getstatus("which node") == 0:
+    node = "node"
+else:
+    exit(1, 'FAIL: could not find "nodejs" or "node" on the PATH')
+  
 # Get all the pages and resources from publish.xml:
 
 os.chdir(master_dir)
-status, output = 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()
 
 os.chdir(master_dir)
-status, output = getstatusoutput("node \"" +
+status, output = getstatusoutput(node + " \"" +
     native_path(join(tools_dir, "publish/publish.js")) + "\" --list-resources")
 os.chdir(repo_dir)
 if status != 0:
   exit(1, 'FAIL: could not get list of resources')
 
 resources = output.split()
 
 # Build chapters as required:
@@ -154,17 +168,17 @@ for name in all:
     if srctime > desttime:
       tobuild.append(pub_path)
       tobuild_names.append(name)
       break
 
 if tobuild:
   toremove = tobuild
   os.chdir(master_dir)
-  run("node \"" +
+  run(node + " \"" +
       native_path(join(tools_dir, join("publish","publish.js"))) +
       "\" --build " +
       " ".join(tobuild_names) +
       (" --local-style" if os.environ.get("SVG_BUILD_LOCAL_STYLE_SHEETS") else ""))
   toremove = []
   os.chdir(repo_dir) # chdir back
 
 # Build single page spec as required:
@@ -179,17 +193,17 @@ if len(all) > 1:
     singlePageTime = getmtime(single_page)
     for name in all:
       if getmtime(join(publish_dir, name + ".html")) > singlePageTime:
         buildSinglePage = True
         break
   
   if buildSinglePage:
     os.chdir(master_dir)
-    run("node \"" +
+    run(node + " \"" +
         native_path(join(tools_dir, join("publish","publish.js"))) +
         "\" --build-single-page")
     os.chdir(repo_dir) # chdir back
 
 # Copy over anything else that needs to be copied to 'publish':
 for f in resources:
   tocopypath = join(master_dir, f)
   if os.path.exists(tocopypath):

Received on Tuesday, 1 April 2014 00:14:34 UTC