Skip to content

Instantly share code, notes, and snippets.

@jirikuncar
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirikuncar/e4bfd248221c387de835 to your computer and use it in GitHub Desktop.
Save jirikuncar/e4bfd248221c387de835 to your computer and use it in GitHub Desktop.
Invenio WebDoc to rst migration script
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