[Checkins] SVN: zc.recipe.zope3instance/trunk/ initial version

Jim Fulton jim at zope.com
Thu Jun 29 06:37:40 EDT 2006


Log message for revision 68903:
  initial version

Changed:
  A   zc.recipe.zope3instance/trunk/README.txt
  A   zc.recipe.zope3instance/trunk/setup.cfg
  A   zc.recipe.zope3instance/trunk/setup.py
  A   zc.recipe.zope3instance/trunk/src/
  A   zc.recipe.zope3instance/trunk/src/zc/
  A   zc.recipe.zope3instance/trunk/src/zc/__init__.py
  A   zc.recipe.zope3instance/trunk/src/zc/recipe/
  A   zc.recipe.zope3instance/trunk/src/zc/recipe/__init__.py
  A   zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/
  A   zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/__init__.py

-=-
Added: zc.recipe.zope3instance/trunk/README.txt
===================================================================
--- zc.recipe.zope3instance/trunk/README.txt	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/README.txt	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,83 @@
+Recipe for createing a Zope 3 instance
+======================================
+
+This recipe takes the following options:
+
+zope3 
+   The name of a section providing a Zope 3 installation definition.
+   This defaults to zope3.  The section is required to have a 
+   location option giving the location of the installation.  This
+   could be a section used to install a part, like a Zope 3 checkout,
+   or simply a section with a location option pointing to an existing
+   install. 
+
+database
+   The name of a section defining a zconfig option that has a zodb
+   section.
+
+user
+   The user name and password for manager user
+
+distribution
+   One or more requirements for distributions to be included.
+
+   THIS WILL SOON BE RENAMED TO EGGS
+
+zcml
+
+   If specified, provides the list of package ZCML files to include in
+   the instance's package includes and their order.
+
+   By default, the ZCML files normally included in package-includes
+   are ommitted.  To includes these, include '*' in the list of
+   includes.
+
+   Each entry is a package name with an optional include type and file
+   name.  An package name can be optionally followed by a ':' and a
+   file name within the package.  The default file name is
+   configure.zcml.  The string '-meta' can be included between the
+   file name and the package name. If so, then the default file name
+   is meta.zcml and the include will be treated as a meta include.
+   Similarly for '-overrides'. For example, the include::
+
+      foo.bar
+
+   Causes the file named NNN-foo.bar-configure.zcml to be inserted
+   into package-includes containing:
+
+      <include package="foo.bar" file="configure.zcml" />
+
+   where NNN is a 3-digit number computed from the order if the entry
+   in the zcml option.
+
+   The include:
+
+      foo.bar-meta
+
+   Causes the file named NNN-foo.bar-meta.zcml to be inserted
+   into package-includes containing:
+
+      <include package="foo.bar" file="meta.zcml" />
+
+   The include:
+
+      foo.bar-overrides:x.zcml
+
+   Causes the file named NNN-foo.bar-overrides.zcml to be inserted
+   into package-includes containing:
+
+      <include package="foo.bar" file="x.zcml" />
+
+      
+To do
+-----
+
+- Need tests
+
+- Hopefully, for Zope 3.4, we'll be able to make the instance-creation
+  process more modular, which will allow a cleaner implementation for
+  this recipe.
+
+- Support for multiple storages
+
+- Support for more configuration options.


Property changes on: zc.recipe.zope3instance/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zc.recipe.zope3instance/trunk/setup.cfg
===================================================================
--- zc.recipe.zope3instance/trunk/setup.cfg	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/setup.cfg	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = .dev
+tag_svn_revision = 1


Property changes on: zc.recipe.zope3instance/trunk/setup.cfg
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zc.recipe.zope3instance/trunk/setup.py
===================================================================
--- zc.recipe.zope3instance/trunk/setup.py	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/setup.py	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,23 @@
+from setuptools import setup, find_packages
+
+name = "zc.recipe.zope3instance"
+setup(
+    name = name,
+    version = "1.0",
+    author = "Jim Fulton",
+    author_email = "jim at zope.com",
+    description = "ZC Buildout recipe for defining a Zope 3 instance",
+    long_description = open('README.txt').read(),
+    license = "ZPL 2.1",
+    keywords = "zope3 buildout",
+    url='http://svn.zope.org/'+name,
+
+    packages = find_packages('src'),
+    include_package_data = True,
+    package_dir = {'':'src'},
+    namespace_packages = ['zc', 'zc.recipe'],
+    install_requires = ['zc.buildout', 'zope.testing', 'setuptools',
+                        'zc.recipe.egg'],
+    dependency_links = ['http://download.zope.org/distribution/'],
+    entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+    )


Property changes on: zc.recipe.zope3instance/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.recipe.zope3instance/trunk/src/zc/__init__.py
===================================================================
--- zc.recipe.zope3instance/trunk/src/zc/__init__.py	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/src/zc/__init__.py	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)


Property changes on: zc.recipe.zope3instance/trunk/src/zc/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.recipe.zope3instance/trunk/src/zc/recipe/__init__.py
===================================================================
--- zc.recipe.zope3instance/trunk/src/zc/recipe/__init__.py	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/src/zc/recipe/__init__.py	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)


