[Checkins] SVN: zc.zope3recipes/dev/ Added an extends option to the instance recipe to allow an instance to

Jim Fulton jim at zope.com
Thu Feb 15 18:53:57 EST 2007


Log message for revision 72644:
  Added an extends option to the instance recipe to allow an instance to
  more easily reuse options from another part.
  
  Fixed a bug in some error reporting logic.
  

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

-=-
Modified: zc.zope3recipes/dev/setup.py
===================================================================
--- zc.zope3recipes/dev/setup.py	2007-02-15 21:18:45 UTC (rev 72643)
+++ zc.zope3recipes/dev/setup.py	2007-02-15 23:53:56 UTC (rev 72644)
@@ -3,7 +3,7 @@
 name = "zc.zope3recipes"
 setup(
     name = name,
-    version = "0.1a1",
+    version = "0.2",
     author = "Jim Fulton",
     author_email = "jim at zope.com",
     description = "ZC Buildout recipe for defining Zope 3 applications",

Modified: zc.zope3recipes/dev/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/dev/zc/zope3recipes/README.txt	2007-02-15 21:18:45 UTC (rev 72643)
+++ zc.zope3recipes/dev/zc/zope3recipes/README.txt	2007-02-15 23:53:56 UTC (rev 72644)
@@ -1013,3 +1013,108 @@
       </logfile>
     <BLANKLINE>
     </eventlog>
+
+Defining multiple similar instances
+-----------------------------------
+
+Often you want to define multiple instances that differ only by one or
+two options (e.g. an address).  The extends option lets you name a
+section from which default options should be loaded.  Any options in
+the source section not defined in the extending section are added to
+the extending section.
+
+Let's update our buildout to add a new instance:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1 demo2
+    ... parts = instance instance2
+    ... 
+    ... [zope3]
+    ... location = %(zope3)s
+    ...
+    ... [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
+    ...
+    ... [instance]
+    ... recipe = zc.zope3recipes:instance
+    ... application = myapp
+    ... zope.conf = ${database:zconfig}
+    ... address = 8081
+    ... deployment = myapp-run
+    ...
+    ... [instance2]
+    ... recipe = zc.zope3recipes:instance
+    ... extends = instance
+    ... address = 8082
+    ...
+    ... [database]
+    ... recipe = zc.recipe.filestorage
+    ...
+    ... [myapp-run]
+    ... etc-directory = %(root)s/etc/myapp-run
+    ... rc-directory = %(root)s/etc/init.d
+    ... log-directory = %(root)s/var/log/myapp-run
+    ... run-directory = %(root)s/var/run/myapp-run
+    ... user = zope
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    buildout: Develop: /sample-buildout/demo1
+    buildout: Develop: /sample-buildout/demo2
+    buildout: Updating database
+    buildout: Updating myapp
+    buildout: Updating instance
+    buildout: Installing instance2
+
+Now, we have the new instance configuration files:
+
+    >>> ls(root, 'etc', 'myapp-run')
+    -  instance-zdaemon.conf
+    -  instance-zope.conf
+    -  instance2-zdaemon.conf
+    -  instance2-zope.conf
+
+    >>> cat(root, 'etc', 'myapp-run', 'instance2-zope.conf')
+    site-definition /sample-buildout/parts/myapp/site.zcml
+    <BLANKLINE>
+    <zodb>
+      <filestorage>
+        path /sample-buildout/parts/database/Data.fs
+      </filestorage>
+    <BLANKLINE>
+    </zodb>
+    <BLANKLINE>
+    <server>
+      address 8082
+      type HTTP
+    </server>
+    <BLANKLINE>
+    <accesslog>
+      <logfile>
+        path /root/var/log/myapp-run/instance2-access.log
+      </logfile>
+    <BLANKLINE>
+    </accesslog>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        formatter zope.exceptions.log.Formatter
+        path STDOUT
+      </logfile>
+    <BLANKLINE>
+    </eventlog>

Modified: zc.zope3recipes/dev/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/dev/zc/zope3recipes/recipes.py	2007-02-15 21:18:45 UTC (rev 72643)
+++ zc.zope3recipes/dev/zc/zope3recipes/recipes.py	2007-02-15 23:53:56 UTC (rev 72644)
@@ -129,6 +129,12 @@
     def __init__(self, buildout, name, options):
         self.name, self.options = name, options
 
+        for section in options.get('extends', '').split():
+            options.update(
+                [(k, v) for (k, v) in buildout[section].items()
+                 if k not in options
+                 ])
+
         options['application-location'] = buildout[options['application']
                                                    ]['location']
 
@@ -150,12 +156,8 @@
                 self.name,
                 )
             
-            
-
     def install(self):
         options = self.options
-
-
         run_directory = options['run-directory']
         deployment = self.deployment
         if deployment:
@@ -282,9 +284,9 @@
 
         except:
             for f in creating:
-                if os.path.is_dir(f):
+                if os.path.isdir(f):
                     shutil.rmtree(f)
-                else:
+                elif os.path.exists(f):
                     os.remove(f)
             raise
 

Modified: zc.zope3recipes/dev/zc/zope3recipes/tests.py
===================================================================
--- zc.zope3recipes/dev/zc/zope3recipes/tests.py	2007-02-15 21:18:45 UTC (rev 72643)
+++ zc.zope3recipes/dev/zc/zope3recipes/tests.py	2007-02-15 23:53:56 UTC (rev 72644)
@@ -85,6 +85,30 @@
 
 """
 
+def test_sane_errors_from_recipe():
+    """
+There was a bug in the recipe error handling that caused errors to be hidden
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = instance
+    ...
+    ... [myapp]
+    ... location = foo
+    ...
+    ... [instance]
+    ... recipe = zc.zope3recipes:instance
+    ... application = myapp
+    ... zope.conf = 
+    ... ''')
+
+    >>> print system(join('bin', 'buildout')),
+    Couldn't find index page for 'zc.recipe.egg' (maybe misspelled?)
+    buildout: Installing instance
+    Error: No database sections have been defined.
+    """
+
 def setUp(test):
     zc.buildout.testing.buildoutSetUp(test)
     zc.buildout.testing.install_develop('zc.zope3recipes', test)



More information about the Checkins mailing list