[Checkins] SVN: z3c.recipe.dev/ Implemented 2 new recipes,
work in progress...
Roger Ineichen
roger at projekt01.ch
Fri Oct 12 11:47:33 EDT 2007
Log message for revision 80857:
Implemented 2 new recipes, work in progress...
z3c.recipe.app
--------------
A zope start script e.g. the old z3.py
This scrip supports the following files:
- zope.conf
- site.zcml
- principals.zcml
- securitypolicy.zcml
This recipe includes simpler and better windows support
for zope startup.
z3c.recipe.script
-----------------
A script caller including eggs in sys path
Changed:
A z3c.recipe.dev/branches/
A z3c.recipe.dev/tags/
A z3c.recipe.dev/trunk/
A z3c.recipe.dev/trunk/CHANGES.txt
A z3c.recipe.dev/trunk/README.txt
A z3c.recipe.dev/trunk/bootstrap.py
A z3c.recipe.dev/trunk/buildout.cfg
A z3c.recipe.dev/trunk/setup.py
A z3c.recipe.dev/trunk/src/
A z3c.recipe.dev/trunk/src/z3c/
A z3c.recipe.dev/trunk/src/z3c/__init__.py
A z3c.recipe.dev/trunk/src/z3c/recipe/
A z3c.recipe.dev/trunk/src/z3c/recipe/__init__.py
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/__init__.py
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/app.py
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/script.py
A z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py
-=-
Property changes on: z3c.recipe.dev/trunk
___________________________________________________________________
Name: svn:ignore
+ .installed.cfg
bin
parts
develop-eggs
Added: z3c.recipe.dev/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.dev/trunk/CHANGES.txt (rev 0)
+++ z3c.recipe.dev/trunk/CHANGES.txt 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,9 @@
+=======
+CHANGES
+=======
+
+unreleased
+----------
+
+- Initial implementation
+
Property changes on: z3c.recipe.dev/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/README.txt
===================================================================
--- z3c.recipe.dev/trunk/README.txt (rev 0)
+++ z3c.recipe.dev/trunk/README.txt 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,9 @@
+=========================
+Zope 3 development recipe
+=========================
+
+The z3c.recipe.start generates start scripts and configuration files for
+starting a egg based Zope 3 setup.
+
+The z3c.recipe.script generates a hook to a existing python module and allows
+to execute a python method including eggs in sys path.
Property changes on: z3c.recipe.dev/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/bootstrap.py
===================================================================
--- z3c.recipe.dev/trunk/bootstrap.py (rev 0)
+++ z3c.recipe.dev/trunk/bootstrap.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 77225 2007-06-29 09:20:13Z dobe $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+try:
+ import pkg_resources
+except ImportError:
+ ez = {}
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
+
Property changes on: z3c.recipe.dev/trunk/bootstrap.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/buildout.cfg
===================================================================
--- z3c.recipe.dev/trunk/buildout.cfg (rev 0)
+++ z3c.recipe.dev/trunk/buildout.cfg 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,7 @@
+[buildout]
+parts = test
+develop = .
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.recipe.dev [test]
Added: z3c.recipe.dev/trunk/setup.py
===================================================================
--- z3c.recipe.dev/trunk/setup.py (rev 0)
+++ z3c.recipe.dev/trunk/setup.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,64 @@
+import os
+from setuptools import setup, find_packages
+
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+name = "z3c.recipe.dev"
+setup(
+ name = name,
+ version = "0.0.1dev",
+ author = "Roger Ineichen and the Zope Community",
+ author_email = "roger at projekt01.ch",
+ description = "Zope3 development recipes",
+ long_description = (
+ read('README.txt')
+ + '\n' +
+ read('CHANGES.txt')
+ + '\n' +
+ 'Detailed Documentation\n'
+ '**********************\n'
+ + '\n' +
+ read('src', 'z3c', 'recipe', 'dev', 'README.txt')
+ + '\n' +
+ 'Download\n'
+ '**********************\n'
+ ),
+ license = "ZPL 2.1",
+ keywords = "zope3 z3c dev recipe",
+ classifiers = [
+ 'Development Status :: 3 - Alpha',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url = 'http://cheeseshop.python.org/pypi/'+name,
+ packages = find_packages('src'),
+ package_dir = {'':'src'},
+ dependency_links = ['http://download.zope.org/distribution/'],
+ include_package_data = True,
+ namespace_packages = ['z3c', 'z3c.recipe'],
+ extras_require = dict(
+ test = [
+ 'zc.recipe.filestorage',
+ ],
+ ),
+ install_requires = [
+ 'ZConfig >=2.4a5',
+ 'setuptools',
+ 'zc.buildout',
+ 'zc.recipe.egg',
+ 'zope.testing',
+ ],
+ entry_points = {
+ 'zc.buildout': [
+ 'app = %s.app:AppSetup' % name,
+ 'script = %s.script:ScriptSetup' % name,
+ ]
+ },
+)
Property changes on: z3c.recipe.dev/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
+ native
Property changes on: z3c.recipe.dev/trunk/src
___________________________________________________________________
Name: svn:ignore
+ z3c.recipe.dev.egg-info
Added: z3c.recipe.dev/trunk/src/z3c/__init__.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/__init__.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/__init__.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ import pkgutil
+ __path__ = pkgutil.extend_path(__path__, __name__)
Property changes on: z3c.recipe.dev/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/__init__.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/__init__.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/__init__.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -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: z3c.recipe.dev/trunk/src/z3c/recipe/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,305 @@
+=====================
+Z3 development recipe
+=====================
+
+z3c.recipe.start
+----------------
+
+This Zope 3 recipes allows you to define Zope applications.
+
+The 'app' 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 application's zope.conf, site.zcml,
+principals.zcml and securitypolicy.zcml. This configuration files will get
+recreated during each update. Another folder called logs will get created and
+contains the access.log and z3c.log files. This log files doesn't get
+recreated. The start script itself is located in the bin folder and uses
+the configuration files from the relevant parts folder.
+
+
+Options
+*******
+
+The 'app' recipe accepts the following options:
+
+eggs
+ The names of one or more eggs, with their dependencies that should
+ be included in the Python path of the generated scripts.
+
+server
+ The ``zserver`` or ``twisted`` server otpion.
+
+zope.conf
+ The contents of zope.conf.
+
+site.zcml
+ The contents of site.zcml.
+
+principals.zcml
+ The contents of securitypolicy.zcml.
+
+securitypolicy.zcml
+ The contents of securitypolicy.zcml.
+
+site.zcml
+ The contents of site.zcml.
+
+
+Test
+****
+
+Lets define some (bogus) eggs that we can use in our application:
+
+ >>> mkdir('demo1')
+ >>> write('demo1', 'setup.py',
+ ... '''
+ ... from setuptools import setup
+ ... setup(name = 'demo1')
+ ... ''')
+
+ >>> mkdir('demo2')
+ >>> write('demo2', 'setup.py',
+ ... '''
+ ... from setuptools import setup
+ ... 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 var
+ ...
+ ... [myapp]
+ ... recipe = z3c.recipe.dev:app
+ ... eggs = demo2
+ ... z3c.recipe.dev [test]
+ ... server = zserver
+ ... zope.conf = ${var:zconfig}
+ ... <eventlog>
+ ... #level DEBUG
+ ... <logfile>
+ ... path STDOUT
+ ... formatter zope.exceptions.log.Formatter
+ ... </logfile>
+ ... </eventlog>
+ ...
+ ... devmode on
+ ...
+ ... site.zcml =
+ ... <include package="demo1" />
+ ... <include package="demo2" />
+ ...
+ ... principals.zcml =
+ ... <unauthenticatedPrincipal
+ ... id="lovelybooks.anybody"
+ ... title="Unauthenticated User"
+ ... />
+ ...
+ ... <unauthenticatedGroup
+ ... id="zope.Anybody"
+ ... title="Unauthenticated Users"
+ ... />
+ ...
+ ... <authenticatedGroup
+ ... id="zope.Authenticated"
+ ... title="Authenticated Users"
+ ... />
+ ...
+ ... <everybodyGroup
+ ... id="zope.Everybody"
+ ... title="All Users"
+ ... />
+ ...
+ ... <principal
+ ... id="zope.manager"
+ ... title="Manager"
+ ... login="Manager"
+ ... password="password"
+ ... />
+ ...
+ ... <grant
+ ... role="zope.Manager"
+ ... principal="zope.manager"
+ ... />
+ ...
+ ... securitypolicy.zcml =
+ ... <include package="zope.app.securitypolicy" />
+ ...
+ ... <securityPolicy
+ ... component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+ ... />
+ ...
+ ... <role id="zope.Anonymous" title="Everybody"
+ ... description="All users have this role implicitly" />
+ ... <role id="zope.Manager" title="Site Manager" />
+ ... <role id="zope.Member" title="Site Member" />
+ ...
+ ... <!-- Replace the following directive if you don't want public access -->
+ ... <grant permission="zope.View"
+ ... role="zope.Anonymous"
+ ... />
+ ... <grant permission="zope.app.dublincore.view"
+ ... role="zope.Anonymous"
+ ... />
+ ...
+ ... <grantAll role="zope.Manager" />
+ ...
+ ... [var]
+ ... recipe = zc.recipe.filestorage
+ ...
+ ... ''' % 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 var.
+ Installing myapp.
+ Generated script '/sample-buildout/bin/myapp'.
+
+The bin folder contains the start script:
+
+ >>> ls('bin')
+ - buildout-script.py
+ - buildout.exe
+ - myapp-script.py
+ - myapp.exe
+
+The myapp-scrip.py contains the start code for our zope setup:
+
+ >>> cat('bin', 'myapp-script.py')
+ #!C:\Python24\python.exe
+ <BLANKLINE>
+ import sys
+ sys.path[0:0] = [
+ '/sample-buildout/demo2',
+ '/z3c.recipe.dev/trunk/src',
+ '/sample-buildout/eggs/zc.recipe.filestorage-1.0a5-py2.4.egg',
+ '/sample-buildout/eggs/zope.testing-3.5.1-py2.4.egg',
+ '/sample-buildout/eggs/zc.recipe.egg-1.0.0b6-py2.4.egg',
+ '/sample-buildout/eggs/zc.buildout-1.0.0b30-py2.4.egg',
+ '/sample-buildout/eggs/setuptools-0.6c7-py2.4.egg',
+ '/sample-buildout/eggs/zconfig-2.5-py2.4.egg',
+ '/sample-buildout/demo1',
+ ]
+ <BLANKLINE>
+ import os
+ sys.argv[0] = os.path.abspath(sys.argv[0])
+ <BLANKLINE>
+ <BLANKLINE>
+ import zope.app.server.main
+ <BLANKLINE>
+ if __name__ == '__main__':
+ zope.app.server.main.main([
+ '-C', '/sample-buildout/parts/myapp/zope.conf',
+ ]+sys.argv[1:])
+
+And the myapp folder contains the configure files:
+
+ >>> ls('parts', 'myapp')
+ - principals.zcml
+ - securitypolicy.zcml
+ - site.zcml
+ - zope.conf
+
+
+z3c.recipe.script
+-----------------
+
+The script recipe allows us to point to scripts which the recipe will install
+a execute script hook for us. You can use this if you need to run a python
+script which knows about some egg packages.
+
+
+Options
+*******
+
+The 'script' recipe accepts the following options:
+
+eggs
+ The names of one or more eggs, with their dependencies that should
+ be included in the Python path of the generated scripts.
+
+module
+ The ``module`` which contains the ``method`` to be executed.
+
+method
+ The ``method`` which get called from the ``module``.
+
+
+Test
+****
+
+Lets define a egg that we can use in our application:
+
+ >>> mkdir('hello')
+ >>> write('hello', 'setup.py',
+ ... '''
+ ... from setuptools import setup
+ ... setup(name = 'hello')
+ ... ''')
+
+And let's define a python module which we use for our test:
+
+ >>> write('hello', 'helloworld.py',
+ ... """
+ ... def helloWorld():
+ ... print 'Hello World'
+ ... """)
+
+Alos add a __init__ to the hello package:
+
+ >>> write('hello', '__init__.py', '#make package')
+
+We'll create a buildout.cfg file that defines our script:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... develop = hello
+ ... parts = helloworld
+ ...
+ ... [helloworld]
+ ... recipe = z3c.recipe.dev:script
+ ... eggs = hello
+ ... module = hello.helloworld
+ ... method = helloWorld
+ ...
+ ... ''' % globals())
+
+Let's run buildout again:
+
+ >>> print system(join('bin', 'buildout')),
+ Develop: '/sample-buildout/hello'
+ Uninstalling myapp.
+ Uninstalling var.
+ Installing helloworld.
+ Generated script '/sample-buildout/bin/helloworld'.
+
+And check the script again. Now we see the helloWorld method is used:
+
+ >>> cat('bin', 'helloworld-script.py')
+ #!C:\Python24\python.exe
+ <BLANKLINE>
+ import sys
+ sys.path[0:0] = [
+ '/sample-buildout/hello',
+ ]
+ <BLANKLINE>
+ import os
+ sys.argv[0] = os.path.abspath(sys.argv[0])
+ <BLANKLINE>
+ <BLANKLINE>
+ import hello.helloworld
+ <BLANKLINE>
+ if __name__ == '__main__':
+ hello.helloworld.helloWorld()
+
+Now we can call the script:
+
+ >>> print system(join('bin', 'helloworld')),
+ Hello World
Property changes on: z3c.recipe.dev/trunk/src/z3c/recipe/dev/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/__init__.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/__init__.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/__init__.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,110 @@
+###############################################################################
+##
+## Copyright (c) 2007 Zope Foundation and Contributors.
+## All Rights Reserved.
+##
+## This software is subject to the provisions of the Zope Public License,
+## Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+## WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+## WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+## FOR A PARTICULAR PURPOSE.
+##
+###############################################################################
+#"""Z3c development recipes
+#
+#$Id:$
+#"""
+#
+#import os, sys
+#import pkg_resources
+#import zc.buildout.easy_install
+#import zc.recipe.egg
+#
+#
+#class DevSetup:
+#
+# def __init__(self, buildout, name, options):
+# self.egg = None
+# self.buildout = buildout
+# self.name = name
+# self.options = options
+# options['script'] = os.path.join(buildout['buildout']['bin-directory'],
+# options.get('script', self.name),
+# )
+# if not options.get('working-directory', ''):
+# options['location'] = os.path.join(
+# buildout['buildout']['parts-directory'], name)
+#
+# if options.get('eggs'):
+# self.egg = zc.recipe.egg.Egg(buildout, name, options)
+#
+# # get the workspace dir
+# directory = buildout['buildout']['directory']
+# workspace = options['workspace']
+# self.workspace = os.path.join(directory, workspace)
+#
+# def install(self):
+# options = self.options
+# dest = []
+#
+# if self.egg:
+# extra_paths = self.egg.extra_paths
+# extra_paths = [self.workspace] + extra_paths
+# eggs, ws = self.egg.working_set()
+#
+# test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
+# for spec in eggs]
+# else:
+# extra_paths = [self.workspace]
+# test_paths = [self.workspace]
+# ws = []
+#
+# executable = self.buildout['buildout']['executable']
+#
+# defaults = options.get('defaults', '').strip()
+# if defaults:
+# defaults = '(%s) + ' % defaults
+#
+# wd = options.get('working-directory', options['location'])
+# if os.path.exists(wd):
+# assert os.path.isdir(wd)
+# else:
+# os.mkdir(wd)
+# dest.append(wd)
+# initialization = initialization_template % wd
+#
+# env_section = options.get('environment', '').strip()
+# if env_section:
+# env = self.buildout[env_section]
+# for key, value in env.items():
+# initialization += env_template % (key, value)
+#
+# dest.extend(zc.buildout.easy_install.scripts(
+# [(options['script'], 'zope.testing.testrunner', 'run')],
+# ws, executable, self.buildout['buildout']['bin-directory'],
+# extra_paths=extra_paths,
+# arguments = defaults + (arg_template % dict(
+# TESTPATH=repr(test_paths)[1:-1].replace(
+# ', ', ",\n '--test-path', "),
+# )),
+# initialization = initialization,
+# ))
+#
+# return dest
+#
+# update = install
+#
+#
+#arg_template = """[
+# '--test-path', %(TESTPATH)s,
+# ]"""
+#
+#
+#initialization_template = """import os
+#sys.argv[0] = os.path.abspath(sys.argv[0])
+#os.chdir(%r)
+#"""
+#
+#env_template = """os.environ['%s'] = %r
+#"""
Property changes on: z3c.recipe.dev/trunk/src/z3c/recipe/dev/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/app.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/app.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/app.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,226 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Z3c development recipes
+
+$Id:$
+"""
+
+import os, sys, shutil
+import zc.buildout
+import zc.recipe.egg
+import pkg_resources
+import ZConfig.schemaless
+import cStringIO
+
+server_types = {
+ # name (module, http-name)
+ 'twisted': ('zope.app.twisted.main', 'HTTP'),
+ 'zserver': ('zope.app.server.main', 'WSGI-HTTP'),
+ }
+
+class AppSetup:
+
+ def __init__(self, buildout, name, options):
+ self.egg = None
+ self.buildout = buildout
+ self.name = name
+ self.options = options
+ options['script'] = os.path.join(buildout['buildout']['bin-directory'],
+ options.get('script', self.name),
+ )
+ if not options.get('working-directory', ''):
+ options['location'] = os.path.join(
+ buildout['buildout']['parts-directory'], name)
+
+ if options.get('eggs'):
+ self.egg = zc.recipe.egg.Egg(buildout, name, options)
+
+ def install(self):
+ options = self.options
+ location = options['location']
+ executable = self.buildout['buildout']['executable']
+
+ # setup path
+ dest = []
+ if not os.path.exists(location):
+ os.mkdir(location)
+ dest.append(location)
+
+ event_log_path = os.path.join(location, 'z3.log')
+ access_log_path = os.path.join(location, 'access.log')
+ site_zcml_path = os.path.join(location, 'site.zcml')
+ principals_zcml_path = os.path.join(location, 'principals.zcml')
+ securitypolicy_zcml_path = os.path.join(location, 'securitypolicy.zcml')
+
+ # append files to dest whihc should get removed on update
+ dest.append(site_zcml_path)
+ dest.append(principals_zcml_path)
+ dest.append(securitypolicy_zcml_path)
+
+
+ # setup site.zcml
+ open(site_zcml_path, 'w').write(
+ site_zcml_template % self.options['site.zcml']
+ )
+
+ # setup principals.zcml
+ open(principals_zcml_path, 'w').write(
+ principals_zcml_template % self.options['principals.zcml']
+ )
+
+ # setup securitypolicy.zcml
+ open(securitypolicy_zcml_path, 'w').write(
+ securitypolicy_zcml_template % self.options['securitypolicy.zcml']
+ )
+
+ # setup zope.conf
+ zope_conf = options.get('zope.conf', '')+'\n'
+ zope_conf = ZConfig.schemaless.loadConfigFile(
+ cStringIO.StringIO(zope_conf))
+
+ zope_conf['site-definition'] = [site_zcml_path]
+
+ server_type = server_types[options['server']][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))
+
+ if not [s for s in zope_conf.sections if s.type == 'eventlog']:
+ zdaemon_conf.sections.append(event_log(event_log_path))
+
+ # create zope.conf
+ zope_conf_path = os.path.join(location, 'zope.conf')
+ open(zope_conf_path, 'w').write(str(zope_conf))
+
+ extra_paths = self.egg.extra_paths
+ eggs, ws = self.egg.working_set()
+
+ test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
+ for spec in eggs]
+
+ # setup start script
+ defaults = options.get('defaults', '').strip()
+ if defaults:
+ defaults = '(%s) + ' % defaults
+
+ initialization = initialization_template
+ server_module = server_types[options['server']][0]
+
+ dest.extend(zc.buildout.easy_install.scripts(
+ [(options['script'], server_module, 'main')],
+ ws, executable, self.buildout['buildout']['bin-directory'],
+ extra_paths = extra_paths,
+ arguments = defaults + (arg_template % dict(
+ ZOPE_CONF=zope_conf_path,
+ )),
+ initialization = initialization,
+ ))
+
+ return dest
+
+ update = install
+
+
+site_zcml_template = """\
+<configure
+ xmlns="http://namespaces.zope.org/zope">
+
+%s
+
+</configure>
+"""
+
+principals_zcml_template = """\
+<configure
+ xmlns="http://namespaces.zope.org/zope">
+
+%s
+
+</configure>
+"""
+
+securitypolicy_zcml_template = """\
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope">
+
+%s
+
+</configure>
+"""
+
+arg_template = """[
+ '-C', %(ZOPE_CONF)r,
+ ]+sys.argv[1:]"""
+
+
+initialization_template = """import os
+sys.argv[0] = os.path.abspath(sys.argv[0])
+"""
+
+server_template = """
+<server>
+ type HTTP
+ address %s
+</server>
+"""
+
+access_log_template = """
+<accesslog>
+ <logfile>
+ path %s
+ </logfile>
+</accesslog>
+"""
+
+event_log_template = """
+<eventlog>
+ <logfile>
+ path %s
+ formatter zope.exceptions.log.Formatter
+ </logfile>
+</eventlog>
+"""
+
+def access_log(path):
+ return ZConfig.schemaless.Section(
+ 'accesslog', '',
+ sections=[ZConfig.schemaless.Section('logfile', '', dict(path=[path]))]
+ )
+
+def event_log(path, *data):
+ return ZConfig.schemaless.Section(
+ 'eventlog', '', None,
+ [ZConfig.schemaless.Section(
+ 'logfile',
+ '',
+ dict(path=[path])),
+ ])
Property changes on: z3c.recipe.dev/trunk/src/z3c/recipe/dev/app.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/script.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/script.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/script.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Z3c development recipes
+
+$Id:$
+"""
+
+import os, sys, shutil
+import zc.buildout
+import zc.recipe.egg
+import pkg_resources
+import ZConfig.schemaless
+import cStringIO
+
+
+class ScriptSetup:
+
+ def __init__(self, buildout, name, options):
+ self.egg = None
+ self.buildout = buildout
+ self.name = name
+ self.options = options
+ options['script'] = os.path.join(buildout['buildout']['bin-directory'],
+ options.get('script', self.name),
+ )
+ if not options.get('working-directory', ''):
+ options['location'] = os.path.join(
+ buildout['buildout']['parts-directory'], name)
+
+ if options.get('eggs'):
+ self.egg = zc.recipe.egg.Egg(buildout, name, options)
+
+ def install(self):
+ options = self.options
+ module = options['module']
+ method = options.get('method', 'py')
+ executable = self.buildout['buildout']['executable']
+
+ # setup additional egg path
+ if self.egg:
+ extra_paths = self.egg.extra_paths
+ eggs, ws = self.egg.working_set()
+ else:
+ extra_paths = ()
+ ws = []
+
+ # setup script default vars
+ defaults = options.get('defaults', '').strip()
+ if defaults:
+ defaults = '(%s) + ' % defaults
+
+ wd = options.get('working-directory', options['location'])
+
+ initialization = initialization_template
+
+ return zc.buildout.easy_install.scripts(
+ [(options['script'], module, method)],
+ ws, executable, self.buildout['buildout']['bin-directory'],
+ extra_paths = extra_paths,
+ arguments = defaults,
+ initialization = initialization,
+ )
+
+ return ()
+
+ update = install
+
+
+initialization_template = """import os
+sys.argv[0] = os.path.abspath(sys.argv[0])
+"""
Property changes on: z3c.recipe.dev/trunk/src/z3c/recipe/dev/script.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py
===================================================================
--- z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py (rev 0)
+++ z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py 2007-10-12 15:47:32 UTC (rev 80857)
@@ -0,0 +1,80 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os, re, shutil, sys, tempfile
+import pkg_resources
+
+import zc.buildout.testing
+
+import unittest
+import zope.testing
+from zope.testing import doctest, renormalizing
+
+
+def test_start_error():
+ """
+The start script will setup a egg based start hook for a Zope 3 setup. Let's
+create a buildout that installs it as an ordinary script:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [app]
+ ... recipe = z3c.recipe.dev:app
+ ... eggs = z3c.recipe.dev
+ ... servers = zserver
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+
+"""
+
+
+def setUp(test):
+ zc.buildout.testing.buildoutSetUp(test)
+ zc.buildout.testing.install_develop('z3c.recipe.dev', test)
+ zc.buildout.testing.install('zope.testing', test)
+ zc.buildout.testing.install('zc.recipe.egg', test)
+ zc.buildout.testing.install('ZConfig', test)
+ zc.buildout.testing.install('zc.recipe.filestorage', test)
+
+
+checker = renormalizing.RENormalizing([
+ zc.buildout.testing.normalize_path,
+ (re.compile(
+ "Couldn't find index page for '[a-zA-Z0-9.]+' "
+ "\(maybe misspelled\?\)"
+ "\n"
+ ), ''),
+ (re.compile("""['"][^\n"']+z3c.recipe.dev[^\n"']*['"],"""),
+ "'/z3c.recipe.dev',"),
+ (re.compile('#![^\n]+\n'), ''),
+ (re.compile('-\S+-py\d[.]\d(-\S+)?.egg'),
+ '-pyN.N.egg',
+ ),
+ ])
+
+
+def test_suite():
+ return unittest.TestSuite(
+# doctest.DocTestSuite(
+# setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+# checker=checker),
+ doctest.DocFileSuite('README.txt',
+ setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+ checker=checker),
+ )
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.recipe.dev/trunk/src/z3c/recipe/dev/tests.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list