Last active
August 29, 2015 14:02
-
-
Save jirikuncar/e4bfd248221c387de835 to your computer and use it in GitHub Desktop.
Invenio WebDoc to rst migration script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from invenio.base.factory import with_app_context | |
def html2rst(html): | |
p = subprocess.Popen(['pandoc', '--from=html', '--to=rst'], | |
stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
return p.communicate(html)[0] | |
@with_app_context() | |
def main(): | |
from invenio.legacy.webstyle.registry import doc_category_topics | |
from invenio.legacy.webstyle.webdoc import transform, get_webdoc_parts | |
topics = doc_category_topics('admin').keys() | |
for webdoc in topics: | |
parts = get_webdoc_parts(webdoc) | |
print webdoc | |
with open('docs/admin/' + webdoc + '.rst', 'w+') as f: | |
f.write('.. _{0}:\n\n'.format(webdoc)) | |
f.write(html2rst("<h1>{title}<h1> {body}".format(**parts))) | |
with open('docs/admin/index.rst', 'w+') as f: | |
index = """.. _admins-guide: | |
============= | |
Admin's Guide | |
============= | |
.. toctree:: | |
:maxdepth: 1 | |
{0} | |
""".format("\n ".join(sorted(topics))) | |
f.write(index) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment