File: jekyll_fix.py

package info (click to toggle)
bitwuzla 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 43,292 kB
  • sloc: cpp: 94,870; python: 3,254; ansic: 1,613; sh: 50; makefile: 10
file content (107 lines) | stat: -rw-r--r-- 3,525 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
###
# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
#
# Copyright (C) 2023 by the authors listed in the AUTHORS file at
# https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
#
# This file is part of Bitwuzla under the MIT license. See COPYING for more
# information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
##

import argparse
import os
import shutil

ap = argparse.ArgumentParser()
ap.add_argument('output')
args = ap.parse_args()

if not os.path.isdir(args.output):
    raise RuntimeError(f'Directory `{args.output}` does not exist.')

docs_dir = f'{args.output}-gh'
# Delete directory if it already exists
if os.path.exists(docs_dir):
    print(f'[jekyll-fix] delete {docs_dir}')
    shutil.rmtree(docs_dir)
# Copy directory
print(f'[jekyll-fix] copy {args.output} to {docs_dir}')
src = shutil.copytree(args.output, docs_dir)

# Rename _static to static since Jekyll ignores directory with _ prefix.
src = os.path.join(docs_dir, '_static')
dst = os.path.join(docs_dir, 'static')
if os.path.exists(src):
    if os.path.exists(dst):
        shutil.rmtree(dst)
    print(f'[jekyll-fix] rename {src} to {dst}')
    os.rename(src, dst)
if not os.path.exists(dst):
    raise RuntimeError(f'Directory `{dst}` not found after rename.')

# Rename static/sphinx_javascript_frameworks_compat.js to
# static/sphinx_javascript_frameworks_compat.js
src = os.path.join(dst, '_sphinx_javascript_frameworks_compat.js')
dst = os.path.join(dst, 'sphinx_javascript_frameworks_compat.js')
if os.path.exists(src):
    if os.path.exists(dst):
        shutil.rmtree(dst)
    print(f'[jekyll-fix] rename {src} to {dst}')
    os.rename(src, dst)
if not os.path.exists(dst):
    raise RuntimeError(f'File `{dst}` not found after rename.')


# Delete _sources
src = os.path.join(docs_dir, '_sources')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    shutil.rmtree(src)
# Delete conf.py
src = os.path.join(docs_dir, 'conf.py')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    os.remove(src)
# Delete objects.inv
src = os.path.join(docs_dir, 'objects.inv')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    os.remove(src)
# Delete c/Doxyfile
src = os.path.join(docs_dir, 'c/Doxyfile')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    os.remove(src)
# Delete c/xml
src = os.path.join(docs_dir, 'c/xml')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    shutil.rmtree(src)
# Delete cpp/Doxyfile
src = os.path.join(docs_dir, 'cpp/Doxyfile')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    os.remove(src)
# Delete cpp/xml
src = os.path.join(docs_dir, 'cpp/xml')
if os.path.exists(src):
    print(f'[jekyll-fix] delete {src}')
    shutil.rmtree(src)

# Rename _static to static and _sphinx_javascript_frameworks_compat.js to
# sphinx_javascript_frameworks_compat.js in all documentation files
print(f'[jekyll-fix] rename "_static" and ' +
       '"_sphinx_javascript_frameworks_compat.js" in files')
for root, dirs, files in os.walk(docs_dir):
    for file in files:
        if not file.endswith('.html'):
            continue
        filename = os.path.join(root, file)
        with open(filename, 'r+') as file:
            contents = file.read()
            file.seek(0)
            file.write(contents.replace('_static', 'static').
                replace(
                    '_sphinx_javascript_frameworks_compat.js',
                    'sphinx_javascript_frameworks_compat.js'))
            file.truncate()