[Repoze-checkins] r757 - in repoze.zope2/trunk: . repoze/zope2 repoze/zope2/etc repoze/zope2/scripts repoze/zope2/tests

Chris McDonough chrism at agendaless.com
Sun Mar 2 09:12:34 UTC 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Sun Mar  2 04:12:33 2008
New Revision: 757

Log:
0.3.1 (2008-03-02)

  - mkzope2instance now:

    o takes no arguments, only options.  '-d' replaces the single
      argument path.

    o creates a "log" directory

    o writes out a zeo.conf into "etc" (unconditionally); you can
      start a ZEO instance after installation now via 'bin/runzeo -C
      etc/zeo.conf', after ensuring that the 'address' in the ZEO
      section is correct.

    o allows the specification of 'sandbox' (-s) (replaces
      single-argument instancedir), 'zeo-port' (-z) , 'zope-port'
      (-p), and 'use-zeo' (-z) options.  If 'use-zeo' is specified,
      the zope.conf that's written will use a ClientStorage by
      default.

    o writes a zope.conf with a zodb cache-size of 50000 rather than
      10000.

  - addzope2user, runzope2script, and debugzope2 now respect a
    "ZOPE_CONF" environment variable, which can be used to specify the
    zope.conf configuration file to use.

  - Add a sample <zodb_db main> section to the generated zope.conf
    that can be uncommented if the installer wants to use ZEO instead
    of FileStorage or vice versa.

  - Added an (experimental) 'zope2testrunner' script that sets up
    stuff in the environment before running
    'zope.testing.testrunner.run'.  It accepts the same arguments as
    the Zope 3 testrunner.  E.g. 'bin/zope2testrunner -m
    Products.faster'.  This also respects the ZOPE_CONF envvar.

  - Depend on Zope 2.10.5 (zopelib-2.10.5.0) instead of 2.10.4.2 and
    various other updated repoze libraries.
    



Added:
   repoze.zope2/trunk/repoze/zope2/etc/zope-nonzeoclient.conf
   repoze.zope2/trunk/repoze/zope2/scripts/finder.py   (contents, props changed)
   repoze.zope2/trunk/repoze/zope2/scripts/testrunner.py   (contents, props changed)
   repoze.zope2/trunk/repoze/zope2/tests/test_scripts.py   (contents, props changed)
Removed:
   repoze.zope2/trunk/repoze/zope2/etc/zope.conf
Modified:
   repoze.zope2/trunk/CHANGES.txt
   repoze.zope2/trunk/repoze/zope2/etc/zope-zeoclient.conf
   repoze.zope2/trunk/repoze/zope2/etc/zope2.ini
   repoze.zope2/trunk/repoze/zope2/instance.py
   repoze.zope2/trunk/repoze/zope2/scripts/adduser.py
   repoze.zope2/trunk/repoze/zope2/scripts/debug.py
   repoze.zope2/trunk/repoze/zope2/scripts/runscript.py
   repoze.zope2/trunk/setup.py

Modified: repoze.zope2/trunk/CHANGES.txt
==============================================================================
--- repoze.zope2/trunk/CHANGES.txt	(original)
+++ repoze.zope2/trunk/CHANGES.txt	Sun Mar  2 04:12:33 2008
@@ -1,22 +1,42 @@
-0.3.1
+0.3.1 (2008-03-02)
 
   - mkzope2instance now:
 
-    o creates a "log" directory
-
-    o writes out a zeo.conf into "etc"
-
     o takes no arguments, only options.  '-d' replaces the single
       argument path.
 
-    o allows the specification of 'zeo-port' (-z), 'directory' (-d)
-      (replaces single-argument instancedir), and 'http-port' (-p)
-      options.
+    o creates a "log" directory
+
+    o writes out a zeo.conf into "etc" (unconditionally); you can
+      start a ZEO instance after installation now via 'bin/runzeo -C
+      etc/zeo.conf', after ensuring that the 'address' in the ZEO
+      section is correct.
+
+    o allows the specification of 'sandbox' (-s) (replaces
+      single-argument instancedir), 'zeo-port' (-z) , 'zope-port'
+      (-p), and 'use-zeo' (-z) options.  If 'use-zeo' is specified,
+      the zope.conf that's written will use a ClientStorage by
+      default.
+
+    o writes a zope.conf with a zodb cache-size of 50000 rather than
+      10000.
+
+  - addzope2user, runzope2script, and debugzope2 now respect a
+    "ZOPE_CONF" environment variable, which can be used to specify the
+    zope.conf configuration file to use.
 
   - Add a sample <zodb_db main> section to the generated zope.conf
     that can be uncommented if the installer wants to use ZEO instead
