From 5c68a2e3ea7337fb87117331b45d8aabde84cf0d Mon Sep 17 00:00:00 2001
From: neodarz <neodarz@neodarz.net>
Date: Sun, 26 May 2019 13:08:51 +0200
Subject: Move generate_table to external file

---
 generators/generators.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 pyblog                   | 94 +-----------------------------------------------
 2 files changed, 92 insertions(+), 93 deletions(-)

diff --git a/generators/generators.py b/generators/generators.py
index 2705ca69..9e0fb33c 100644
--- a/generators/generators.py
+++ b/generators/generators.py
@@ -46,3 +46,94 @@ def generate_menu():
         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)
diff --git a/pyblog b/pyblog
index 3ac492d1..e6a15c57 100755
--- a/pyblog
+++ b/pyblog
@@ -51,98 +51,6 @@ from config.config import *
 from generators import generators
 
 
-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)
-
 def generate_blog_list(feed):
     """"Generate blog list """
 
@@ -655,7 +563,7 @@ def generate_index_and_feed():
 
     generate_index(feed)
     generators.generate_menu()
-    generate_table()
+    generators.generate_table()
     generate_blog_list(feed)
     generate_notes_list()
     rewrite_title()
-- 
cgit v1.2.1