make_index.py 1.8 KB
Newer Older
paugier's avatar
paugier committed
1
2
3
4
from pathlib import Path
import sys

titles = {
paugier's avatar
paugier committed
5
6
7
8
    "Intro bash": "First steps with Linux and Bash",
    "Intro computing": "Introduction on scientific computing & why using Python for this course?",
    "Intro first steps": "First steps with Python",
    "Intro python language": "Some characteristics of the language",
paugier's avatar
paugier committed
9
10
11
    "Readwritefiles": "Read and write files",
    "Import standard library": "Import statements and the standart library",
    "Data struct": "Standard data structure (list, tuple, set and dict)",
paugier's avatar
paugier committed
12
13
    "Oop encapsulation": "Bonus: Object-oriented programming - encapsulation",
    "Oop inheritance": "Bonus: Object-oriented programming - inheritance",
paugier's avatar
paugier committed
14
15
16
17
18
    "Packaging": "Packaging, documentation and unittest",
    "Numpy scipy": "Numpy / Scipy",
    "Wrapping": "Wrapping compiled code",
    "Accelerators": "Tools to accelerate Python code",
    "Parallel": "Parallel computing (CPU bounded)",
paugier's avatar
paugier committed
19
    "Mercurial and gitlab": "Bonus: versioning with Mercurial and Gitlab",
paugier's avatar
paugier committed
20
    "Environnement": "Bonus: interpreters, distributions, packages"
paugier's avatar
paugier committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
}

this_dir = Path(__file__).parent

ipynb_files = sorted(tuple(this_dir.glob("*.ipynb")))

lines = []

for path in ipynb_files:
    name = path.with_suffix("").name
    index, title = name.split("_", 1)
    title = title.capitalize().replace("_", " ")

    if title in titles:
        title = titles[title]

    path_html = name + ".slides.html"
paugier's avatar
paugier committed
38
    lines.append(f"- `{title} <{path_html}>`_")
paugier's avatar
paugier committed
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

back = "\n"

code = """
Scientific computing course 2020
================================
"""

code += f"""
{back.join(lines)}
"""

path_rst = this_dir / "index.rst"

if path_rst.exists():

    with open(path_rst) as file:
        old_code = file.read()

    if code == old_code:
        sys.exit(0)

print(f"override {path_rst}")

with open(path_rst, "w") as file:
    file.write(code)