aboutsummaryrefslogtreecommitdiff
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
parenta4c612707f13c41d94a15e62adb64ab75b03a988 (diff)
downloadpaludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.gz
paludis-ba68c346ded62b46d6881cef4a9fb12e766c07fb.tar.xz
(python) Start of examples.
-rw-r--r--doc/api/index.html.part35
-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
6 files changed, 204 insertions, 4 deletions
diff --git a/doc/api/index.html.part b/doc/api/index.html.part
index cb0c3b9..c43cce7 100644
--- a/doc/api/index.html.part
+++ b/doc/api/index.html.part
@@ -22,139 +22,172 @@ how concepts map on to different language bindings.</p>
<tr>
<th>Example</th>
<th colspan="3">Language</th>
+ <th>Description</th>
</tr>
<tr>
+ <td>example_command_line</td>
+ <td>C++:
+ <a href="cplusplus/example__command__line_8hh-source.html">hh</a>
+ <a href="cplusplus/example__command__line_8cc.html">cc</a>
+ </td>
+ <td><a href="ruby/example_command_line.html">Ruby</a></td>
+ <td><a href="python/example_command_line.html">Python</a></td>
+ <td>Common command line code (not a standalone example)</td>
+ </tr>
+ <tr>
<td>example_about</td>
<td><a href="cplusplus/example__about_8cc-example.html">C++</a></td>
<td><a href="ruby/example_about.html">Ruby</a></td>
<td></td>
+ <td>How to use Paludis version macros</td>
</tr>
<tr>
<td>example_action</td>
<td><a href="cplusplus/example__action_8cc-example.html">C++</a></td>
<td><a href="ruby/example_action.html">Ruby</a></td>
<td></td>
+ <td>How to use actions</td>
</tr>
<tr>
<td>example_contents</td>
<td><a href="cplusplus/example__contents_8cc-example.html">C++</a></td>
<td><a href="ruby/example_contents.html">Ruby</a></td>
<td></td>
+ <td>How to use contents</td>
</tr>
<tr>
<td>example_dep_label</td>
<td><a href="cplusplus/example__dep__label_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to handle dependency labels</td>
</tr>
<tr>
<td>example_dep_spec</td>
<td><a href="cplusplus/example__dep__spec_8cc-example.html">C++</a></td>
<td><a href="ruby/example_dep_spec.html">Ruby</a></td>
<td></td>
+ <td>How to handle dependency specs</td>
</tr>
<tr>
<td>example_dep_spec_flattener</td>
<td><a href="cplusplus/example__dep__spec__flattener_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use DepSpecFlattener</td>
</tr>
<tr>
<td>example_dep_tag</td>
<td><a href="cplusplus/example__dep__tag_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to handle dependency tags</td>
</tr>
<tr>
<td>example_dep_tree</td>
<td><a href="cplusplus/example__dep__tree_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to handle dependency specs</td>
</tr>
<tr>
<td>example_environment</td>
<td><a href="cplusplus/example__environment_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use EnvironmentMaker and the resultant Environment</td>
</tr>
<tr>
<td>example_formatter</td>
<td><a href="cplusplus/example__formatter_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to create a formatter</td>
</tr>
<tr>
<td>example_mask</td>
<td><a href="cplusplus/example__mask_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use Mask</td>
</tr>
<tr>
<td>example_match_package</td>
<td><a href="cplusplus/example__match__package_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use paludis::match_package and paludis::match_package_in_set</td>
</tr>
<tr>
<td>example_metadata_key</td>
<td><a href="cplusplus/example__metadata__key_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use MetadataKey</td>
</tr>
<tr>
<td>example_name</td>
<td><a href="cplusplus/example__name_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use name classes</td>
</tr>
<tr>
<td>example_package_database</td>
<td><a href="cplusplus/example__package__database_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use PackageDatabase</td>
</tr>
<tr>
<td>example_package_id</td>
<td><a href="cplusplus/example__package__id_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use PackageID</td>
</tr>
<tr>
<td>example_query</td>
<td><a href="cplusplus/example__query_8cc-example.html">C++</a></td>
<td><a href="ruby/example_query.html">Ruby</a></td>
<td></td>
+ <td>How to use the standard Query classes</td>
</tr>
<tr>
<td>example_query_delegate</td>
<td><a href="cplusplus/example__query__delegate_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to implement a new Query classes</td>
</tr>
<tr>
<td>example_repository</td>
<td><a href="cplusplus/example__repository_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use Repository</td>
</tr>
<tr>
<td>example_stringify_formatter</td>
<td><a href="cplusplus/example__stringify__formatter_8cc-example.html">C++</a></td>
<td></td>
<td></td>
+ <td>How to use StringifyFormatter</td>
</tr>
<tr>
<td>example_version_operator</td>
<td><a href="cplusplus/example__version__operator_8cc-example.html">C++</a></td>
<td><a href="ruby/example_version_operator.html">Ruby</a></td>
<td></td>
+ <td>How to use VersionOperator</td>
</tr>
<tr>
<td>example_version_spec</td>
<td><a href="cplusplus/example__version__spec_8cc-example.html">C++</a></td>
<td><a href="ruby/example_version_spec.html">Ruby</a></td>
- <td></td>
+ <td><a href="python/example_version_spec.html">Python</a></td>
+ <td>How to use VersionSpec</td>
</tr>
</table>
diff --git a/doc/api/python/Makefile.am b/doc/api/python/Makefile.am
index f8d8d7d..f6a679e 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 0000000..6dd99a0
--- /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 0000000..1146f30
--- /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 0000000..93f5ba5
--- /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 0000000..3d255ea
--- /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 */