[Checkins] SVN: zope2docs/trunk/zdgbook/source/ Added Getting Started chapter (need more cleanup)

Baiju M baiju.m.mail at gmail.com
Tue Oct 6 01:11:23 EDT 2009


Log message for revision 104823:
  Added Getting Started chapter (need more cleanup)
  

Changed:
  A   zope2docs/trunk/zdgbook/source/GettingStarted.rst
  U   zope2docs/trunk/zdgbook/source/Introduction.rst
  U   zope2docs/trunk/zdgbook/source/index.rst

-=-
Added: zope2docs/trunk/zdgbook/source/GettingStarted.rst
===================================================================
--- zope2docs/trunk/zdgbook/source/GettingStarted.rst	                        (rev 0)
+++ zope2docs/trunk/zdgbook/source/GettingStarted.rst	2009-10-06 05:11:22 UTC (rev 104823)
@@ -0,0 +1,370 @@
+###############
+Getting Started
+###############
+
+Introduction
+============
+
+This chapter cover installation and getting started with development
+of a simple application.  This guide use a build system called
+`Buildout <http://www.buildout.org>`_ to build the application.  And
+the Python packages developed as part of the application can be
+distributed as `Python eggs
+<http://peak.telecommunity.com/DevCenter/setuptools>`_.
+
+
+Directory Structure
+===================
+
+To begin the application development, create a directory structure to
+place Python packages and build system.
+
+::
+
+  $ mkdir poll
+  $ mkdir poll/poll_build
+  $ mkdir poll/poll.main
+
+All build related things can be added inside `poll_build` directory.
+And the main Python package can be added inside `poll.main`
+directory.  The ``poll`` will be a a namespace package created using
+the functionality provided by `pkg_resources` module included in
+setuptools.
+
+Bootstraping the Build
+======================
+
+You should have Python 2.5 or 2.6 already installed in your system.
+To start the build process, download and run `bootstrap.py` to
+install `setuptools` and `zc.buildout` packages.  The `bootstrap.py`
+will create the directory structure and `buildout` script inside
+`bin` directory.
+
+::
+
+  $ cd poll/poll.build
+  $ touch buildout.cfg
+  $ wget -c http://svn.zope.org/repos/main/zc.buildout/trunk/bootstrap/bootstrap.py
+  $ python2.6 bootstrap.py
+
+Installing Zope 2
+=================
+
+From Zope 2.12 onwards Zope 2 is distributed in egg format.  To
+install Zope 2 egg and create an instance, update buildout
+configuration file (``buildout.cfg``).
+
+::
+
+  [buildout]
+  parts = zope2
+          instance
+  extends = http://svn.zope.org/*checkout*/Zope/branches/2.12/versions.cfg
+
+  [zope2]
+  recipe = zc.recipe.egg
+  eggs = Zope2
+  interpreter = zopepy
+
+  [instance]
+  recipe = plone.recipe.zope2instance
+  user = admin:admin
+  http-address = 8080
+  eggs = ${zope2:eggs}
+
+The ``[zope2]`` part use `zc.recipe.egg` which will download `Zope2`
+egg and all its dependencies.  It will create few console scripts
+inside `bin` directory.  Also it will create a custom Python
+interpreter named ``zopepy``.
+
+The ``[instance]`` part creates a Zope 2 application instance to
+develop application.  It will create a script named ``instance``
+inside `bin` directory.  We can use that script to run the
+application instance.
+
+After updating the buildout configuration, you can run the `buildout`
+command to build the system.
+
+::
+
+  $ ./bin/buildout
+
+The initial build will take some time to complete.
+
+Running Instance
+================
+
+Once build is completed, you can run Zope 2 instance like this.
+
+::
+
+  $ ./bin/instance fg
+
+
+You can see that Zope is running in 8080 port.  You can go to the
+Zope Management Interface (ZMI).
+
+::
+
+  http://localhost:8080/manage
+
+You can provide the user name & password provided in `[instance]`
+part to access this page.
+
+You can see a list of installable applications in the drop-down box.
+Also you can see it in "Control_Panel" -> "Products".
+
+::
+
+  http://localhost:8080/Control_Panel/Products/manage_main
+
+In the next section we will make the `poll.main` listed here.  And
+later we will make it installable.
+
+
+Developing the main package
+===========================
+
+Now we can move to `poll.main` packae to create the main package to
+develop the application.  We can develop the entire application
+inside `poll.main` package.  But it is reccomended to split packages
+logically and maintain the dependencies between packages properly.
+
+::
+
+  $ cd ../poll.build
+
+Again we need to create the basic directory structure and `setup.py`
+to create egg distribution.  We are going to place python package
+inside `src` directory.
+
+::
+
+  $ touch setup.py
+  $ mkdir src
+  $ mkdir src/poll
+  $ mkdir src/poll/main
+  $ touch src/poll/__init__.py
+  $ touch src/poll/main/__init__.py
+  $ touch src/poll/main/configure.zcml
+
+The last file we created is a configuration file called Zope
+Configuration Markup Language (ZCML). Soon we will add some boiler
+plate code inside ZCML file.
+
+To declare `poll` as a namespace package, we need to add this boiler
+plate code to `src/poll/__init__.py`.
+
+::
+
+  __import__('pkg_resources').declare_namespace(__name__)
+
+Next we need to add the minimum meta data required for the package in
+`setup.py`.
+
+::
+
+  from setuptools import setup, find_packages
+
+  setup(
+      name="poll.main",
+      version="0.1",
+      packages=find_packages("src"),
+      package_dir={"": "src"},
+      namespace_packages=["poll"],
+      install_requires=["setuptools",
+                        "Zope2"],
+      )
+
+We need to add two more things to be recognized by Zope.  First,
+define this call-back function in `src/poll/main/__init__.py`.
+
+::
+
+  def initialize(context):
+      pass
+
+And in the ZCML file add these few lines.
+
+::
+
+  <configure
+      xmlns="http://namespaces.zope.org/five">
+
+      <registerPackage package="." initialize=".initialize" />
+
+  </configure>
+
+Creating Installable Application
+================================
+
+We need three things to make an installable application.
+
+ - Form object created using ZPT (manage_addPollMain)
+ - A function to define form action (addPollMain)
+ - A class to define toplevel application object (PollMain).
+
+And we need to register these things using the `context` passed to
+`initialize` method.
+
+We can define all these things in `app.py` and the form template as
+`manage_addPollMain_form.zpt`.
+
+::
+
+  $ touch src/poll/main/app.py
+  $ touch src/poll/main/manage_addPollMain_form.zpt
+
+Here is the code for `app.py`.
+
+::
+
+  from OFS.Folder import Folder
+  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+
+  class PollMain(Folder):
+      meta_type = "POLL"
+
+  manage_addPollMain = PageTemplateFile("manage_addPollMain_form", globals())
+
+  def addPollMain(context, id):
+      """ """
+      context._setObject(id, PollMain(id))
+      return "POLL Installed: %s" % id
+
+And `manage_addPollMain_form.zpt`.
+
+::
+
+  <html xmlns="http://www.w3.org/1999/xhtml"
+        xmlns:tal="http://xml.zope.org/namespaces/tal">
+    <body>
+
+      <h2>Add POLL</h2>
+      <form action="addPollMain" method="post">
+        Id: <input type="text" name="id" /><br />
+        Title: <input type="text" name="title" /><br />
+        <input type="submit" value="Add" />
+      </form>
+    </body>
+  </html>
+
+Finally we can register it like this (update `__init__.py`)::
+
+  from poll.main.app import PollMain, manage_addPollMain, addPollMain
+
+  def initialize(context):
+      context.registerClass(PollMain,
+                            constructors=(manage_addPollMain, addPollMain))
+
+The application is now ready to install. But we need to make some
+changes in `poll_build` to recognize this package by Zope 2.
+
+Adding poll.main to build
+=========================
+
+First in `[buildout]` part we need to mention that `poll.main` is
+locally developed.  Otherwise buildout will try to get the package
+from package index server, by default http://pypi.python.org/pypi .
+
+::
+
+  [buildout]
+  develop = ../poll.main
+  ...
+
+Also we need to add `poll.main` egg to `eggs` option in `[zope2]`
+part.
+
+::
+
+  ...
+  eggs = Zope2
+         poll.main
+  ...
+
+And finally we need to add a new option to include the ZCML file.
+So, that the package will be recognized by Zope.
+
+::
+
+  ...
+  zcml = poll.main
+
+The final `buildout.cfg` will look like this.
+
+::
+
+  [buildout]
+  develop = ../poll.main
+  parts = zope2
+          instance
+
+  [zope2]
+  recipe = zc.recipe.egg
+  eggs = Zope2
+         poll.main
+  interpreter = zopepy
+
+  [instance]
+  recipe = plone.recipe.zope2instance
+  user = admin:admin
+  http-address = 8080
+  eggs = ${zope2:eggs}
+  zcml = poll.main
+
+Now to make these change effective, run the buildout again.
+
+::
+
+  $ ./bin/buildout
+
+Now we can run application instance again.
+
+::
+
+  $ ./bin/instance fg
+
+Adding application instance
+===========================
+
+Visit ZMI and select `POLL` from drop-down box.  And fill the form and
+you can see that it tells that poll is installed.
+
+Adding the main page to POLL
+---------------------------
+
+In this section we will try to add a main page to POLL application.
+So that we can acces POLL application like this:
+http://localhost:8080/poll .
+
+First create a file named `index_html.zpt` inside `src/poll/main` with
+content like this::
+
+  <html>
+  <head>
+    <title>Welcome to POLL</title>
+  </head>
+  <body>
+
+  <h2>Welcome to POLL</h2>
+
+  </body>
+  </html>
+
+Now add an attribute named `index_html` inside PollMain class like
+this::
+
+  class PollMain(Folder):
+      meta_type = "POLL"
+
+      index_html = PageTemplateFile("index_html", globals())
+
+Now you can see that it display the main page when you access:
+http://localhost:8080/poll .
+
+Summary
+-------
+
+This chapter covered installation beginning a simple project in Zope
+2.

