[Checkins] SVN: zc.zope3recipes/trunk/ Created another recipe called 'application' that installs Zope 3 solely from eggs.

Philipp von Weitershausen philikon at philikon.de
Sat Jul 14 11:02:55 EDT 2007


Log message for revision 77929:
  Created another recipe called 'application' that installs Zope 3 solely from eggs.
  The 'app' recipe is just a subclass that also supports Zope 3 from checkout or
  tarball.
  

Changed:
  U   zc.zope3recipes/trunk/setup.py
  U   zc.zope3recipes/trunk/zc/zope3recipes/README.txt
  U   zc.zope3recipes/trunk/zc/zope3recipes/recipes.py

-=-
Modified: zc.zope3recipes/trunk/setup.py
===================================================================
--- zc.zope3recipes/trunk/setup.py	2007-07-14 14:16:07 UTC (rev 77928)
+++ zc.zope3recipes/trunk/setup.py	2007-07-14 15:02:54 UTC (rev 77929)
@@ -39,6 +39,7 @@
     dependency_links = ['http://download.zope.org/distribution/'],
     entry_points = {
         'zc.buildout': [
+             'application = %s.recipes:Application' % name,
              'app = %s.recipes:App' % name,
              'instance = %s.recipes:Instance' % name,
              ]

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2007-07-14 14:16:07 UTC (rev 77928)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2007-07-14 15:02:54 UTC (rev 77929)
@@ -8,29 +8,20 @@
 invokes the application with a specific instance configuration.  A
 single application may have many instances.
 
-Building Zope 3 Applications
-============================
+Building Zope 3 applications (from eggs)
+========================================
 
-The "app" recipe is used to define a Zope application.  It is designed
-to work with classic Zope releases and with Zope solely as eggs.
-The app recipe causes a part to be created. The part will contain the
-scripts runzope and debugzope and the application's site.zcml.
-Both of the scripts will require providing a -C option and the path to a
-zope.conf file when run.  The debugzope script can be run with a script
-name and arguments, in which case it will run the script, rather than
-starting an interactive session.
+The 'application' recipe can be used to define a Zope application.  It
+is designed to work with with Zope solely from eggs.  The app recipe
+causes a part to be created. The part will contain the scripts runzope
+and debugzope and the application's site.zcml.  Both of the scripts
+will require providing a -C option and the path to a zope.conf file
+when run.  The debugzope script can be run with a script name and
+arguments, in which case it will run the script, rather than starting
+an interactive session.
 
-The app recipe accepts the following options:
+The 'application' recipe accepts the following options:
 
-zope3
-  The name of a section defining a location option that gives the
-  location of a Zope installation.  This can be either a checkout or a
-  distribution.  If the location has a lib/python subdirectory, it is
-  treated as a distribution, otherwise, it must have a src
-  subdirectory and will be treated as a checkout. This option defaults
-  to "zope3".  And if location is empty, the application will run solely
-  from eggs.
-
 site.zcml
   The contents of site.zcml.
 
@@ -38,14 +29,9 @@
   The names of one or more eggs, with their dependencies that should
   be included in the Python path of the generated scripts.
 
-Let's look at an example.  We'll make a faux zope installation:
 
-    >>> zope3 = tmpdir('zope3')
-    >>> mkdir(zope3, 'src')
+Lets define some (bogus) eggs that we can use in our application:
 
-We'll also define some (bogus) eggs that we can use in our
-application:
-
     >>> mkdir('demo1')
     >>> write('demo1', 'setup.py',
     ... '''
@@ -60,7 +46,95 @@
     ... setup(name = 'demo2', install_requires='demo1')
     ... ''')
 
+We'll create a buildout.cfg file that defines our application:
 
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo2" />
+    ...             <principal
+    ...                 id="zope.manager"
+    ...                 title="Manager"
+    ...                 login="jim"
+    ...                 password_manager="SHA1"
+    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
+    ...                 />
+    ...             <grant
+    ...                 role="zope.Manager"
+    ...                 principal="zope.manager"
+    ...                 />
+    ... eggs = demo2
+    ... ''' % globals())
+
+Now, Let's run the buildout and see what we get:
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/sample-buildout/demo1'
+    Develop: '/sample-buildout/demo2'
+    Installing myapp.
+    Generated script '/sample-buildout/parts/myapp/runzope'.
+    Generated script '/sample-buildout/parts/myapp/debugzope'.
+
+The runzope script runs the Web server:
+
+    >>> cat('parts', 'myapp', 'runzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      ]
+    <BLANKLINE>
+    import zope.app.twisted.main
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.app.twisted.main.main()
+
+Here, unlike the above example the location path is not included
+in sys.path .  Similarly debugzope script is also changed:
+
+    >>> cat('parts', 'myapp', 'debugzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug()
+
+
+Building Zope 3 Applications (from Zope 3 checkouts/tarballs)
+=============================================================
+
+The 'app' recipe works much like the 'application' recipe.  It takes
+the same configuration options plus the following one:
+
+zope3
+  The name of a section defining a location option that gives the
+  location of a Zope installation.  This can be either a checkout or a
+  distribution.  If the location has a lib/python subdirectory, it is
+  treated as a distribution, otherwise, it must have a src
+  subdirectory and will be treated as a checkout. This option defaults
+  to "zope3".  And if location is empty, the application will run solely
+  from eggs.
+
+Let's look at an example.  We'll make a faux zope installation:
+
+    >>> zope3 = tmpdir('zope3')
+    >>> mkdir(zope3, 'src')
+
 Now we'll create a buildout.cfg file that defines our application:
 
     >>> write('buildout.cfg',
@@ -100,6 +174,7 @@
     >>> print system(join('bin', 'buildout')),
     Develop: '/sample-buildout/demo1'
     Develop: '/sample-buildout/demo2'
+    Uninstalling myapp.
     Installing myapp.
     Generated script '/sample-buildout/parts/myapp/runzope'.
     Generated script '/sample-buildout/parts/myapp/debugzope'.
@@ -312,84 +387,6 @@
         zope.app.server.main.main()
 
 
-Run Application Solely from Eggs
---------------------------------
-
-To run a Zope 3 application solely from eggs, value of location in
-zope3 section should be set to empty.  Now we'll create a buildout.cfg
-file that defines our application with an empty location for zope3:
-
-    >>> write('buildout.cfg',
-    ... '''
-    ... [buildout]
-    ... develop = demo1 demo2
-    ... parts = myapp
-    ...
-    ... [zope3]
-    ... location =
-    ...
-    ... [myapp]
-    ... recipe = zc.zope3recipes:app
-    ... site.zcml = <include package="demo2" />
-    ...             <principal
-    ...                 id="zope.manager"
-    ...                 title="Manager"
-    ...                 login="jim"
-    ...                 password_manager="SHA1"
-    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
-    ...                 />
-    ...             <grant
-    ...                 role="zope.Manager"
-    ...                 principal="zope.manager"
-    ...                 />
-    ... eggs = demo2
-    ... ''' % globals())
-
-Now, Let's run the buildout and see what we get:
-
-    >>> print system(join('bin', 'buildout')),
-    Develop: '/sample-buildout/demo1'
-    Develop: '/sample-buildout/demo2'
-    Uninstalling myapp.
-    Installing myapp.
-    Generated script '/sample-buildout/parts/myapp/runzope'.
-    Generated script '/sample-buildout/parts/myapp/debugzope'.
-
-The runzope script runs the Web server:
-
-    >>> cat('parts', 'myapp', 'runzope')
-    #!/usr/local/bin/python2.4
-    <BLANKLINE>
-    import sys
-    sys.path[0:0] = [
-      '/sample-buildout/demo2',
-      '/sample-buildout/demo1',
-      ]
-    <BLANKLINE>
-    import zope.app.twisted.main
-    <BLANKLINE>
-    if __name__ == '__main__':
-        zope.app.twisted.main.main()
-
-Here, unlike the above example the location path is not included
-in sys.path .  Similarly debugzope script is also changed:
-
-    >>> cat('parts', 'myapp', 'debugzope')
-    #!/usr/local/bin/python2.4
-    <BLANKLINE>
-    import sys
-    sys.path[0:0] = [
-      '/sample-buildout/demo2',
-      '/sample-buildout/demo1',
-      '/zope3recipes',
-      ]
-    <BLANKLINE>
-    import zc.zope3recipes.debugzope
-    <BLANKLINE>
-    if __name__ == '__main__':
-        zc.zope3recipes.debugzope.debug()
-
-
 Legacy Functional Testing Support
 ---------------------------------
 

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2007-07-14 14:16:07 UTC (rev 77928)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2007-07-14 15:02:54 UTC (rev 77929)
@@ -30,9 +30,8 @@
     'zserver': ('zope.app.server.main',  'WSGI-HTTP'),
     }
 
-
-class App:
-
+class Application(object):
+    
     def __init__(self, buildout, name, options):
         self.name, self.options = name, options
 
@@ -41,13 +40,6 @@
             self.name,
             )
 
-        location = buildout[options.get('zope3', 'zope3')]['location']
-        if location:
-            options['zope3-location'] = os.path.join(
-                buildout['buildout']['directory'],
-                location,
-                )
-
         options['servers'] = options.get('servers', 'twisted')
         if options['servers'] not in server_types:
             raise ValueError(
@@ -59,56 +51,31 @@
     def install(self):
         options = self.options
 
-        try:
-            z3path = options['zope3-location']
-        except KeyError:
-            path = ''
-        else:
-            if not os.path.exists(z3path):
-                logger.error("The directory, %r, doesn't exist." % z3path)
-                raise zc.buildout.UserError("No directory:", z3path)
-
-            path = os.path.join(z3path, 'lib', 'python')
-            if not os.path.exists(path):
-                path = os.path.join(z3path, 'src')
-                if not os.path.exists(path):
-                    logger.error(
-                        "The directory, %r, isn't a valid checkout or release."
-                        % z3)
-                    raise zc.buildout.UserError(
-                        "Invalid Zope 3 installation:", z3path)
-
         dest = options['location']
         if not os.path.exists(dest):
             os.mkdir(dest)
             created = True
         else:
             created = False
-            
+
         try:
             open(os.path.join(dest, 'site.zcml'), 'w').write(
                 site_zcml_template % self.options['site.zcml']
                 )
 
-            extra = options.get('extra-paths')
-            if extra:
-                extra += '\n' + path
-            else:
-                extra = path
-            options['extra-paths'] = extra
-
             self.egg.install()
             requirements, ws = self.egg.working_set()
 
             # install subprograms and ctl scripts
             server_module = server_types[options['servers']][0]
+            extra_paths = options.get('extra-paths', '')
             zc.buildout.easy_install.scripts(
                 [('runzope', server_module, 'main')],
                 ws, options['executable'], dest,
-                extra_paths = options['extra-paths'].split(),
+                extra_paths = extra_paths.split(),
                 )
 
-            options['extra-paths'] = extra + '\n' + this_loc
+            options['extra-paths'] = extra_paths + '\n' + this_loc
 
             zc.buildout.easy_install.scripts(
                 [('debugzope', 'zc.zope3recipes.debugzope', 'debug')],
@@ -129,11 +96,51 @@
             if created:
                 shutil.rmtree(dest)
             raise
-        
+
         return dest
 
-    update = install
+    def update(self):
+        self.install()
 
+class App(Application):
+
+    def __init__(self, buildout, name, options):
+        super(App, self).__init__(buildout, name, options)
+
+        location = buildout[options.get('zope3', 'zope3')]['location']
+        if location:
+            options['zope3-location'] = os.path.join(
+                buildout['buildout']['directory'],
+                location,
+                )
+
+    def install(self):
+        options = self.options
+        z3path = options.get('zope3-location')
+        if z3path is not None:    
+            if not os.path.exists(z3path):
+                logger.error("The directory, %r, doesn't exist." % z3path)
+                raise zc.buildout.UserError("No directory:", z3path)
+
+            path = os.path.join(z3path, 'lib', 'python')
+            if not os.path.exists(path):
+                path = os.path.join(z3path, 'src')
+                if not os.path.exists(path):
+                    logger.error(
+                        "The directory, %r, isn't a valid checkout or release."
+                        % z3)
+                    raise zc.buildout.UserError(
+                        "Invalid Zope 3 installation:", z3path)
+
+            extra = options.get('extra-paths')
+            if extra:
+                extra += '\n' + path
+            else:
+                extra = path
+            options['extra-paths'] = extra
+
+        return super(App, self).install()
+
 site_zcml_template = """\
 <configure xmlns='http://namespaces.zope.org/zope'
            xmlns:meta="http://namespaces.zope.org/meta"



More information about the Checkins mailing list