aboutsummaryrefslogtreecommitdiff
path: root/generators/generators.py
blob: 9e0fb33c362897ea0dc7325034aa96685ed274fb (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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/python3

import os
import sys
import tempfile
import re

from config.config import *


def generate_menu():
    """Generate menu."""

    sys.stderr.write("generating menu\n")

    fd, tmppath = tempfile.mkstemp()
    os.close(fd)

    # Put in a list the pages where the menu will be written
    html_fileList = []
    for root, dirs, files in os.walk(BUILDDIR):
        for name in files:
            if name.endswith(".html"):
                try:
                    html_fileList.append(os.path.join(root.split('build/')[1], name))
                except IndexError:
                    html_fileList.append(name)

    # Generate the string who contain the links of the menu
    htmly_website_page = "<ul>"
    for name in sorted(os.listdir(os.path.join(BUILDDIR, "website"))):
        if name != "Documents":
            htmly_website_page += "<a href='/website/"+name+"' class='lia'><li><span class='left-lia'></span><span class='center-lia'>"+name.split('.html')[0]+"</span><span class='right-lia'></span></li></a>"
    htmly_website_page += "</ul>"

    # Writing the menu in all pages contained in the variable in place of the -- generate menu here --
    for html_file in html_fileList:
        with open(tmppath, 'w', encoding='utf-8') as tmpfile:
            if os.path.exists("build/"+html_file):
                with open("build/"+html_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build/"+html_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:
                            indexmd.write(re.sub(r'-- generate menu here --', htmly_website_page, line))

        os.remove(tmppath)


def generate_table():
    """Generate table."""

    first_comp = 1
    first_pr = 1
    tr_class = "odd"

    documents_fileList = []
    documents_fileList.append("/website/bts-sio.html")

    fd, tmppath = tempfile.mkstemp()
    os.close(fd)

    htmly_website_page = ""

    if os.path.exists(BUILDDIR+"/website/bts-sio.html"):
        sys.stderr.write("generating table\n")

        # Put in a list the pages where the menu will be written
        #for root, dirs, files in os.walk(BUILDDIR+"/website/Documents/Situation2"):
        #    for name in files:
        #        if name.endswith(".html"):
        #            try:
        #                documents_fileList.append(os.path.join(root.split('build')[1], name))
        #            except IndexError:
        #                documents_fileList.append(name)

        # Generate the string who contain the links of the menu
        #htmly_website_page = "<ul>"
        #for name in os.listdir(os.path.join(BUILDDIR, "website/Documents/Situation2")):
        #    htmly_website_page += "<a href='/website/Documents/Situation2/"+name+"' class='situation2lia'><li><span class='situation2left-lia'></span><span class='situation2center-lia'>"+name.split('.html')[0]+"</span><span class='situation2right-lia'></span></li></a>"
        #htmly_website_page += "</ul>"

    # Writing the menu in all pages contained in the variable in place of the -- generate submenu here --
    for document_file in documents_fileList:
        with open(tmppath, 'w', encoding='utf-8') as tmpfile:
            if os.path.exists("build"+document_file):
                with open("build"+document_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build"+document_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:
                            indexmd.write(re.sub(r'<pre>-- table --', '<table><colgroup><col width="18%"></col><col width="16%"></col><col width="23%"></col></colgroup><thead><tr class="header"><th>Compétence</th><th>Activité</th><th>Justification</th></tr></thead><tbody class="skill-table">', line))
                with open("build"+document_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build"+document_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:
                            if (re.match('^\$.*', line) and first_pr == 1):
                                line_edited='<tr class="'+tr_class+'">'
                                indexmd.write(re.sub(r'^\$.*', line_edited, line))
                                first_pr = 0
                                first_comp = 1
                            elif (re.match('^\$.*', line)):
                                if (tr_class == "odd"):
                                    tr_class = "even"
                                else:
                                    tr_class = "odd"
                                line_edited='</tr><tr class="'+tr_class+'">'
                                indexmd.write(re.sub(r'^\$.*', line_edited, line))
                            else:
                                indexmd.write(line)
                with open("build"+document_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build"+document_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:

                            if (re.match('^    \$.*\$$', line)):
                                indexmd.write(re.sub(r'^    \$.*\$$', "<li>"+line.split("$")[1]+'</li>', line))
                                first_comp = 1
                            elif (re.match('^    \$.*[^\$]$', line)):
                                if first_comp == 1:
                                    indexmd.write(re.sub(r'^    \$.*[^\$]$', "<td><ul><li>"+line.split("$")[1]+'</li>', line))
                                    first_comp = 0
                                else:
                                    indexmd.write(re.sub(r'^    \$.*[^\$]$', "<li>"+line.split("$")[1]+'</li>', line))
                            else:
                                indexmd.write(line)
                with open("build"+document_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build"+document_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:
                            if (re.match('^  \$.*', line)):
                                indexmd.write(re.sub(r'^  \$.*', "</td></ul><td><ul><li>"+line.split("$")[1]+"</li></ul></td>", line))
                            else:
                                indexmd.write(re.sub(r'^  \$.*', "</td></ul><td><ul><li>"+line+"</li></ul></td>", line))
                with open("build"+document_file, 'r', encoding='utf-8') as indexmd:
                    lines = indexmd.readlines()
                    with open("build"+document_file, 'w', encoding='utf-8') as indexmd:
                        for line in lines:
                            indexmd.write(re.sub(r"-- end table --", "</tbody></table>", line))

    os.remove(tmppath)