.build_web.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from shutil import copyfile
  2. from subprocess import check_output, CalledProcessError
  3. import sys
  4. import os
  5. import platform
  6. import subprocess
  7. Import("env")
  8. def is_tool(name):
  9. cmd = "where" if platform.system() == "Windows" else "which"
  10. try:
  11. check_output([cmd, name])
  12. return True
  13. except:
  14. return False;
  15. def build_web():
  16. if is_tool("npm"):
  17. os.chdir("web")
  18. print("Attempting to build webpage...")
  19. try:
  20. if platform.system() == "Windows":
  21. print check_output(["npm.cmd", "install", "--only=dev"])
  22. print check_output(["node_modules\\.bin\\gulp.cmd"])
  23. else:
  24. print check_output(["npm", "install"])
  25. print check_output(["node_modules/.bin/gulp"])
  26. copyfile("build/index.html.gz.h", "../dist/index.html.gz.h")
  27. except OSError as e:
  28. print "Encountered error OSError building webpage:", e
  29. if e.filename:
  30. print "Filename is", e.filename
  31. print "WARNING: Failed to build web package. Using pre-built page."
  32. except CalledProcessError as e:
  33. print e.output
  34. print "Encountered error CalledProcessError building webpage:", e
  35. print "WARNING: Failed to build web package. Using pre-built page."
  36. except Exception as e:
  37. print "Encountered error", type(e).__name__, "building webpage:", e
  38. print "WARNING: Failed to build web package. Using pre-built page."
  39. finally:
  40. os.chdir("..");
  41. build_web()