Property changes on: zc.recipe.zope3instance/trunk/src/zc/recipe/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/__init__.py
===================================================================
--- zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/__init__.py	2006-06-29 08:45:54 UTC (rev 68902)
+++ zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/__init__.py	2006-06-29 10:37:40 UTC (rev 68903)
@@ -0,0 +1,145 @@
+import os, re, shutil
+import zc.buildout
+import zc.recipe.egg
+
+class Recipe(zc.recipe.egg.Egg):
+    # Need to think about the inheritence interface
+    # it *is* reasonable to think about instances as an
+    # extension of the basic egg/script-generation model.
+
+    def __init__(self, buildout, name, options):
+        zc.recipe.egg.Egg.__init__(self, buildout, name, options)
+
+        options['zope3'] = options.get('zope3', 'zope3')
+        options['database-config'] = buildout[options['database']]['zconfig']
+        python = buildout['buildout']['python']
+        options['zope3-directory'] = buildout[options['zope3']]['location']
+        options['location'] = os.path.join(
+            buildout['buildout']['parts-directory'],
+            self.name,
+            )
+        options['scripts'] = '' # suppress script generation.
+
+    def install(self):
+        
+        options = self.options
+        location = options['location']
+        if os.path.exists(location):
+            return location
+
+        # Gather information on extra distros. We should be able to
+        # inherit the next 2 statements, but Egg doesn't provide a
+        # subclassing api
+        
+        distributions = [
+            r.strip()
+            for r in options.get('distribution', self.name).split('\n')
+            if r.strip()
+            ]
+
+        if self.buildout['buildout'].get('offline') == 'true':
+            ws = zc.buildout.easy_install.working_set(
+                distributions, options['executable'],
+                [options['_d'], options['_e']]
+                )
+        else:
+            ws = zc.buildout.easy_install.install(
+                distributions, options['_e'],
+                links = self.links,
+                index = self.index, 
+                executable = options['executable'],
+                always_unzip=options.get('unzip') == 'true',
+                path=[options['_d']]
+                )
+        
+        # What follows is a bit of a hack because the instance-setup mechanism
+        # is a bit monolithic.  We'll run mkzopeinstabce and then we'll
+        # patch the result.  A better approach might be to provide independent
+        # instance-creation logic, but this raises lots of issues that
+        # need to be stored out first.
+        mkzopeinstance = os.path.join(options['zope3-directory'],
+                                      'bin', 'mkzopeinstance')
+
+        assert os.spawnl(
+            os.P_WAIT, options['executable'], options['executable'],
+            mkzopeinstance, '-d', location, '-u', options['user'],
+            '--non-interactive',
+            ) == 0
+
+        try:
+
+            # Now, patch the zodb option in zope.conf
+            zope_conf_path = os.path.join(location, 'etc', 'zope.conf')
+            zope_conf = open(zope_conf_path).read()
+            zope_conf = (
+                zope_conf[:zope_conf.find('<zodb>')]
+                +
+                options['database-config']
+                +
+                zope_conf[zope_conf.find('</zodb>')+7:]
+                )
+            open(zope_conf_path, 'w').write(zope_conf)
+
+            # Patch extra paths into binaries
+            path = "\n        '" + "',\n        '".join([
+                dist.location for dist in ws]) + "'\n        "
+            for script_name in 'runzope', 'debugzope', 'scriptzope':
+                script_path = os.path.join(location, 'bin', script_name)
+                script = open(script_path).read()
+                # don't look :/
+                script = script.replace(
+                    'sys.path[:] = [',
+                    'sys.path[:] = ['+path+'] + ['
+                    )
+                open(script_path, 'w').write(script)
+
+            # finally, add zcml files to package-includes
+            zcml = options.get('zcml')
+            if zcml:
+                includes_path = os.path.join(
+                    location, 'etc', 'package-includes')
+                zcml = zcml.split()
+                if '*' in zcml:
+                    zcml.remove('*')
+                else:
+                    shutil.rmtree(includes_path)
+                    os.mkdir(includes_path)
+
+                n = 0
+                package_match = re.compile('\w+([.]\w+)*$').match
+                for package in zcml:
+                    n += 1
+                    orig = package
+                    if ':' in package:
+                        package, filename = package.split(':')
+                    else:
+                        filename = None
+
+                    if '-' in package:
+                        package, suff = package.split('-')
+                        if suff not in ('configure', 'meta', 'overrides'):
+                            raise ValueError('Invalid zcml', orig)
+                    else:
+                        suff = 'configure'
+
+                    if filename is None:
+                        filename = suff + '.zcml'
+
+                    if not package_match(package):
+                        raise ValueError('Invalid zcml', orig)
+
+                    path = os.path.join(
+                        includes_path,
+                        "%3.3d-%s-%s.zcml" % (n, package, suff),
+                        )
+                    open(path, 'w').write(
+                        '<include package="%s" file="%s" />\n'
+                        % (package, filename)
+                        )
+                    
+        except:
+            # clean up
+            shutil.rmtree(location)
+            raise
+        
+        return location


Property changes on: zc.recipe.zope3instance/trunk/src/zc/recipe/zope3instance/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list