[Checkins] SVN: zc.zope3recipes/trunk/ add support for script initialization code

Fred Drake fdrake at gmail.com
Wed Nov 24 12:22:02 EST 2010


Log message for revision 118571:
  add support for script initialization code

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

-=-
Modified: zc.zope3recipes/trunk/README.txt
===================================================================
--- zc.zope3recipes/trunk/README.txt	2010-11-24 17:17:30 UTC (rev 118570)
+++ zc.zope3recipes/trunk/README.txt	2010-11-24 17:22:01 UTC (rev 118571)
@@ -18,6 +18,13 @@
 ********
 
 ===================
+0.13.0 (2010/11/24)
+===================
+
+- Support inserting additional code into the runzope & debugzope scripts
+  using ``initialization`` and ``debug-initialization``.
+
+===================
 0.12.0 (2010/11/22)
 ===================
 

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2010-11-24 17:17:30 UTC (rev 118570)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2010-11-24 17:22:01 UTC (rev 118571)
@@ -100,7 +100,7 @@
         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:
+in ``sys.path``.  Similarly debugzope script is also changed:
 
     >>> cat('parts', 'myapp', 'debugzope')
     #!/usr/local/bin/python2.4
@@ -120,7 +120,187 @@
     if __name__ == '__main__':
         zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
 
+The ``initialization`` setting can be used to provide a bit of
+additional code that will be included in the runzope and debugzope
+scripts just before the server's main function is called:
 
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo2" />
+    ... eggs = demo2
+    ... initialization =
+    ...     print "Starting application server."
+    ... ''')
+
+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 and debugzope scripts now include the additional code just
+before server is started:
+
+    >>> cat('parts', 'myapp', 'runzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      ]
+    <BLANKLINE>
+    print "Starting application server."
+    <BLANKLINE>
+    import zope.app.twisted.main
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.app.twisted.main.main()
+
+    >>> cat('parts', 'myapp', 'debugzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    print "Starting application server."
+    import zope.app.twisted.main
+    <BLANKLINE>
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
+
+If the additional initialization for debugzope needs to be different
+from that of runzope, the ``debug-initialization`` setting can be used.
+If set, that is used for debugzope *instead* of the value of
+``initialization``.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo2" />
+    ... eggs = demo2
+    ... initialization =
+    ...     print "Starting application server."
+    ... debug-initialization =
+    ...     print "Starting debugging interaction."
+    ... ''')
+
+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'.
+
+    >>> cat('parts', 'myapp', 'debugzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      '/zope3recipes',
+      ]
+    <BLANKLINE>
+    print "Starting debugging interaction."
+    import zope.app.twisted.main
+    <BLANKLINE>
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
+
+The runzope script still uses the ``initialization`` setting::
+
+    >>> cat('parts', 'myapp', 'runzope')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/demo2',
+      '/sample-buildout/demo1',
+      ]
+    <BLANKLINE>
+    print "Starting application server."
+    <BLANKLINE>
+    import zope.app.twisted.main
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.app.twisted.main.main()
+
+Setting ``debug-initialization`` to an empty string suppresses the
+``initialization`` setting for the debugzope script:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = myapp
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo2" />
+    ... eggs = demo2
+    ... initialization =
+    ...     print "Starting application server."
+    ... debug-initialization =
+    ... ''')
+
+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'.
+
+    >>> 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 zope.app.twisted.main
+    <BLANKLINE>
+    <BLANKLINE>
+    import zc.zope3recipes.debugzope
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zc.zope3recipes.debugzope.debug(main_module=zope.app.twisted.main)
+
+
 Relative paths
 --------------
 

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2010-11-24 17:17:30 UTC (rev 118570)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2010-11-24 17:22:01 UTC (rev 118571)
@@ -75,16 +75,25 @@
             # install subprograms and ctl scripts
             server_module = server_types[options['servers']][0]
             extra_paths = options.get('extra-paths', '')
+            initialization = options.get('initialization') or ''
             zc.buildout.easy_install.scripts(
                 [('runzope', server_module, 'main')],
                 ws, options['executable'], dest,
-                extra_paths = extra_paths.split(),
+                extra_paths=extra_paths.split(),
+                initialization=initialization,
                 relative_paths=self.egg._relative_paths,
                 )
 
             options['extra-paths'] = extra_paths + '\n' + this_loc
 
-            initialization = 'import %s\n' % server_module
+            initialization = options.get('debug-initialization')
+            if initialization is None:
+                initialization = options.get('initialization')
+            if initialization:
+                initialization += '\n'
+            else:
+                initialization = ''
+            initialization += 'import %s\n' % server_module
             arguments = 'main_module=%s' % server_module
             zc.buildout.easy_install.scripts(
                 [('debugzope', 'zc.zope3recipes.debugzope', 'debug')],
@@ -141,7 +150,7 @@
                 if not os.path.exists(path):
                     logger.error(
                         "The directory, %r, isn't a valid checkout or release."
-                        % z3)
+                        % z3path)
                     raise zc.buildout.UserError(
                         "Invalid Zope 3 installation:", z3path)
 



More information about the checkins mailing list