[Checkins] SVN: z3c.recipe.paster/trunk/s Added recipe for generate a paster script with a custom name and egg dependencies.

Roger Ineichen roger at projekt01.ch
Mon Jun 30 19:39:38 EDT 2008


Log message for revision 87868:
  Added recipe for generate a paster script with a custom name and egg dependencies.
  This allows us to setup more then one paster with different egg dependencies
  Added tests

Changed:
  U   z3c.recipe.paster/trunk/setup.py
  U   z3c.recipe.paster/trunk/src/z3c/recipe/paster/README.txt
  A   z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.py
  A   z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.txt
  U   z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py

-=-
Modified: z3c.recipe.paster/trunk/setup.py
===================================================================
--- z3c.recipe.paster/trunk/setup.py	2008-06-30 19:38:20 UTC (rev 87867)
+++ z3c.recipe.paster/trunk/setup.py	2008-06-30 23:39:35 UTC (rev 87868)
@@ -77,6 +77,7 @@
     entry_points = {
         'zc.buildout': [
              'serve = z3c.recipe.paster.serve:ServeSetup',
+             'paster = z3c.recipe.paster.paster:PasterSetup',
          ]
     },
 )

Modified: z3c.recipe.paster/trunk/src/z3c/recipe/paster/README.txt
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/README.txt	2008-06-30 19:38:20 UTC (rev 87867)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/README.txt	2008-06-30 23:39:35 UTC (rev 87868)
@@ -5,7 +5,10 @@
 z3c.recipe.paster
 -----------------
 
-This Zope 3 recipes offers a Paste Deploy setup for Zope3 projects.
+This Zope 3 recipes offers a Paste Deploy setup for Zope3 projects. It requires
+to define a PAste DEploy *.ini file in the buoldout.cfg. If you need a simple 
+PasteScript setup you can use the z3c.recipe.paster:paster recipe which allows
+to run already existing *.ini files.
 
 
 Options

Added: z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.py
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.py	                        (rev 0)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.py	2008-06-30 23:39:35 UTC (rev 87868)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""PasteScript recipe for setup a paste.script.command.run call for Zope3 apps
+
+$Id:$
+"""
+
+import os
+import zc.recipe.egg
+
+
+class PasterSetup(zc.recipe.egg.Scripts):
+    """Paster setup script."""
+
+    def __init__(self, buildout, name, options):
+        if options.get('eggs') is None:
+            raise zc.buildout.UserError(
+                'You have to define at least one egg for setup a paster.')
+
+        # add PasteScript egg
+        options['eggs'] = '%s\nPasteScript' % options.get('eggs')
+        super(PasterSetup, self).__init__(buildout, name, options)
+        self.egg = zc.recipe.egg.Egg(buildout, name, options)
+
+    def install(self):
+        # install paste.script.command.run
+        dest = []
+        extra_paths = self.egg.extra_paths
+        eggs, ws = self.egg.working_set()
+        dest.extend(zc.buildout.easy_install.scripts(
+            [('%s'% self.name, 'paste.script.command', 'run')],
+            ws, self.options['executable'],
+            self.buildout['buildout']['bin-directory'],
+            extra_paths = extra_paths,
+            interpreter=self.options.get('interpreter'),
+            initialization=self.options.get('initialization', ''),
+            arguments=self.options.get('arguments', ''),
+            ))
+
+        return dest


Property changes on: z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.txt
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.txt	                        (rev 0)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.txt	2008-06-30 23:39:35 UTC (rev 87868)
@@ -0,0 +1,113 @@
+======
+README
+======
+
+z3c.recipe.paster
+-----------------
+
+This Zope 3 recipes offers a Paste Deploy script setup for Zope3 projects.
+
+
+z3c.recipe.paster:paster
+------------------------
+
+The paster part allows us to setup a plain paster executable which could be 
+used for start up your zope server using the paste deploy ".ini file like:
+``bin/paster serve app.ini``. This recipe inherits the zc.recipe.egg class
+and will setup the paster within your egg dependency. All you have to do is
+to define your eggs. The benefit of this recipe compared with the built in
+PasteScript it the option to choose another name if you need more then one 
+paster script. This is required if you have paster with different egg 
+dependencies in one buildout configuration.
+
+
+Options
+*******
+
+The 'serve' recipe accepts the following options:
+
+eggs
+  The names of one or more eggs, with their dependencies that should
+  be included in the Python path of the generated scripts.
+
+ini
+  The paste deploy *.ini file content.
+
+zope.conf
+  The zope.conf file defining the DB used in the WSGI app and the error log
+  section.
+
+site.zcml
+  The zope site.zcml file used by the zope application.
+
+
+Test
+****
+
+Lets define a (bogus) eggs that we can use in our application:
+
+  >>> mkdir('sample')
+  >>> write('sample', 'setup.py',
+  ... '''
+  ... from setuptools import setup
+  ... setup(name = 'sample')
+  ... ''')
+
+Now check if the setup was correct:
+
+  >>> ls('bin')
+  -  buildout-script.py
+  -  buildout.exe
+
+We'll create a ``buildout.cfg`` file that defines our paster configuration:
+
+  >>> write('buildout.cfg',
+  ... '''
+  ... [buildout]
+  ... develop = sample
+  ... parts = mypaster
+  ... 
+  ... [mypaster]
+  ... recipe = z3c.recipe.paster:paster
+  ... eggs = sample
+  ...  
+  ... ''' % globals())
+
+  >>> ls('bin')
+  -  buildout-script.py
+  -  buildout.exe
+
+Now, Let's run the buildout and see what we get:
+
+  >>> print system(join('bin', 'buildout')),
+  Develop: '/sample-buildout/sample'
+  Installing mypaster.
+  Generated script '/sample-buildout/bin/mypaster'.
+
+Now check if the setup was correct:
+
+  >>> ls('bin')
+  -  buildout-script.py
+  -  buildout.exe
+  -  mypaster-script.py
+  -  mypaster.exe
+
+Check the content of our new generated paster script. As you can see, the 
+generated script uses the ``paste.script.command.run`` for starting our server.
+This script is generic but uses the path of our eggs and uses the given name:
+
+  >>> cat('bin', 'mypaster-script.py')
+  <BLANKLINE>
+  import sys
+  sys.path[0:0] = [
+    '/sample-buildout/sample',
+    '/sample-pyN.N.egg',
+    'c:\\python24\\lib\\site-packages',
+    '/sample-pyN.N.egg',
+    '/sample-pyN.N.egg',
+    ]
+  <BLANKLINE>
+  import paste.script.command
+  <BLANKLINE>
+  if __name__ == '__main__':
+      paste.script.command.run()


Property changes on: z3c.recipe.paster/trunk/src/z3c/recipe/paster/paster.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py	2008-06-30 19:38:20 UTC (rev 87867)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py	2008-06-30 23:39:35 UTC (rev 87868)
@@ -128,12 +128,16 @@
 
 
 def test_suite():
-    return unittest.TestSuite(
+    return unittest.TestSuite((
         doctest.DocFileSuite('README.txt',
             setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
             optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
             checker=checker),
-        )
+        doctest.DocFileSuite('paster.txt',
+            setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+            checker=checker),
+        ))
 
 
 if __name__ == '__main__':



More information about the Checkins mailing list