Modified: zope2docs/trunk/zdgbook/source/Introduction.rst
===================================================================
--- zope2docs/trunk/zdgbook/source/Introduction.rst	2009-10-06 03:05:10 UTC (rev 104822)
+++ zope2docs/trunk/zdgbook/source/Introduction.rst	2009-10-06 05:11:22 UTC (rev 104823)
@@ -51,6 +51,10 @@
 services to develop and deploy your own web applications.  This book
 covers the following topics:
 
+*Getting Started*
+  This chapter provides a brief overview of installation and getting
+  started with application development.
+
 *Components and Interfaces*
   Zope is moving toward a component-centric development model.  This
   chapter describes the new component model in Zope and how Zope

Modified: zope2docs/trunk/zdgbook/source/index.rst
===================================================================
--- zope2docs/trunk/zdgbook/source/index.rst	2009-10-06 03:05:10 UTC (rev 104822)
+++ zope2docs/trunk/zdgbook/source/index.rst	2009-10-06 05:11:22 UTC (rev 104823)
@@ -1,14 +1,11 @@
 Zope Developer's Guide
 ======================
 
-Contents
---------
-
 .. toctree::
    :maxdepth: 2
 
-   Outline.rst
    Introduction.rst
+   GettingStarted.rst
    ComponentsAndInterfaces.rst
    ObjectPublishing.rst
    Products.rst



More information about the checkins mailing list