[Checkins] SVN: zc.zope3recipes/trunk/ add a separate zopeconf recipe that produces

Fred Drake fdrake at gmail.com
Mon Dec 12 03:02:49 UTC 2011


Log message for revision 123695:
  add a separate zopeconf recipe that produces
  nicely-formatted zope.conf files without generating a full instance

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	2011-12-11 23:53:56 UTC (rev 123694)
+++ zc.zope3recipes/trunk/setup.py	2011-12-12 03:02:48 UTC (rev 123695)
@@ -39,7 +39,8 @@
              'application = %s.recipes:Application' % name,
              'app = %s.recipes:App' % name,
              'instance = %s.recipes:Instance' % name,
-             'offline = %s.recipes:Offline' %name,
+             'offline = %s.recipes:Offline' % name,
+             'zopeconf = %s.recipes:ZopeConf' % name,
              ]
         },
     extras_require = dict(

Modified: zc.zope3recipes/trunk/zc/zope3recipes/README.txt
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2011-12-11 23:53:56 UTC (rev 123694)
+++ zc.zope3recipes/trunk/zc/zope3recipes/README.txt	2011-12-12 03:02:48 UTC (rev 123695)
@@ -2466,6 +2466,193 @@
             )
 
 
+zope.conf recipe
+================
+
+The zope.conf recipe handles filling in the implied bits of a zope.conf
+file that the instance recipe performs, without creating the rest of an
+instance.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1
+    ... parts = some.conf
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo1" />
+    ... eggs = demo1
+    ...
+    ... [some.conf]
+    ... recipe = zc.zope3recipes:zopeconf
+    ... application = myapp
+    ... text =
+    ...     <zodb>
+    ...       <zeoclient>
+    ...         server 127.0.0.1:8001
+    ...       </zeoclient>
+    ...     </zodb>
+    ...
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/sample-buildout/demo1'
+    Uninstalling instance.
+    Uninstalling myapp.
+    Uninstalling database.
+    Installing myapp.
+    Generated script '/sample-buildout/parts/myapp/runzope'.
+    Generated script '/sample-buildout/parts/myapp/debugzope'.
+    Installing some.conf.
+
+    >>> cat('parts', 'some.conf')
+    site-definition /sample-buildout/parts/myapp/site.zcml
+    <BLANKLINE>
+    <zodb>
+      <zeoclient>
+        server 127.0.0.1:8001
+      </zeoclient>
+    </zodb>
+    <BLANKLINE>
+    <server>
+      address 8080
+      type HTTP
+    </server>
+    <BLANKLINE>
+    <accesslog>
+      <logfile>
+        path /sample-buildout/parts/some-access.log
+      </logfile>
+    </accesslog>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        formatter zope.exceptions.log.Formatter
+        path STDOUT
+      </logfile>
+    </eventlog>
+
+We can specify the location of the access log directly in the part:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1
+    ... parts = some.conf
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo1" />
+    ... eggs = demo1
+    ...
+    ... [some.conf]
+    ... recipe = zc.zope3recipes:zopeconf
+    ... application = myapp
+    ... access-log = ${buildout:directory}/access.log
+    ... text =
+    ...     <zodb>
+    ...       <zeoclient>
+    ...         server 127.0.0.1:8001
+    ...       </zeoclient>
+    ...     </zodb>
+    ...
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/tmp/tmp2eRRw1buildoutSetUp/_TEST_/sample-buildout/demo1'
+    Uninstalling some.conf.
+    Updating myapp.
+    Installing some.conf.
+
+    >>> cat('parts', 'some.conf')
+    site-definition /sample-buildout/parts/myapp/site.zcml
+    <BLANKLINE>
+    <zodb>
+      <zeoclient>
+        server 127.0.0.1:8001
+      </zeoclient>
+    </zodb>
+    <BLANKLINE>
+    <server>
+      address 8080
+      type HTTP
+    </server>
+    <BLANKLINE>
+    <accesslog>
+      <logfile>
+        path /sample-buildout/access.log
+      </logfile>
+    </accesslog>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        formatter zope.exceptions.log.Formatter
+        path STDOUT
+      </logfile>
+    </eventlog>
+
+The address of the server can be set using the "address" setting:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = demo1
+    ... parts = some.conf
+    ...
+    ... [myapp]
+    ... recipe = zc.zope3recipes:application
+    ... site.zcml = <include package="demo1" />
+    ... eggs = demo1
+    ...
+    ... [some.conf]
+    ... recipe = zc.zope3recipes:zopeconf
+    ... address = 4242
+    ... application = myapp
+    ... text =
+    ...     <zodb>
+    ...       <zeoclient>
+    ...         server 127.0.0.1:8001
+    ...       </zeoclient>
+    ...     </zodb>
+    ...
+    ... ''' % globals())
+
+    >>> print system(join('bin', 'buildout')),
+    Develop: '/tmp/tmp2eRRw1buildoutSetUp/_TEST_/sample-buildout/demo1'
+    Uninstalling some.conf.
+    Updating myapp.
+    Installing some.conf.
+
+    >>> cat('parts', 'some.conf')
+    site-definition /sample-buildout/parts/myapp/site.zcml
+    <BLANKLINE>
+    <zodb>
+      <zeoclient>
+        server 127.0.0.1:8001
+      </zeoclient>
+    </zodb>
+    <BLANKLINE>
+    <server>
+      address 4242
+      type HTTP
+    </server>
+    <BLANKLINE>
+    <accesslog>
+      <logfile>
+        path /sample-buildout/parts/some-access.log
+      </logfile>
+    </accesslog>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        formatter zope.exceptions.log.Formatter
+        path STDOUT
+      </logfile>
+    </eventlog>
+
+
+
 Offline recipe
 ==============
 
@@ -2537,9 +2724,8 @@
     >>> print system(join('bin', 'buildout')),
     Develop: '/sample-buildout/demo1'
     Develop: '/sample-buildout/demo2'
-    Uninstalling instance.
+    Uninstalling some.conf.
     Uninstalling myapp.
-    Uninstalling database.
     Installing myapp.
     Generated script '/sample-buildout/parts/myapp/runzope'.
     Generated script '/sample-buildout/parts/myapp/debugzope'.

Modified: zc.zope3recipes/trunk/zc/zope3recipes/recipes.py
===================================================================
--- zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2011-12-11 23:53:56 UTC (rev 123694)
+++ zc.zope3recipes/trunk/zc/zope3recipes/recipes.py	2011-12-12 03:02:48 UTC (rev 123695)
@@ -36,6 +36,7 @@
 if sys.platform[:3].lower() == "win":
     WIN = True
 
+
 class Application(object):
 
     def __init__(self, buildout, name, options):
@@ -504,30 +505,124 @@
 """
 
 
-class Offline(object):
+class SupportingBase(object):
 
     def __init__(self, buildout, name, options):
-        self.name, self.options = name, options
+        self.options = options
+        self.name = name
         deployment = options.get("deployment")
         if deployment:
             deployment = buildout[deployment]
-        if deployment is not None and "user" not in options:
-            options["user"] = deployment["user"]
+        self.deployment = deployment
+        self.app = buildout[options["application"]]
+        options["application-location"] = self.app["location"]
+
+    def update(self):
+        self.install()
+
+
+class ZopeConf(SupportingBase):
+
+    def __init__(self, buildout, name, options):
+        super(ZopeConf, self).__init__(buildout, name, options)
+        if self.deployment:
+            options['run-directory'] = self.deployment['run-directory']
+        else:
+            options['run-directory'] = os.path.join(
+                buildout['buildout']['parts-directory'])
+
+    def install(self):
+        options = self.options
+        run_directory = options['run-directory']
+
+        zope_conf = options.get('text', '')+'\n'
+        zope_conf = ZConfig.schemaless.loadConfigFile(
+            cStringIO.StringIO(zope_conf))
+
+        if "access-log" in options:
+            access_log_name = options["access-log"]
+            access_log_specified = True
+        else:
+            basename = os.path.splitext(self.name)[0]
+            access_log_name = basename+'-access.log'
+            access_log_specified = False
+
+        # access_log_path depends on whether a given name is an absolute
+        # path; this (and the windows case) are handled specially so the
+        # file can be dumped to /dev/null for offline scripts.
+        if (os.path.isabs(access_log_name)
+            or (WIN and access_log_name.upper() == "NUL")):
+            access_log_path = access_log_name
+        elif self.deployment:
+            access_log_path = os.path.join(
+                self.deployment['log-directory'], access_log_name)
+        else:
+            access_log_path = os.path.join(run_directory, access_log_name)
+
+        if self.deployment:
+            zope_conf_path = os.path.join(
+                self.deployment['etc-directory'], self.name)
+        else:
+            zope_conf_path = os.path.join(run_directory, self.name)
+
+        if 'site-definition' not in zope_conf:
+            app_loc = options["application-location"]
+            zope_conf['site-definition'] = [
+                os.path.join(app_loc, 'site.zcml')
+                ]
+
+        server_type = server_types[self.app['servers']][1]
+        for address in options.get('address', '').split():
+            zope_conf.sections.append(
+                ZConfig.schemaless.Section(
+                    'server',
+                    data=dict(type=[server_type], address=[address]))
+                )
+        if not [s for s in zope_conf.sections
+                if ('server' in s.type)]:
+            zope_conf.sections.append(
+                ZConfig.schemaless.Section(
+                    'server',
+                    data=dict(type=[server_type], address=['8080']))
+                )
+
+        if not [s for s in zope_conf.sections if s.type == 'zodb']:
+            raise zc.buildout.UserError(
+                'No database sections have been defined.')
+
+        if not [s for s in zope_conf.sections if s.type == 'accesslog']:
+            zope_conf.sections.append(access_log(access_log_path))
+        elif access_log_specified:
+            # Can't include one and specify the path.
+            raise zc.buildout.UserError(
+                "access log can only be specified once")
+
+        if not [s for s in zope_conf.sections if s.type == 'eventlog']:
+            zope_conf.sections.append(event_log('STDOUT'))
+
+        open(zope_conf_path, 'w').write(str(zope_conf))
+        return [zope_conf_path]
+
+
+class Offline(SupportingBase):
+
+    def __init__(self, buildout, name, options):
+        super(Offline, self).__init__(buildout, name, options)
         if "directory" not in options:
-            if deployment is None:
+            if self.deployment is None:
                 directory = buildout["buildout"]["bin-directory"]
             else:
-                directory = deployment["etc-directory"]
+                directory = self.deployment["etc-directory"]
             options["directory"] = directory
-        options["dest"] = os.path.join(directory, name)
+        if self.deployment is not None and "user" not in options:
+            options["user"] = self.deployment["user"]
+        options["dest"] = os.path.join(options["directory"], name)
         env = options.get("environment")
         if env:
             self.environment = dict(buildout[env])
         else:
             self.environment = {}
-        app = buildout[options["application"]]
-        options["application-location"] = app["location"]
-        options["executable"] = app["executable"]
+        options["executable"] = self.app["executable"]
         zope_conf = buildout[options["zope.conf"]]
         options["zope.conf-location"] =  zope_conf["location"]
         script = options.get("script")
@@ -535,9 +630,6 @@
             script = os.path.join(buildout["buildout"]["directory"], script)
             options["script"] = script
 
-    def update(self):
-        self.install()
-
     def install(self):
         options = self.options
 



More information about the checkins mailing list