build.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/python
  2. from browser.linkjs import link
  3. import os
  4. import subprocess
  5. import sys
  6. def run(cmd):
  7. p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
  8. return p.stdout.read().decode()
  9. def build(out, use_git):
  10. version = None
  11. if use_git:
  12. print(run('git pull'))
  13. version = run('git log -1 --format="%ci%n%H"')
  14. build_version = None
  15. build_version_path = os.path.join(out, 'version.txt')
  16. try:
  17. with open(build_version_path) as f:
  18. build_version = f.read()
  19. except:
  20. pass
  21. if (not build_version is None) and build_version == version:
  22. print("current html is up to date, do nothing")
  23. return
  24. if not os.path.exists(out):
  25. os.mkdir(out)
  26. link('oc.js', os.path.join(out, 'oc.js'), 'src', version)
  27. with open('browser/oberonjs.html') as input:
  28. with open(os.path.join(out, 'oberonjs.html'), 'w') as output:
  29. output.write(input.read())
  30. if version is None:
  31. if os.path.exists(build_version_path):
  32. os.remove(build_version_path)
  33. else:
  34. with open(build_version_path, 'w') as f:
  35. f.write(version)
  36. if __name__ == '__main__':
  37. if len(sys.argv) < 2:
  38. print('Pull repo and build html page\nUsage: build.py <output directory> [--no-git]')
  39. exit(-1)
  40. use_git = len(sys.argv) < 3 or sys.argv[2] != '--no-git'
  41. build(sys.argv[1], use_git)