Debian Codegraph @

tools/build_website.py

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