From 98ce072f00cb28fa831cd0de1d8964c7ca8274d1 Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 18 May 2017 20:50:53 +0200 Subject: Add menu and table --- pyblog | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 180 insertions(+), 1 deletion(-) (limited to 'pyblog') diff --git a/pyblog b/pyblog index 4dd2eb4e..256ed9e3 100755 --- a/pyblog +++ b/pyblog @@ -348,7 +348,8 @@ def generate_submenu(): htmly_website_page = "" # Writing the menu in all pages contained in the variable in place of the -- generate submenu here -- @@ -363,6 +364,181 @@ def generate_submenu(): os.remove(tmppath) +def generate_situation1menu(): + """Generate situation1menu.""" + + sys.stderr.write("generating situation1menu\n") + + documents_fileList = [] + documents_fileList.append("/website/Documents/situation-pro-1.html") + + fd, tmppath = tempfile.mkstemp() + os.close(fd) + + htmly_website_page = "" + + if os.path.exists(BUILDDIR+"/website/Documents/Situation1"): + + # Put in a list the pages where the menu will be written + for root, dirs, files in os.walk(BUILDDIR+"/website/Documents/Situation1"): + 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 = "" + + # 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'-- generate situation1menu here --', htmly_website_page, line)) + + os.remove(tmppath) + +def generate_situation2menu(): + """Generate situation2menu.""" + + documents_fileList = [] + documents_fileList.append("/website/Documents/situation-pro-2.html") + + fd, tmppath = tempfile.mkstemp() + os.close(fd) + + htmly_website_page = "" + + if os.path.exists(BUILDDIR+"/website/Documents/Situation2"): + sys.stderr.write("generating situation2menu\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 = "" + + # 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'-- generate situation2menu 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 = "" + + # 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'
-- 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=''
+                                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=''
+                                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'^    \$.*\$$', "
  • "+line.split("$")[1]+'
  • ', line)) + first_comp = 1 + elif (re.match('^ \$.*[^\$]$', line)): + if first_comp == 1: + indexmd.write(re.sub(r'^ \$.*[^\$]$', "", line)) + else: + indexmd.write(re.sub(r'^ \$.*', "", 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 --", "
    CompétenceActivitéJustification
    • "+line.split("$")[1]+'
    • ', line)) + first_comp = 0 + else: + indexmd.write(re.sub(r'^ \$.*[^\$]$', "
    • "+line.split("$")[1]+'
    • ', 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'^ \$.*', "
    • "+line.split("$")[1]+"
    • "+line+"
    ", line)) + + os.remove(tmppath) + def generate_blog_list(feed): """"Generate blog list """ @@ -883,6 +1059,9 @@ def generate_index_and_feed(): generate_index(feed) generate_menu() generate_submenu() + generate_situation1menu() + generate_situation2menu() + generate_table() generate_blog_list(feed) generate_notes_list() rewrite_title() -- cgit v1.2.1