[Checkins] SVN: megrok.nozodb/trunk/ create package space

Christian Klinger cklinger at novareto.de
Thu Nov 4 14:23:59 EDT 2010


Log message for revision 118210:
  create package space

Changed:
  A   megrok.nozodb/trunk/README.txt
  A   megrok.nozodb/trunk/bootstrap.py
  A   megrok.nozodb/trunk/buildout.cfg
  A   megrok.nozodb/trunk/docs/
  A   megrok.nozodb/trunk/docs/HISTORY.txt
  A   megrok.nozodb/trunk/setup.py
  A   megrok.nozodb/trunk/src/
  A   megrok.nozodb/trunk/src/megrok/
  A   megrok.nozodb/trunk/src/megrok/__init__.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/
  A   megrok.nozodb/trunk/src/megrok/nozodb/README.txt
  A   megrok.nozodb/trunk/src/megrok/nozodb/__init__.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/components.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/nozodb.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/tests/
  A   megrok.nozodb/trunk/src/megrok/nozodb/tests/__init__.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/tests/test_megroknozodb.py
  A   megrok.nozodb/trunk/src/megrok/nozodb/utils.py

-=-
Added: megrok.nozodb/trunk/README.txt
===================================================================
--- megrok.nozodb/trunk/README.txt	                        (rev 0)
+++ megrok.nozodb/trunk/README.txt	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,4 @@
+Introduction
+============
+
+

