aboutsummaryrefslogtreecommitdiff
path: root/doc/api/python
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
parenta4c612707f13c41d94a15e62adb64ab75b03a988 (diff)
downloadpaludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.gz
paludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.xz
(python) Start of examples.
Diffstat (limited to 'doc/api/python')
-rw-r--r--doc/api/python/Makefile.am18
-rwxr-xr-xdoc/api/python/create_python_examples.py37
-rwxr-xr-xdoc/api/python/example_command_line.py25
-rwxr-xr-xdoc/api/python/example_version_spec.py20
-rw-r--r--doc/api/python/python_syntax.css73
5 files changed, 170 insertions, 3 deletions
diff --git a/doc/api/python/Makefile.am b/doc/api/python/Makefile.am
index f8d8d7dff..f6a679ef2 100644
--- a/doc/api/python/Makefile.am
+++ b/doc/api/python/Makefile.am
@@ -2,7 +2,16 @@ SUBDIRS = .
CLEANFILES = *~ python/*
MAINTAINERCLEANFILES = Makefile.in
-EXTRA_DIST = epydoc.css
+
+examples = \
+ example_command_line.py \
+ example_version_spec.py
+
+EXTRA_DIST = epydoc.css \
+ python_syntax.css \
+ $(examples)
+
+dist_noinst_SCRIPTS = create_python_examples.py
if ENABLE_PYTHON
@@ -10,9 +19,9 @@ all-local : epydoc
epydoc : python
-python : epydoc.css
+python : epydoc.css python_syntax.css create_python_examples.py $(examples)
rm -fr python
- mkdir -p python
+ mkdir python
env \
LD_LIBRARY_PATH=`echo "\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs\`: \
\`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/.libs\`: \
@@ -26,6 +35,9 @@ python : epydoc.css
PYTHONPATH="./.libs" \
epydoc -n Paludis -o python -u http://paludis.pioto.org --no-frames -c $(srcdir)/epydoc.css \
$(top_builddir)/python/paludis.so
+ $(PYTHON) $(srcdir)/create_python_examples.py $(srcdir) $(examples)
+ cp $(srcdir)/python_syntax.css python/
+
install-data-local :
mkdir -p $(DESTDIR)$(htmldir)/api
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)
diff --git a/doc/api/python/example_command_line.py b/doc/api/python/example_command_line.py
new file mode 100755
index 000000000..1146f30eb
--- /dev/null
+++ b/doc/api/python/example_command_line.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+"""Basic command line handling for most examples"""
+
+import optparse
+import paludis
+
+class ExampleCommandLine:
+ def __init__(self):
+ parser = optparse.OptionParser()
+ parser.add_option("", "--log-level", type = "choice",
+ choices = ["debug", "qa", "warning", "silence"],
+ action = "store", dest = "log_level", help = "Specify the log level")
+ parser.add_option("-E", "--environment", action = "store", dest = "environment", default = "",
+ help = "Environment specification")
+
+ (options, args) = parser.parse_args()
+
+ print options.log_level
+ if options.log_level:
+ paludis.Log.instance.log_level = getattr(paludis.LogLevel, options.log_level.upper())
+
+if __name__ == "__main__":
+ ExampleCommandLine()
diff --git a/doc/api/python/example_version_spec.py b/doc/api/python/example_version_spec.py
new file mode 100755
index 000000000..93f5ba50f
--- /dev/null
+++ b/doc/api/python/example_version_spec.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+"""This example demonstrates how to use VersionSpec"""
+
+import paludis
+
+# Make a list of versions
+versions = [paludis.VersionSpec(v) for v in "1.0 1.1 1.2 1.2-r1 2.0 2.0-try1 2.0-scm 9999".split()]
+
+# For each version...
+for v in versions:
+ print str(v) + ":"
+
+ # Show the output of various members.
+ print " Remove revision: %s" % v.remove_revision()
+ print " Revision only: %s" % v.revision_only()
+ print " Bump: %s" % v.bump()
+ print " Is SCM? %s" % v.is_scm
+ print
diff --git a/doc/api/python/python_syntax.css b/doc/api/python/python_syntax.css
new file mode 100644
index 000000000..3d255ea2b
--- /dev/null
+++ b/doc/api/python/python_syntax.css
@@ -0,0 +1,73 @@
+table.syntaxtable { background: #FFF5EE; width: 90%; margin: 0; padding: 0; border: 0; border-spacing: 0; border-collapse: collapse; }
+table.syntaxtable pre { margin: 0; padding: 0; border: 0; }
+table.syntaxtable td { margin: 0; padding: 3px; border: 0; }
+td.code { width: 100% }
+
+.syntaxtable pre { background: #fff5ee; color: #000000; background-color: #fff5ee }
+.syntaxtable pre .c { color: #339933; font-style: italic; background-color: #fff5ee } /* Comment */
+.syntaxtable pre .err { color: #000000; background-color: #fff5ee } /* Error */
+.syntaxtable pre .g { color: #000000; background-color: #fff5ee } /* Generic */
+.syntaxtable pre .k { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword */
+.syntaxtable pre .l { color: #000000; background-color: #fff5ee } /* Literal */
+.syntaxtable pre .n { color: #000000; background-color: #fff5ee } /* Name */
+.syntaxtable pre .o { color: #000000; background-color: #fff5ee } /* Operator */
+.syntaxtable pre .x { color: #000000; background-color: #fff5ee } /* Other */
+.syntaxtable pre .p { color: #000000; background-color: #fff5ee } /* Punctuation */
+.syntaxtable pre .cm { color: #339933; font-style: italic; background-color: #fff5ee } /* Comment.Multiline */
+.syntaxtable pre .cp { color: #339933; font-style: italic; background-color: #fff5ee } /* Comment.Preproc */
+.syntaxtable pre .c1 { color: #339933; font-style: italic; background-color: #fff5ee } /* Comment.Single */
+.syntaxtable pre .cs { color: #339933; font-style: italic; background-color: #fff5ee } /* Comment.Special */
+.syntaxtable pre .gd { color: #000000; background-color: #fff5ee } /* Generic.Deleted */
+.syntaxtable pre .ge { color: #000000; text-decoration: underline; background-color: #fff5ee } /* Generic.Emph */
+.syntaxtable pre .gr { color: #000000; background-color: #ff0000 } /* Generic.Error */
+.syntaxtable pre .gh { color: #000000; font-weight: bold; background-color: #fff5ee } /* Generic.Heading */
+.syntaxtable pre .gi { color: #000000; background-color: #fff5ee } /* Generic.Inserted */
+.syntaxtable pre .go { color: #000000; background-color: #fff5ee } /* Generic.Output */
+.syntaxtable pre .gp { color: #000000; background-color: #fff5ee } /* Generic.Prompt */
+.syntaxtable pre .gs { color: #000000; background-color: #fff5ee } /* Generic.Strong */
+.syntaxtable pre .gu { color: #000000; font-weight: bold; background-color: #fff5ee } /* Generic.Subheading */
+.syntaxtable pre .gt { color: #000000; background-color: #fff5ee } /* Generic.Traceback */
+.syntaxtable pre .kc { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword.Constant */
+.syntaxtable pre .kd { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword.Declaration */
+.syntaxtable pre .kp { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword.Pseudo */
+.syntaxtable pre .kr { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword.Reserved */
+.syntaxtable pre .kt { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Keyword.Type */
+.syntaxtable pre .ld { color: #000000; background-color: #fff5ee } /* Literal.Date */
+.syntaxtable pre .m { color: #000000; background-color: #fff5ee } /* Literal.Number */
+.syntaxtable pre .s { color: #b8860b; background-color: #fff5ee } /* Literal.String */
+.syntaxtable pre .na { color: #8a2be2; background-color: #fff5ee } /* Name.Attribute */
+.syntaxtable pre .nb { color: #000000; background-color: #fff5ee } /* Name.Builtin */
+.syntaxtable pre .nc { color: #000000; background-color: #fff5ee } /* Name.Class */
+.syntaxtable pre .no { color: #000000; font-weight: bold; background-color: #fff5ee } /* Name.Constant */
+.syntaxtable pre .nd { color: #000000; background-color: #fff5ee } /* Name.Decorator */
+.syntaxtable pre .ni { color: #000000; background-color: #fff5ee } /* Name.Entity */
+.syntaxtable pre .ne { color: #000000; background-color: #fff5ee } /* Name.Exception */
+.syntaxtable pre .nf { color: #8a2be2; background-color: #fff5ee } /* Name.Function */
+.syntaxtable pre .nl { color: #000000; background-color: #fff5ee } /* Name.Label */
+.syntaxtable pre .nn { color: #000000; background-color: #fff5ee } /* Name.Namespace */
+.syntaxtable pre .nx { color: #000000; background-color: #fff5ee } /* Name.Other */
+.syntaxtable pre .py { color: #000000; background-color: #fff5ee } /* Name.Property */
+.syntaxtable pre .nt { color: #6a5acd; font-weight: bold; background-color: #fff5ee } /* Name.Tag */
+.syntaxtable pre .nv { color: #c71585; background-color: #fff5ee } /* Name.Variable */
+.syntaxtable pre .ow { color: #ff0000; background-color: #fff5ee } /* Operator.Word */
+.syntaxtable pre .w { color: #000000; background-color: #fff5ee } /* Text.Whitespace */
+.syntaxtable pre .mf { color: #000000; background-color: #fff5ee } /* Literal.Number.Float */
+.syntaxtable pre .mh { color: #000000; background-color: #fff5ee } /* Literal.Number.Hex */
+.syntaxtable pre .mi { color: #000000; background-color: #fff5ee } /* Literal.Number.Integer */
+.syntaxtable pre .mo { color: #000000; background-color: #fff5ee } /* Literal.Number.Oct */
+.syntaxtable pre .sb { color: #b8860b; background-color: #fff5ee } /* Literal.String.Backtick */
+.syntaxtable pre .sc { color: #b8860b; background-color: #fff5ee } /* Literal.String.Char */
+.syntaxtable pre .sd { color: #b8860b; background-color: #fff5ee } /* Literal.String.Doc */
+.syntaxtable pre .s2 { color: #b8860b; background-color: #fff5ee } /* Literal.String.Double */
+.syntaxtable pre .se { color: #b8860b; background-color: #fff5ee } /* Literal.String.Escape */
+.syntaxtable pre .sh { color: #b8860b; background-color: #fff5ee } /* Literal.String.Heredoc */
+.syntaxtable pre .si { color: #b8860b; background-color: #fff5ee } /* Literal.String.Interpol */
+.syntaxtable pre .sx { color: #b8860b; background-color: #fff5ee } /* Literal.String.Other */
+.syntaxtable pre .sr { color: #b8860b; background-color: #fff5ee } /* Literal.String.Regex */
+.syntaxtable pre .s1 { color: #b8860b; background-color: #fff5ee } /* Literal.String.Single */
+.syntaxtable pre .ss { color: #b8860b; background-color: #fff5ee } /* Literal.String.Symbol */
+.syntaxtable pre .bp { color: #000000; background-color: #fff5ee } /* Name.Builtin.Pseudo */
+.syntaxtable pre .vc { color: #c71585; background-color: #fff5ee } /* Name.Variable.Class */
+.syntaxtable pre .vg { color: #c71585; background-color: #fff5ee } /* Name.Variable.Global */
+.syntaxtable pre .vi { color: #c71585; background-color: #fff5ee } /* Name.Variable.Instance */
+.syntaxtable pre .il { color: #000000; background-color: #fff5ee } /* Literal.Number.Integer.Long */