aboutsummaryrefslogtreecommitdiff
path: root/tools/build_website.py
blob: 77a049c94cbc60546797d94be2655a169da953e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

import os, subprocess, shutil

assert os.getcwd() == '/home/jpakkane'

from glob import glob

def purge(fname: str) -> None:
    if not os.path.exists(fname):
        return
    if os.path.isdir(fname):
        shutil.rmtree(fname)
    os.unlink(fname)

def update() -> None:
    webdir = 'mesonweb'
    repodir = 'mesonwebbuild'
    docdir = os.path.join(repodir, 'docs')
    builddir = os.path.join(docdir, 'builddir')
    htmldir = os.path.join(builddir, 'Meson documentation-doc/html')
#    subprocess.check_call(['git', 'pull'], cwd=webdir)
    subprocess.check_call(['git', 'fetch', '-a'], cwd=repodir)
    subprocess.check_call(['git', 'reset', '--hard', 'origin/master'],
                          cwd=repodir)
    if os.path.isdir(htmldir):
        shutil.rmtree(htmldir)
    if os.path.isdir(builddir):
        shutil.rmtree(builddir)
    env = os.environ.copy()
    env['PATH'] = env['PATH'] + ':/home/jpakkane/.local/bin'
    subprocess.check_call(['../meson.py', '.', 'builddir'], cwd=docdir, env=env)
    subprocess.check_call(['ninja'], cwd=builddir)
    old_files = glob(os.path.join(webdir, '*'))
    for f in old_files:
        base = f[len(webdir)+1:]
        if base == 'CNAME' or base == 'favicon.png':
            continue
        subprocess.check_call(['git', 'rm', '-rf', base], cwd=webdir)
    assert os.path.isdir(webdir)
    new_entries = glob(os.path.join(htmldir, '*'))
    for e in new_entries:
        shutil.move(e, webdir)
    subprocess.check_call('git add *', shell=True, cwd=webdir)
    subprocess.check_call(['git', 'commit', '-a', '-m', 'Bleep. Bloop. I am a bot.'],
                          cwd=webdir)
    subprocess.check_call(['git', 'push'], cwd=webdir)
    shutil.rmtree(builddir)

if __name__ == '__main__':
    update()