Added: megrok.nozodb/trunk/bootstrap.py
===================================================================
--- megrok.nozodb/trunk/bootstrap.py	                        (rev 0)
+++ megrok.nozodb/trunk/bootstrap.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,260 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""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.
+"""
+
+import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
+from optparse import OptionParser
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    quote = str
+
+# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
+stdout, stderr = subprocess.Popen(
+    [sys.executable, '-Sc',
+     'try:\n'
+     '    import ConfigParser\n'
+     'except ImportError:\n'
+     '    print 1\n'
+     'else:\n'
+     '    print 0\n'],
+    stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+has_broken_dash_S = bool(int(stdout.strip()))
+
+# In order to be more robust in the face of system Pythons, we want to
+# run without site-packages loaded.  This is somewhat tricky, in
+# particular because Python 2.6's distutils imports site, so starting
+# with the -S flag is not sufficient.  However, we'll start with that:
+if not has_broken_dash_S and 'site' in sys.modules:
+    # We will restart with python -S.
+    args = sys.argv[:]
+    args[0:0] = [sys.executable, '-S']
+    args = map(quote, args)
+    os.execv(sys.executable, args)
+# Now we are running with -S.  We'll get the clean sys.path, import site
+# because distutils will do it later, and then reset the path and clean
+# out any namespace packages from site-packages that might have been
+# loaded by .pth files.
+clean_path = sys.path[:]
+import site
+sys.path[:] = clean_path
+for k, v in sys.modules.items():
+    if k in ('setuptools', 'pkg_resources') or (
+        hasattr(v, '__path__') and
+        len(v.__path__)==1 and
+        not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
+        # This is a namespace package.  Remove it.
+        sys.modules.pop(k)
+
+is_jython = sys.platform.startswith('java')
+
+setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
+distribute_source = 'http://python-distribute.org/distribute_setup.py'
+
+# parsing arguments
+def normalize_to_url(option, opt_str, value, parser):
+    if value:
+        if '://' not in value: # It doesn't smell like a URL.
+            value = 'file://%s' % (
+                urllib.pathname2url(
+                    os.path.abspath(os.path.expanduser(value))),)
+        if opt_str == '--download-base' and not value.endswith('/'):
+            # Download base needs a trailing slash to make the world happy.
+            value += '/'
+    else:
+        value = None
+    name = opt_str[2:].replace('-', '_')
+    setattr(parser.values, name, value)
+
+usage = '''\
+[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
+
+Bootstraps a buildout-based project.
+
+Simply run this script in a directory containing a buildout.cfg, using the
+Python that you want bin/buildout to use.
+
+Note that by using --setup-source and --download-base to point to
+local resources, you can keep this script from going over the network.
+'''
+
+parser = OptionParser(usage=usage)
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="use_distribute", default=False,
+                   help="Use Distribute rather than Setuptools.")
+parser.add_option("--setup-source", action="callback", dest="setup_source",
+                  callback=normalize_to_url, nargs=1, type="string",
+                  help=("Specify a URL or file location for the setup file. "
+                        "If you use Setuptools, this will default to " +
+                        setuptools_source + "; if you use Distribute, this "
+                        "will default to " + distribute_source +"."))
+parser.add_option("--download-base", action="callback", dest="download_base",
+                  callback=normalize_to_url, nargs=1, type="string",
+                  help=("Specify a URL or directory for downloading "
+                        "zc.buildout and either Setuptools or Distribute. "
+                        "Defaults to PyPI."))
+parser.add_option("--eggs",
+                  help=("Specify a directory for storing eggs.  Defaults to "
+                        "a temporary directory that is deleted when the "
+                        "bootstrap script completes."))
+parser.add_option("-t", "--accept-buildout-test-releases",
+                  dest='accept_buildout_test_releases',
+                  action="store_true", default=False,
+                  help=("Normally, if you do not specify a --version, the "
+                        "bootstrap script and buildout gets the newest "
+                        "*final* versions of zc.buildout and its recipes and "
+                        "extensions for you.  If you use this flag, "
+                        "bootstrap and buildout will get the newest releases "
+                        "even if they are alphas or betas."))
+parser.add_option("-c", None, action="store", dest="config_file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout's main function
+if options.config_file is not None:
+    args += ['-c', options.config_file]
+
+if options.eggs:
+    eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
+else:
+    eggs_dir = tempfile.mkdtemp()
+
+if options.setup_source is None:
+    if options.use_distribute:
+        options.setup_source = distribute_source
+    else:
+        options.setup_source = setuptools_source
+
+if options.accept_buildout_test_releases:
+    args.append('buildout:accept-buildout-test-releases=true')
+args.append('bootstrap')
+
+try:
+    import pkg_resources
+    import setuptools # A flag.  Sometimes pkg_resources is installed alone.
+    if not hasattr(pkg_resources, '_distribute'):
+        raise ImportError
+except ImportError:
+    ez_code = urllib2.urlopen(
+        options.setup_source).read().replace('\r\n', '\n')
+    ez = {}
+    exec ez_code in ez
+    setup_args = dict(to_dir=eggs_dir, download_delay=0)
+    if options.download_base:
+        setup_args['download_base'] = options.download_base
+    if options.use_distribute:
+        setup_args['no_fake'] = True
+    ez['use_setuptools'](**setup_args)
+    if 'pkg_resources' in sys.modules:
+        reload(sys.modules['pkg_resources'])
+    import pkg_resources
+    # This does not (always?) update the default working set.  We will
+    # do it.
+    for path in sys.path:
+        if path not in pkg_resources.working_set.entries:
+            pkg_resources.working_set.add_entry(path)
+
+cmd = [quote(sys.executable),
+       '-c',
+       quote('from setuptools.command.easy_install import main; main()'),
+       '-mqNxd',
+       quote(eggs_dir)]
+
+if not has_broken_dash_S:
+    cmd.insert(1, '-S')
+
+find_links = options.download_base
+if not find_links:
+    find_links = os.environ.get('bootstrap-testing-find-links')
+if find_links:
+    cmd.extend(['-f', quote(find_links)])
+
+if options.use_distribute:
+    setup_requirement = 'distribute'
+else:
+    setup_requirement = 'setuptools'
+ws = pkg_resources.working_set
+setup_requirement_path = ws.find(
+    pkg_resources.Requirement.parse(setup_requirement)).location
+env = dict(
+    os.environ,
+    PYTHONPATH=setup_requirement_path)
+
+requirement = 'zc.buildout'
+version = options.version
+if version is None and not options.accept_buildout_test_releases:
+    # Figure out the most recent final version of zc.buildout.
+    import setuptools.package_index
+    _final_parts = '*final-', '*final'
+    def _final_version(parsed_version):
+        for part in parsed_version:
+            if (part[:1] == '*') and (part not in _final_parts):
+                return False
+        return True
+    index = setuptools.package_index.PackageIndex(
+        search_path=[setup_requirement_path])
+    if find_links:
+        index.add_find_links((find_links,))
+    req = pkg_resources.Requirement.parse(requirement)
+    if index.obtain(req) is not None:
+        best = []
+        bestv = None
+        for dist in index[req.project_name]:
+            distv = dist.parsed_version
+            if _final_version(distv):
+                if bestv is None or distv > bestv:
+                    best = [dist]
+                    bestv = distv
+                elif distv == bestv:
+                    best.append(dist)
+        if best:
+            best.sort()
+            version = best[-1].version
+if version:
+    requirement = '=='.join((requirement, version))
+cmd.append(requirement)
+
+if is_jython:
+    import subprocess
+    exitcode = subprocess.Popen(cmd, env=env).wait()
+else: # Windows prefers this, apparently; otherwise we would prefer subprocess
+    exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
+if exitcode != 0:
+    sys.stdout.flush()
+    sys.stderr.flush()
+    print ("An error occurred when trying to install zc.buildout. "
+           "Look above this message for any errors that "
+           "were output by easy_install.")
+    sys.exit(exitcode)
+
+ws.add_entry(eggs_dir)
+ws.require(requirement)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+if not options.eggs: # clean up temporary egg directory
+    shutil.rmtree(eggs_dir)

Added: megrok.nozodb/trunk/buildout.cfg
===================================================================
--- megrok.nozodb/trunk/buildout.cfg	                        (rev 0)
+++ megrok.nozodb/trunk/buildout.cfg	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,22 @@
+[buildout]
+develop = .
+parts = interpreter test omelette
+extends = http://svn.zope.org/*checkout*/groktoolkit/trunk/grok.cfg
+
+versions = versions
+
+[omelette]
+recipe = collective.recipe.omelette
+eggs = ${test:eggs}
+
+[versions]
+
+[interpreter]
+recipe = zc.recipe.egg
+eggs = megrok.nozodb
+interpreter = python
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = megrok.nozodb [test]
+defaults = ['--tests-pattern', '^f?tests$', '-v', '-c']

Added: megrok.nozodb/trunk/docs/HISTORY.txt
===================================================================
--- megrok.nozodb/trunk/docs/HISTORY.txt	                        (rev 0)
+++ megrok.nozodb/trunk/docs/HISTORY.txt	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,7 @@
+Changelog
+=========
+
+0.1dev (unreleased)
+-------------------
+
+- Initial release

Added: megrok.nozodb/trunk/setup.py
===================================================================
--- megrok.nozodb/trunk/setup.py	                        (rev 0)
+++ megrok.nozodb/trunk/setup.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,42 @@
+from setuptools import setup, find_packages
+import os
+
+version = '0.1'
+
+readme_filename = os.path.join('src', 'megrok', 'nozodb', 'README.txt')
+long_description = open(readme_filename).read() + '\n\n' + \
+                   open(os.path.join('docs', 'HISTORY.txt')).read()
+
+test_requires = ['zope.app.wsgi',]
+
+setup(name='megrok.nozodb',
+      version=version,
+      description="This package allows you to run grok without the zodb",
+      long_description=long_description,
+      # Get more strings from
+      # http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[
+        "Programming Language :: Python",
+        ],
+      keywords='grok wsgi zodb',
+      author='Christian Klinger',
+      author_email='cklinger at novareto.de',
+      url='http://pypi.python.org/pypi',
+      license='GPL',
+      packages=find_packages('src', exclude=['ez_setup']),
+      package_dir={'': 'src'},
+      namespace_packages=['megrok'],
+      include_package_data=True,
+      zip_safe=False,
+      extras_require={'test': test_requires},
+      install_requires=[
+          'setuptools',
+          'grok',
+          # -*- Extra requirements: -*-
+      ],
+      entry_points={
+         'paste.app_factory': [
+            'nozodb = megrok.nozodb:nozodb_factory',
+            ]
+      }
+      )

Added: megrok.nozodb/trunk/src/megrok/__init__.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/__init__.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/__init__.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: megrok.nozodb/trunk/src/megrok/nozodb/README.txt
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/README.txt	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/README.txt	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,87 @@
+=============
+megrok.nozodb
+=============
+
+The main purpose of this package is to provide support for 
+enabling Grok applications to be run as aster served WSGI
+applications without using the zodb.
+
+
+Using megrok.nozodb
+-------------------
+
+To setup a grok environment which works without the zodb you 
+have to replace the paster-application-factory which typically is
+located in the debug.ini and in the deploy.ini: To be concrete
+replace grokcore.startup#... with megrok.nozodb#nozodb
+
+.. code-block::
+    
+    [app:grok]
+    use = egg:megrok.nozodb#nozodb
+
+
+The next you have to do is setting up global utility which
+acts as an ApplicationRoot which is a  starting point for your application. 
+megrok.nozodb has an ungrokked default one.  You can subclass from it or 
+provide your own stuff which acts as ApplicationRoot.
+
+   >>> from megrok.nozodb import ApplicationRoot
+
+   >>> class MyApplicationRoot(ApplicationRoot):
+   ...     pass
+
+   >>> myapp = MyApplicationRoot()
+   >>> from zope.site.interfaces import IRootFolder
+   >>> IRootFolder.providedBy(myapp)
+   True
+
+   >>> from grok.interfaces import IApplication
+   >>> IApplication.providedBy(myapp)
+   True
+
+   >>> from zope.location import ILocation
+   >>> ILocation.providedBy(myapp)
+   True
+
+   >>> from zope.interface.verify import verifyObject
+   >>> from zope.component.interfaces import ISite
+   >>> verifyObject(ISite, myapp)
+   True
+
+
+API Documentation
+-----------------
+
+We have to create a simple site definition file, which is also quite
+plain::
+
+   >>> import os, tempfile
+   >>> temp_dir = tempfile.mkdtemp()
+
+   >>> sitezcml = os.path.join(temp_dir, 'site.zcml')
+   >>> open(sitezcml, 'w').write('<configure />')
+
+   >>> zope_conf = os.path.join(temp_dir, 'zope.conf')
+   >>> open(zope_conf, 'wb').write('''
+   ... site-definition %s
+   ...
+   ... <zodb>
+   ... </zodb>
+   ...
+   ... <eventlog>
+   ...   <logfile>
+   ...     path STDOUT
+   ...   </logfile>
+   ... </eventlog>
+   ... ''' %sitezcml)
+
+
+   >>> from megrok.nozodb import nozodb_factory
+   >>> app_factory = nozodb_factory({'zope_conf': zope_conf})
+
+  Clean up the temp_dir
+
+    >>> import shutil
+    >>> shutil.rmtree(temp_dir)
+

Added: megrok.nozodb/trunk/src/megrok/nozodb/__init__.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/__init__.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/__init__.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,2 @@
+from megrok.nozodb.nozodb import nozodb_factory
+from megrok.nozodb.components import ApplicationRoot

Added: megrok.nozodb/trunk/src/megrok/nozodb/components.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/components.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/components.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+import grok
+from zope import component, site, location
+
+
+class ApplicationRoot(grok.GlobalUtility):
+    grok.implements(
+        grok.interfaces.IApplication,
+        site.interfaces.IRootFolder,
+        location.ILocation,
+        component.interfaces.ISite)
+    grok.provides(site.interfaces.IRootFolder)
+    grok.baseclass()
+
+    __name__ = None
+    __parent__ = None
+
+    def getSiteManager(self):
+        gsm = component.getGlobalSiteManager()
+        return gsm
+
+    def setSiteManager(self, sm):
+        pass

Added: megrok.nozodb/trunk/src/megrok/nozodb/nozodb.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/nozodb.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/nozodb.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+
+from megrok.nozodb.utils import config, NOZODBWSGIPublisherApplication
+
+
+def nozodb_factory(global_conf, **local_conf):
+    """ this factory creates an wsgi-application, which don't
+        have a releation to zodb
+    """
+    zope_conf = global_conf['zope_conf']
+    config(zope_conf)
+    app = NOZODBWSGIPublisherApplication(handle_errors=True)
+    return app

Added: megrok.nozodb/trunk/src/megrok/nozodb/tests/__init__.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/tests/__init__.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/tests/__init__.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1 @@
+# make me a package

Added: megrok.nozodb/trunk/src/megrok/nozodb/tests/test_megroknozodb.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/tests/test_megroknozodb.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/tests/test_megroknozodb.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,33 @@
+import os
+import re
+import unittest
+from zope.testing import doctest, renormalizing
+
+checker = renormalizing.RENormalizing([
+    # str(Exception) has changed from Python 2.4 to 2.5 (due to
+    # Exception now being a new-style class).  This changes the way
+    # exceptions appear in traceback printouts.
+    (re.compile(r"ConfigurationExecutionError: <class '([\w.]+)'>:"),
+                r'ConfigurationExecutionError: \1:'),
+    ])
+
+optionflags=(doctest.ELLIPSIS+
+            doctest.NORMALIZE_WHITESPACE)
+
+main_doctests = ['README.txt']
+
+def test_suite():
+    suite = unittest.TestSuite()
+
+    for testfile in main_doctests:
+        suite.addTest(
+            doctest.DocFileSuite(
+                os.path.join('..', testfile),
+                optionflags=optionflags,
+                globs=globals(),
+                checker=checker))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+

Added: megrok.nozodb/trunk/src/megrok/nozodb/utils.py
===================================================================
--- megrok.nozodb/trunk/src/megrok/nozodb/utils.py	                        (rev 0)
+++ megrok.nozodb/trunk/src/megrok/nozodb/utils.py	2010-11-04 18:23:58 UTC (rev 118210)
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import logging
+import ZConfig
+
+from zope import component
+from zope.site.hooks import setSite
+from zope.site.interfaces import IRootFolder
+
+from grok.publication import GrokHTTPPublication
+
+from zope.app.appsetup import appsetup, product
+from zope.publisher.interfaces import ISkinnable
+from zope.app.wsgi import WSGIPublisherApplication
+from zope.publisher.skinnable import setDefaultSkin
+from zope.app.publication.httpfactory import chooseClasses
+
+
+# XXX We have to subclass from WSGIPublisherApplication because the
+#     ZODB-Stuff is very hard linked into it.
+class NOZODBWSGIPublisherApplication(WSGIPublisherApplication):
+    """
+    """
+
+    def __init__(self, handle_errors):
+        self.handleErrors = handle_errors
+        self.requestFactory = SimplePublicationRequestFactory()
+
+
+class SimplePublicationRequestFactory(object):
+    """ This Publication Request Factory does not have a link to
+        ZODB.
+    """
+
+    def __call__(self, input_stream, env):
+        method = env.get('REQUEST_METHOD', 'GET').upper()
+        request_class, publication_class = chooseClasses(method, env)
+
+        publication = BrowserPublication()
+        request = request_class(input_stream, env)
+        request.setPublication(publication)
+        if ISkinnable.providedBy(request):
+            # only ISkinnable requests have skins
+            setDefaultSkin(request)
+        return request
+
+
+class BrowserPublication(GrokHTTPPublication):
+    """ Browser Publication with NoZODB
+    """
+
+    def __init__(self):
+        app = component.queryUtility(IRootFolder)
+        if not app:
+            raise NotImplementedError("""
+                You have to register your own IRootFolder utility
+                to be able to register your stuff on it:
+                class AppRoot(grok.GlobalUtility):
+                    grok.implements(IRootFolder)""")
+        else:
+            setSite(app)
+            self._app = app
+
+    def getApplication(self, request):
+        return self._app
+
+
+# Maybe we can include a smarter version
+# in zope.app.wsgi.__init__ config for this...
+def config(configfile, schemafile=None, features=()):
+    # Load the configuration schema
+    if schemafile is None:
+        schemafile = os.path.join(
+            os.path.dirname(appsetup.__file__), 'schema', 'schema.xml')
+
+    # Let's support both, an opened file and path
+    if isinstance(schemafile, basestring):
+        schema = ZConfig.loadSchema(schemafile)
+    else:
+        schema = ZConfig.loadSchemaFile(schemafile)
+
+    # Load the configuration file
+    # Let's support both, an opened file and path
+    try:
+        if isinstance(configfile, basestring):
+            options, handlers = ZConfig.loadConfig(schema, configfile)
+        else:
+            options, handlers = ZConfig.loadConfigFile(schema, configfile)
+    except ZConfig.ConfigurationError, msg:
+        sys.stderr.write("Error: %s\n" % str(msg))
+        sys.exit(2)
+
+    # Insert all specified Python paths
+    if options.path:
+        sys.path[:0] = [os.path.abspath(p) for p in options.path]
+
+    # Parse product configs
+    product.setProductConfigurations(
+        options.product_config)
+
+    # Setup the event log
+    options.eventlog()
+
+    # Setup other defined loggers
+    for logger in options.loggers:
+        logger()
+
+    # Insert the devmode feature, if turned on
+    if options.devmode:
+        features += ('devmode',)
+        logging.warning("Developer mode is enabled: this is a security risk "
+            "and should NOT be enabled on production servers. Developer mode "
+            "can usually be turned off by setting the `devmode` option to "
+            "`off` or by removing it from the instance configuration file "
+            "completely.")
+
+    # Execute the ZCML configuration.
+    appsetup.config(options.site_definition, features=features)
+    return None



More information about the checkins mailing list