aboutsummaryrefslogtreecommitdiff
path: root/doc/api/python/create_python_examples.py
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-11-13 21:57:31 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-11-13 21:57:31 +0000
commitba68c346ded62b46d6881cef4a9fb12e766c07fb (patch)
tree35dfdaac33993b4ae9831d4c1fb975ed101eb3fa /doc/api/python/create_python_examples.py
parenta4c612707f13c41d94a15e62adb64ab75b03a988 (diff)
downloadpaludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.gz
paludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.xz
(python) Start of examples.
Diffstat (limited to 'doc/api/python/create_python_examples.py')
-rwxr-xr-xdoc/api/python/create_python_examples.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/api/python/create_python_examples.py b/doc/api/python/create_python_examples.py
new file mode 100755
index 000000000..6dd99a0f1
--- /dev/null
+++ b/doc/api/python/create_python_examples.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+import sys, os, re
+from pygments import highlight
+from pygments.lexers import PythonLexer
+from pygments.formatters import HtmlFormatter
+
+srcdir = sys.argv[1]
+
+lexer = PythonLexer()
+formatter = HtmlFormatter(linenos=True, cssclass="syntax")
+
+topuri = '../../'
+toplinks = file(os.path.join(srcdir, '../toplinks.html.part.in')).read()
+header = file(os.path.join(srcdir, '../../header.html.part.in')).read()
+footer = file(os.path.join(srcdir, '../../footer.html.part.in')).read()
+css = '<link rel="stylesheet" href="python_syntax.css" type="text/css" />'
+
+header = header.replace('###TOPLINKS###', toplinks)
+header = header.replace('###TOPURI###', topuri)
+header = header.replace('</head>', css + '</head>')
+
+for example in sys.argv[2:]:
+ input = file(os.path.join(srcdir, example)).read()
+
+ example_html = "python/" + example.replace(".py", ".html")
+
+ out_file = file(example_html, "w")
+ out_file.write(header)
+ out_file.write("<h1>%s</h1>" % example)
+ out_file.write("<p>%s</h1>" % re.search('"""(.*?)"""', input).groups()[0])
+ out_file.close()
+
+ highlight(input, lexer, formatter, file(example_html, "a"))
+
+ file(example_html, "a").write(footer)