Tutorial: added intro section about Python interactive intepreter

This commit is contained in:
Jason Gerard DeRose 2008-11-10 21:33:15 -07:00
parent 2be9f2bba8
commit 16b86d559a

View File

@ -19,7 +19,7 @@
'''
Package containing core library.
Package containing the core library.
=============================
Tutorial for Plugin Authors
@ -35,6 +35,54 @@ and `ipa_server.plugins` provide real-life examples of how to write good
plugins.
----------------------------
How this tutorial is written
----------------------------
The code examples in this tutorial are presented as if entered into a Python
interactive interpreter session. As such, when you create a real plugin in
a source file, a few details will be different (in addition to the fact that
you will never include the ``>>>`` nor ``...`` at the beginning of each line
of code).
The tutorial examples all have this pattern:
::
>>> from ipalib import Command, get_standard_api
>>> api = get_standard_api()
>>> class my_command(Command):
... pass
...
>>> api.register(my_command)
>>> api.finalize()
We call `get_standard_api()` to get an *example* instance of `plugable.API`
to work with. But a real plugin will use the standard *run-time* instance
of `plugable.API`, which is available at ``ipalib.api``.
A real plugin will have this pattern:
::
from ipalib import Command, api
class my_command(Command):
pass
api.register(my_command)
The differences are that in a real plugin you will use the standard
``ipalib.api`` instance of `plugable.API` and that you will *not* call
`plugable.API.finalize()`. When in doubt, look at some of the built-in
plugins for guidance, like those in `ipalib.plugins`.
If don't know what the Python *interactive interpreter* is, or are confused
about what this *Python* is in the first place, then you probably should start
with the Python tutorial:
http://docs.python.org/tutorial/index.html
------------------------------------
First steps: A simple command plugin
------------------------------------
@ -67,7 +115,7 @@ instantiated nor the does the ``Command`` namespace yet exist. For example:
>>> hasattr(api, 'Command')
False
>>> api.finalize()
>>> api.finalize() # plugable.API.finalize()
>>> hasattr(api.Command, 'my_command')
True
>>> api.Command.my_command.doc