-    of FileStorage.  Do the inverse if the zope-zeoclient.conf file is
-    the default (if -z).
+    of FileStorage or vice versa.
+
+  - Added an (experimental) 'zope2testrunner' script that sets up
+    stuff in the environment before running
+    'zope.testing.testrunner.run'.  It accepts the same arguments as
+    the Zope 3 testrunner.  E.g. 'bin/zope2testrunner -m
+    Products.faster'.  This also respects the ZOPE_CONF envvar.
+
+  - Depend on Zope 2.10.5 (zopelib-2.10.5.0) instead of 2.10.4.2 and
+    various other updated repoze libraries.
     
 0.3.0
 

Added: repoze.zope2/trunk/repoze/zope2/etc/zope-nonzeoclient.conf
==============================================================================
--- (empty file)
+++ repoze.zope2/trunk/repoze/zope2/etc/zope-nonzeoclient.conf	Sun Mar  2 04:12:33 2008
@@ -0,0 +1,62 @@
+###############################################################################
+# Welcome to Zope 2.
+###############################################################################
+#
+# This is the Zope configuration file.  The Zope configuration file
+# shows what the default configuration directives are, and show
+# examples for each directive.  To declare a directive, make sure that
+# you add it to a line that does not begin with '#'.  Note that comments 
+# are only allowed at the beginning of a line: you may not add comments
+# after directive text on the same line.
+
+%define INSTANCE ${sandbox}
+
+instancehome $INSTANCE
+products $INSTANCE/Products
+debug-mode on
+
+<eventlog>
+  level info
+  <logfile>
+    path STDERR
+    level info
+  </logfile>
+</eventlog>
+
+<logger access>
+  level WARN
+  <logfile>
+    path STDERR
+    format %(message)s
+  </logfile>
+</logger>
+
+<zodb_db temporary>
+    mount-point /temp_folder
+    <temporarystorage>
+      name sessions
+    </temporarystorage>
+    container-class Products.TemporaryFolder.TemporaryContainer
+</zodb_db>
+
+<zodb_db main>
+    mount-point /
+    cache-size 50000
+    <filestorage>
+      path $INSTANCE/var/Data.fs
+    </filestorage>
+</zodb_db>
+
+# Uncomment this to use a ZEO server as the main storage.
+#
+# <zodb_db main>
+#     mount-point /
+#     cache-size 50000
+#     <zeoclient>
+#       server localhost:8100
+#       storage 1
+#       cache-size 100MB
+#       name zeostorage
+#       var $INSTANCE/var
+#     </zeoclient>
+# </zodb_db>

Modified: repoze.zope2/trunk/repoze/zope2/etc/zope-zeoclient.conf
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/etc/zope-zeoclient.conf	(original)
+++ repoze.zope2/trunk/repoze/zope2/etc/zope-zeoclient.conf	Sun Mar  2 04:12:33 2008
@@ -52,7 +52,6 @@
 </zodb_db>
 
 # Uncomment this to use a FileStorage as the main storage
-
 #<zodb_db main>
 #    mount-point /
 #    cache-size 50000

Modified: repoze.zope2/trunk/repoze/zope2/etc/zope2.ini
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/etc/zope2.ini	(original)
+++ repoze.zope2/trunk/repoze/zope2/etc/zope2.ini	Sun Mar  2 04:12:33 2008
@@ -6,7 +6,7 @@
 repoze.obob.get_root = repoze.zope2.z2bob:get_root
 repoze.obob.initializer = repoze.zope2.z2bob:initialize
 repoze.obob.helper_factory = repoze.zope2.z2bob:Zope2ObobHelper
-zope.conf = %(here)s/${zope_conf}
+zope.conf = %(here)s/zope.conf
 
 [filter:errorlog]
 use = egg:repoze.errorlog#errorlog

Modified: repoze.zope2/trunk/repoze/zope2/instance.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/instance.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/instance.py	Sun Mar  2 04:12:33 2008
@@ -29,12 +29,13 @@
         conf['zdaemon_pkgdir'] = zdaemon.__path__[0]
     except ImportError:
         conf['zdaemon_pkgdir'] = '{unknown}'
