build_website.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. import os, subprocess, shutil
  3. assert os.getcwd() == '/home/jpakkane'
  4. from glob import glob
  5. def purge(fname: str) -> None:
  6. if not os.path.exists(fname):
  7. return
  8. if os.path.isdir(fname):
  9. shutil.rmtree(fname)
  10. os.unlink(fname)
  11. def update() -> None:
  12. webdir = 'mesonweb'
  13. repodir = 'mesonwebbuild'
  14. docdir = os.path.join(repodir, 'docs')
  15. builddir = os.path.join(docdir, 'builddir')
  16. htmldir = os.path.join(builddir, 'Meson documentation-doc/html')
  17. # subprocess.check_call(['git', 'pull'], cwd=webdir)
  18. subprocess.check_call(['git', 'fetch', '-a'], cwd=repodir)
  19. subprocess.check_call(['git', 'reset', '--hard', 'origin/master'],
  20. cwd=repodir)
  21. if os.path.isdir(htmldir):
  22. shutil.rmtree(htmldir)
  23. if os.path.isdir(builddir):
  24. shutil.rmtree(builddir)
  25. env = os.environ.copy()
  26. env['PATH'] = env['PATH'] + ':/home/jpakkane/.local/bin'
  27. subprocess.check_call(['../meson.py', '.', 'builddir'], cwd=docdir, env=env)
  28. subprocess.check_call(['ninja'], cwd=builddir)
  29. old_files = glob(os.path.join(webdir, '*'))
  30. for f in old_files:
  31. base = f[len(webdir)+1:]
  32. if base == 'CNAME' or base == 'favicon.png':
  33. continue
  34. subprocess.check_call(['git', 'rm', '-rf', base], cwd=webdir)
  35. assert os.path.isdir(webdir)
  36. new_entries = glob(os.path.join(htmldir, '*'))
  37. for e in new_entries:
  38. shutil.move(e, webdir)
  39. subprocess.check_call('git add *', shell=True, cwd=webdir)
  40. subprocess.check_call(['git', 'commit', '-a', '-m', 'Bleep. Bloop. I am a bot.'],
  41. cwd=webdir)
  42. subprocess.check_call(['git', 'push'], cwd=webdir)
  43. shutil.rmtree(builddir)
  44. if __name__ == '__main__':
  45. update()