Add template to specified page object (wikitools).
()
| 79 | |
| 80 | |
| 81 | def ConvertFilesToRst(): |
| 82 | """Add template to specified page object (wikitools).""" |
| 83 | indexfiletext = '============================\nWiki snapshot (ready-for-review)\n============================\n\n%s\n.. toctree::\n :maxdepth: 2\n' % snapshot_version_information |
| 84 | for file in os.listdir(wiki_checkout): |
| 85 | if not file.endswith(".md"): |
| 86 | continue |
| 87 | |
| 88 | inputfilename = wiki_checkout + file |
| 89 | markdown = Path(inputfilename).read_text(encoding='utf-8') |
| 90 | if 'This article has moved from the wiki to the new site' in markdown: |
| 91 | continue |
| 92 | if 'This page has been migrated to the main site' in markdown: |
| 93 | continue |
| 94 | |
| 95 | print(file) |
| 96 | # get name of file |
| 97 | filenamestripped = os.path.splitext(file)[0] |
| 98 | indexfiletext += '\n %s' % filenamestripped |
| 99 | outputfilename = output_dir + filenamestripped + '.rst' |
| 100 | |
| 101 | command = 'pandoc -f markdown -t rst -o "%s" "%s"' % (outputfilename, inputfilename) |
| 102 | print(command) |
| 103 | if os.system(command): |
| 104 | sys.exit(1) |
| 105 | title = filenamestripped.replace('-', ' ') |
| 106 | # print title |
| 107 | logfile.write('title from filename: %s \n' % title) |
| 108 | # add import message to title |
| 109 | title += ' (wiki-import)' |
| 110 | length = len(title) |
| 111 | # print length |
| 112 | headerbar = '' |
| 113 | for _ in range(length): |
| 114 | headerbar += '=' |
| 115 | page_reference = filenamestripped |
| 116 | page_reference_link_text = '.. _%s:\n\n' % page_reference |
| 117 | titlebar = page_reference_link_text + headerbar + '\n' + title + '\n' + headerbar + '\n' |
| 118 | textinfile = '' |
| 119 | # Add titlebar to start of the file (from the filename) |
| 120 | textinfile += titlebar |
| 121 | # Add wiki snapshot information |
| 122 | |
| 123 | textinfile += snapshot_version_information |
| 124 | |
| 125 | with open(outputfilename, encoding='utf-8') as infile: |
| 126 | for line in infile: |
| 127 | textinfile += line |
| 128 | |
| 129 | # print textinfile |
| 130 | with open(outputfilename, 'w', encoding='utf-8') as outfile: |
| 131 | outfile.write(textinfile) |
| 132 | |
| 133 | # write the index |
| 134 | with open(output_dir + 'index.rst', 'w', encoding='utf-8') as outfile: |
| 135 | outfile.write(indexfiletext) |
| 136 | |
| 137 | |
| 138 | def FixupConvertedRstFiles(): |