+
+    zope_conf = conf['zope_conf']
         
     for source, target in (
         ('zope2.ini', 'zope2.ini'),
         ('site.zcml', 'site.zcml'),
-        ('zope.conf', 'zope.conf'),
-        ('zope-zeoclient.conf', 'zope-zeoclient.conf'),
+        (zope_conf, 'zope.conf'),
         ('apache2.conf', 'apache2.conf'),
         ('zeo.conf', 'zeo.conf'),
         ):
@@ -56,16 +57,18 @@
     parser = optparse.OptionParser(
         usage='%prog [OPTIONS]'
         )
-    parser.add_option('-d', '--directory', action='store', dest='sandbox',
+    parser.add_option('-s', '--sandbox', action='store', dest='sandbox',
                       default='.', help='Create the instance in this directory')
-    parser.add_option('-p', '--http-port', action='store', dest='zope_port',
+    parser.add_option('-p', '--zope-port', action='store', dest='zope_port',
                       default='8080', help='Zope HTTP port')
-    parser.add_option('-z', '--zeo-port', action='store', dest='zeo_port',
-                      default='', help='ZEO port (implies main storage in ZEO)')
-    options, args = parser.parse_args(sys.argv)
-    if options.zeo_port:
+    parser.add_option('-j', '--zeo-port', action='store', dest='zeo_port',
+                      default='8100', help='ZEO server port number')
+    parser.add_option('-z', '--use-zeo', action='store_true', dest='use_zeo',
+                      default=False, help='Use ZEO to house main storage')
+    options, args = parser.parse_args(argv)
+    if options.use_zeo:
         options.zope_conf = 'zope-zeoclient.conf'
     else:
-        options.zope_conf = 'zope.conf'
+        options.zope_conf = 'zope-nonzeoclient.conf'
     options.python = sys.executable
     mkinstance(options.__dict__)

Modified: repoze.zope2/trunk/repoze/zope2/scripts/adduser.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/scripts/adduser.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/scripts/adduser.py	Sun Mar  2 04:12:33 2008
@@ -14,21 +14,25 @@
 
 """ Add a Zope management user to the root Zope user folder """
 
-def adduser(user, pwd):
+import sys
+from repoze.zope2.scripts.finder import ZopeFinder
+
+def adduser(app, user, pwd):
     import transaction
-    from repoze.zope2.scripts.runscript import get_app
-    app = get_app()
-    app.acl_users._doAddUser(user, pwd, ['Manager'], [])
+    result = app.acl_users._doAddUser(user, pwd, ['Manager'], [])
     transaction.commit()
+    return result
 
-def main():
+def main(argv=sys.argv):
     import sys
     try:
-        user, pwd = sys.argv[1], sys.argv[2]
+        user, pwd = argv[1], argv[2]
     except IndexError:
-        print "%s <username> <password>" % sys.argv[0]
+        print "%s <username> <password>" % argv[0]
         sys.exit(255)
-    adduser(user, pwd)
+    finder = ZopeFinder(argv)
+    app = finder.get_app()
+    adduser(app, user, pwd)
 
 if __name__ == '__main__':
     main()

Modified: repoze.zope2/trunk/repoze/zope2/scripts/debug.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/scripts/debug.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/scripts/debug.py	Sun Mar  2 04:12:33 2008
@@ -17,9 +17,11 @@
 from code import interact
 import sys
 
-def main():
-    from repoze.zope2.scripts.runscript import get_app
-    app = get_app()
+from repoze.zope2.scripts.finder import ZopeFinder
+
+def main(argv=sys.argv):
+    finder = ZopeFinder(argv)
+    app = finder.get_app()
     cprt = ('Type "help" for more information. "app" is the Zope application '
             'object.')
     banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt)

Added: repoze.zope2/trunk/repoze/zope2/scripts/finder.py
==============================================================================
--- (empty file)
+++ repoze.zope2/trunk/repoze/zope2/scripts/finder.py	Sun Mar  2 04:12:33 2008
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2007 Agendaless Consulting and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the BSD-like license at
+# http://www.repoze.org/LICENSE.txt.  A copy of the license 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
+
+class ZopeFinder:
+    def __init__(self, argv):
+        self.cmd = argv[0]
+
+    def get_app(self, config_file=None):
+        # given a config file, return a Zope application object
+        if config_file is None:
+            config_file = self.get_zope_conf()
+        from Zope2.Startup import options, handlers
+        import App.config
+        import Zope2
+        opts = options.ZopeOptions()
+        opts.configfile = config_file
+        opts.realize(args=[], doc="", raise_getopt_errs=0)
+        handlers.handleConfig(opts.configroot, opts.confighandlers)
+        App.config.setConfiguration(opts.configroot)
+        app = Zope2.app()
+        return app
+
+    def get_zope_conf(self):
+        # the default config file path is assumed to live in
+        # $instance_home/etc/zope.conf, and the console scripts that use this
+        # are assumed to live in $instance_home/bin; override if the
+        # environ contains "ZOPE_CONF".
+        ihome = os.path.dirname(os.path.abspath(os.path.dirname(self.cmd)))
+        default_config_file = os.path.join(ihome, 'etc', 'zope.conf')
+        zope_conf = os.environ.get('ZOPE_CONF', default_config_file)
+        return zope_conf
+

Modified: repoze.zope2/trunk/repoze/zope2/scripts/runscript.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/scripts/runscript.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/scripts/runscript.py	Sun Mar  2 04:12:33 2008
@@ -15,36 +15,18 @@
 """ Run a Python script with the Zope application object in globals as 'app' """
 
 import sys
-import os
+from repoze.zope2.scripts.finder import ZopeFinder
 
-# given a config file, return a Zope application object
-def get_app(config_file=None):
-    if config_file is None:
-        me = sys.argv[0]
-        ihome = os.path.dirname(os.path.abspath(os.path.dirname(me)))
-        config_file = os.path.join(ihome, 'etc', 'zope.conf')
-    from Zope2.Startup import options, handlers
-    import App.config
-    import Zope2
-    opts = options.ZopeOptions()
-    opts.configfile = config_file
-    opts.realize(args=[], doc="", raise_getopt_errs=0)
-    handlers.handleConfig(opts.configroot, opts.confighandlers)
-    App.config.setConfiguration(opts.configroot)
-    app = Zope2.app()
-    return app
-
-# run a script with arguments with 'app' in the globals namespace
-def main():
-    if len(sys.argv) < 2:
-        me = sys.argv[0]
-        print "%s <script> [args]" % me
-        sys.exit(255)
-    app = get_app()
+def main(argv=sys.argv):
+    # run a script with arguments with 'app' in the globals namespace
+    finder = ZopeFinder(argv)
+    me = argv.pop(0)
+    if not len(argv):
+        raise ValueError("must be called with a script name as first argument")
+    app = finder.get_app()
     g = globals()
     g['app'] = app
-    sys.argv.pop(0) # get rid of our name
-    execfile(sys.argv[0], g)
+    execfile(argv[0], g)
 
 if __name__ == '__main__':
     main()

Added: repoze.zope2/trunk/repoze/zope2/scripts/testrunner.py
==============================================================================
--- (empty file)
+++ repoze.zope2/trunk/repoze/zope2/scripts/testrunner.py	Sun Mar  2 04:12:33 2008
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Zope 2 test script
+
+see zope.testing testrunner.txt
+"""
+
+import sys
+import os
+
+from zope.testing import testrunner
+from repoze.zope2.scripts.finder import ZopeFinder
+
+def filter_warnings(option, opt, *ignored):
+    import warnings
+    warnings.simplefilter('ignore', Warning, append=True)
+
+testrunner.other.add_option(
+    '--nowarnings', action="callback", callback=filter_warnings,
+    help="Install a filter to suppress warnings emitted by code.")
+
+def main(argv=sys.argv):
+    finder = ZopeFinder(argv)
+    config_file = finder.get_zope_conf()
+    import Zope2
+    print 'Parsing %s' % config_file
+    Zope2.configure(config_file)
+    import App.FindHomes
+    ihome = os.getenv('INSTANCE_HOME')
+    products = os.path.join(ihome, 'Products')
+    defaults = []
+    if os.path.exists(products):
+        defaults += ['--package-path', products, 'Products']
+    # Remove script directory from path:
+    scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
+    sys.path[:] = [p for p in sys.path if os.path.realpath(p) != scriptdir]
+    # add parent dir of scriptdir to path
+    sys.path.append(os.path.dirname(scriptdir))
+    for path in sys.path:
+        defaults += ['--test-path', path]
+    return testrunner.run(defaults + argv[1:])
+
+if __name__ == '__main__':
+    sys.exit(main())

Added: repoze.zope2/trunk/repoze/zope2/tests/test_scripts.py
==============================================================================
--- (empty file)
+++ repoze.zope2/trunk/repoze/zope2/tests/test_scripts.py	Sun Mar  2 04:12:33 2008
@@ -0,0 +1,50 @@
+import unittest
+
+class FinderTests(unittest.TestCase):
+    def _getTargetClass(self):
+        from repoze.zope2.scripts.finder import ZopeFinder
+        return ZopeFinder
+
+    def _makeOne(self, argv):
+        return self._getTargetClass()(argv)
+
+    def test_get_zope_conf_from_environ(self):
+        finder = self._makeOne(['foo'])
+        import os
+        try:
+            os.environ['ZOPE_CONF'] = '/foo/zope.conf'
+            self.assertEqual(finder.get_zope_conf(), '/foo/zope.conf')
+        finally:
+            del os.environ['ZOPE_CONF']
+            
+    def test_get_zope_conf_from_console_script_path(self):
+        finder = self._makeOne(['/bin/runzope'])
+        self.assertEqual(finder.get_zope_conf(), '/etc/zope.conf')
+
+class AdduserTests(unittest.TestCase):
+    def _getFUT(self):
+        from repoze.zope2.scripts.adduser import adduser
+        return adduser
+
+    def test_it(self):
+        app = DummyApp()
+        app.acl_users = DummyUserFolder()
+        fn = self._getFUT()
+        result = fn(app, 'chris', '123')
+        self.assertEqual(result, 'OK')
+        self.assertEqual(app.acl_users.user, 'chris')
+        self.assertEqual(app.acl_users.pwd, '123')
+        self.assertEqual(app.acl_users.roles, ['Manager'])
+        self.assertEqual(app.acl_users.domains, [])
+
+class DummyApp:
+    pass
+
+class DummyUserFolder:
+    def _doAddUser(self, user, pwd, roles, domains):
+        self.user = user
+        self.pwd = pwd
+        self.roles = roles
+        self.domains = domains
+        return 'OK'
+        

Modified: repoze.zope2/trunk/setup.py
==============================================================================
--- repoze.zope2/trunk/setup.py	(original)
+++ repoze.zope2/trunk/setup.py	Sun Mar  2 04:12:33 2008
@@ -26,7 +26,7 @@
 
 setup(name='repoze.zope2',
       version=__version__,
-      description='An obob consumer that emulates Zope 2 publisher semantics',
+      description='Zope2 via WSGI and Paste',
       long_description=README + '\n\nCHANGES\n\n' + CHANGES,
       classifiers=[
         "Development Status :: 1 - Planning",
@@ -48,24 +48,24 @@
       namespace_packages=['repoze'],
       zip_safe=False,
       tests_require = [
-               'zopelib >= 2.10.4.2',
+               'zopelib >= 2.10.5.0',
                'ZODB3 >= 3.7.2, < 3.8.0a',
-               'repoze.tm >= 0.7',
-               'repoze.errorlog >= 0.4',
+               'repoze.tm >= 0.8',
+               'repoze.errorlog >= 0.5',
                'repoze.vhm >=0.3',
-               'repoze.retry >=0.5',
+               'repoze.retry >=0.6',
                'repoze.obob >= 0.2',
                ],
       install_requires=[
                'PasteScript >= 1.3.6',
                'WSGIUtils >= 0.7',
                'ZODB3 >= 3.7.2, < 3.8.0a',
-               'zopelib >= 2.10.4.2',
+               'zopelib >= 2.10.5.0',
                'repoze.obob >= 0.2',
-               'repoze.tm >= 0.7',
-               'repoze.retry >= 0.5',
+               'repoze.tm >= 0.8',
+               'repoze.retry >= 0.6',
                'repoze.vhm >= 0.3',
-               'repoze.errorlog >= 0.4',
+               'repoze.errorlog >= 0.5',
                ],
       test_suite="repoze.zope2.tests",
       entry_points = """\
@@ -75,6 +75,7 @@
         debugzope2 = repoze.zope2.scripts.debug:main
         installproduct = repoze.zope2.scripts.installproduct:main
         mkzope2instance = repoze.zope2.instance:main
+        zope2testrunner = repoze.zope2.scripts.testrunner:main
 
         [paste.server_runner]
         zserver = repoze.zope2.server:run_zserver


More information about the Repoze-checkins mailing list