Fix 'buildout.cfg' modification code
Stefan Bund [Sat, 24 Jul 2010 11:32:20 +0000 (13:32 +0200)]
15 files changed:
Makefile.buildout
skel-zope3/.gitignore [new file with mode: 0644]
skel-zope3/apidoc.zcml [new file with mode: 0644]
skel-zope3/buildout.cfg [new file with mode: 0644]
skel-zope3/debug.ini [new file with mode: 0644]
skel-zope3/deploy.ini [new file with mode: 0644]
skel-zope3/setup.py [new file with mode: 0644]
skel-zope3/site.zcml [new file with mode: 0644]
skel-zope3/src/appmain/__init__.py [new file with mode: 0644]
skel-zope3/src/appmain/configure.zcml [new file with mode: 0644]
skel-zope3/src/appmain/ftesting.zcml [new file with mode: 0644]
skel-zope3/src/appmain/startup.py [new file with mode: 0644]
skel-zope3/src/appmain/testing.py [new file with mode: 0644]
skel-zope3/zdaemon.conf [new file with mode: 0644]
skel-zope3/zope.conf [new file with mode: 0644]

index 3728542..47c5738 100644 (file)
@@ -1,13 +1,88 @@
 # -*- makefile -*-
 
+# Usage:
+#     @$(buildout_opt) <cfg-file> [set|add|append|remove] <section> <variable> [<value>]
+#
+# Change setting for <variable> in <section>. Actions are
+#
+#    set       Set <variable> to <value> replacing any existing value
+#    add       If <variable> is unset, set to <value>
+#    append    Append <value> to the end of the current value of <variable>
+#    remove    Remove any assignment to <variable>
+#
+define buildout_opt
+    _buildout_getopt_() {                                                                      \
+        sed -n -e "/^\[$$1\]/,/^\[/ba" -eb -e:a -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/p" $$cfgfile | \
+            sed -e '$$d';                                                                      \
+    };                                                                                         \
+    _buildout_haveopt() {                                                                      \
+       [ -n "`_buildout_getopt_ "$$1" "$$2"`" ];                                               \
+    };                                                                                         \
+    _buildout_getopt() {                                                                       \
+       _buildout_checkopt_ "$$1" "$$2" | -e '1s/[^=]* *= *//';                                 \
+    };                                                                                         \
+    _buildout_addopt() {                                                                       \
+       sed -i -e "/\[$$1\]/ba" -eb -e:a -ea\\ -e "$$2 = $$3" $$cfgfile;                        \
+    };                                                                                         \
+    _buildout_replaceopt() {                                                                   \
+       sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
+            -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                       \
+            -e "/^$$2 *=/bc" -ebd -e:c                                                         \
+            -ec\\ -e "$$2 = $$3" -eb -e:d                                                      \
+           -e "/^\([^ \t]\|\$$\)/b" -ed                                                        \
+               $$cfgfile;                                                                      \
+    };                                                                                         \
+    _buildout_appendopt() {                                                                    \
+       sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
+            -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                       \
+           -e /^\([^ \t]\|$$\)/bc -eb -e:c                                                     \
+            -ei\\ -e "    $$3"                                                                 \
+               $$cfgfile;                                                                      \
+    };                                                                                         \
+    _buildout_removeopt() {                                                                    \
+       sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
+            -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                       \
+           -e "/^\([^ \t]\|\$$\)/b" -ed                                                        \
+               $$cfgfile;                                                                      \
+    };                                                                                         \
+    _buildout_opt_set() {                                                                      \
+       if _buildout_haveopt "$$1" "$$2"; then                                                  \
+           _buildout_replaceopt "$$1" "$$2" "$$3";                                             \
+       else                                                                                    \
+           _buildout_addopt "$$1" "$$2" "$$3";                                                 \
+       fi;                                                                                     \
+    };                                                                                         \
+    _buildout_opt_add() {                                                                      \
+       if ! _buildout_haveopt "$$1" "$$2"; then                                                \
+           _buildout_addopt "$$1" "$$2" "$$3";                                                 \
+       fi;                                                                                     \
+    };                                                                                         \
+    _buildout_opt_append() {                                                                   \
+       if builout_haveopt "$$1" "$$2"; then                                                    \
+           _buildout_appendopt "$$1" "$$2" "$$3";                                              \
+       else                                                                                    \
+           _buildouT_addopt "$$1" "$$2" "$$3";                                                 \
+       fi;                                                                                     \
+    };                                                                                         \
+    _builout_opt_remove() {                                                                    \
+       if buildout_haveopt "$$1" "$$2"; then                                                   \
+           _buildout_removeopt "$$1" "$$2";                                                    \
+       fi;                                                                                     \
+    };                                                                                         \
+    _buildout_opt() {                                                                          \
+       echo "$$1: option '[$$3]/$$4' $$2 '$$5'";                                               \
+       cfgfile="$$1";                                                                          \
+       _buildout_opt_$$2 "$$3" "$$4" "$$5";                                                    \
+    };                                                                                         \
+    _buildout_opt
+endef
+
 buildout-net.cfg: buildout.cfg
-       @sed -i -e '/\[buildout\]/ba' -eb -e:a                  \
-           -ea\\ -e 'download-cache = $(DLCACHE)/downloads'    \
-           -ea\\ -e 'install-from-cache = true'                \
-           -ea\\ -e 'extends-cache = $(DLCACHE)/extends'       \
-           -ea\\ -e 'newest = false'                           \
-                buildout.cfg || ( rm -f buildout.cfg; false )
-       @mkdir -p $(DLCACHE)/downloads $(DLCACHE)/extends || ( rm -f buildout.cfg; false )
+       @$(buildout_opt) buildout.cfg add buildout download_cache $(DLCACHE)/downloads
+       @$(buildout_opt) buildout.cfg add buildout extends-cache $(DLCACHE)/extends
+       @$(buildout_opt) buildout.cfg set buildout install_from_cache true
+       @$(buildout_opt) buildout.cfg set buildout newest true
+       mkdir -p $(DLCACHE)/downloads $(DLCACHE)/extends
        @(                                      \
            echo "[buildout]";                  \
            echo "extends = buildout.cfg";      \
diff --git a/skel-zope3/.gitignore b/skel-zope3/.gitignore
new file mode 100644 (file)
index 0000000..6e26ebc
--- /dev/null
@@ -0,0 +1,13 @@
+*.pyc
+*.egg-info/
+/.env
+/python/
+/buildout-net.cfg
+/bin/
+/develop-eggs/
+/downloads/
+/log/
+/var/
+/parts/
+/.installed.cfg
+/dlcache/
diff --git a/skel-zope3/apidoc.zcml b/skel-zope3/apidoc.zcml
new file mode 100644 (file)
index 0000000..59b34b7
--- /dev/null
@@ -0,0 +1,13 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+  <include package="zope.app.zcmlfiles" file="meta.zcml" />
+  <include package="zope.app.preference" file="meta.zcml" />
+  <include package="zope.app.apidoc" file="meta.zcml" />
+  <include package="zope.app.onlinehelp" file="meta.zcml" />
+
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.tree" />
+  <include package="zope.app.onlinehelp" />
+  <include package="zope.app.renderer" />
+  <include package="zope.app.preference" />
+  <include package="zope.app.apidoc" />
+</configure>
diff --git a/skel-zope3/buildout.cfg b/skel-zope3/buildout.cfg
new file mode 100644 (file)
index 0000000..3a8eb92
--- /dev/null
@@ -0,0 +1,32 @@
+[buildout]
+install_from_cache = true
+extends-cache = dlcache/extends
+download_cache = dlcache/downloads
+develop = .
+newest = true
+parts = app test
+eggs-directory = downloads
+
+# These settings pin egg versions to the Zope 3.4.0 Known Good Set
+# if you want to upgrade the KGS version, you need to change the URL
+# below. If you will comment/remove these settings, you'll get the
+# latest versions of Zope eggs that are not guaranteed to work well
+# together.
+extends = http://download.zope.org/zope3.4/3.4.0/versions.cfg
+versions = versions
+
+[app]
+recipe = zc.recipe.egg
+eggs = appmain
+       zope.app.apidoc
+       zope.app.securitypolicy
+       z3c.evalexception>=2.0
+       Paste
+       PasteScript
+       PasteDeploy
+interpreter = python
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = appmain
+defaults = ['--tests-pattern', '^f?tests$', '-v']
diff --git a/skel-zope3/debug.ini b/skel-zope3/debug.ini
new file mode 100644 (file)
index 0000000..3a5965e
--- /dev/null
@@ -0,0 +1,13 @@
+[filter-app:main]
+# Change the last part from 'ajax' to 'pdb' for a post-mortem debugger
+# on the console:
+use = egg:z3c.evalexception#ajax
+next = zope
+
+[app:zope]
+use = egg:appmain
+
+[server:main]
+use = egg:Paste#http
+host = 127.0.0.1
+port = 8080
diff --git a/skel-zope3/deploy.ini b/skel-zope3/deploy.ini
new file mode 100644 (file)
index 0000000..a480426
--- /dev/null
@@ -0,0 +1,7 @@
+[app:main]
+use = egg:appmain
+
+[server:main]
+use = egg:Paste#http
+host = 127.0.0.1
+port = 8080
diff --git a/skel-zope3/setup.py b/skel-zope3/setup.py
new file mode 100644 (file)
index 0000000..c0f76c4
--- /dev/null
@@ -0,0 +1,58 @@
+from setuptools import setup, find_packages
+
+setup(name='appmain',
+
+      # Fill in project info below
+      version='0.1',
+      description="",
+      long_description="",
+      keywords='',
+      author='',
+      author_email='',
+      url='',
+      license='',
+      # Get more from http://www.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=['Programming Language :: Python',
+                   'Environment :: Web Environment',
+                   'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
+                   'Framework :: Zope3',
+                   ],
+
+      packages=find_packages('src'),
+      package_dir = {'': 'src'},
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=['setuptools',
+                        'ZODB3',
+                        'ZConfig',
+                        'zdaemon',
+                        'zope.publisher',
+                        'zope.traversing',
+                        'zope.app.wsgi>=3.4.0',
+                        'zope.app.appsetup',
+                        'zope.app.zcmlfiles',
+                        # The following packages aren't needed from the
+                        # beginning, but end up being used in most apps
+                        'zope.annotation',
+                        'zope.copypastemove',
+                        'zope.formlib',
+                        'zope.i18n',
+                        'zope.app.authentication',
+                        'zope.app.session',
+                        'zope.app.intid',
+                        'zope.app.keyreference',
+                        'zope.app.catalog',
+                        # The following packages are needed for functional
+                        # tests only
+                        'zope.testing',
+                        'zope.app.testing',
+                        'zope.app.securitypolicy',
+                        ],
+      entry_points = """
+      [console_scripts]
+      appmain-debug = appmain.startup:interactive_debug_prompt
+      appmain-ctl = appmain.startup:zdaemon_controller
+      [paste.app_factory]
+      main = appmain.startup:application_factory
+      """
+      )
diff --git a/skel-zope3/site.zcml b/skel-zope3/site.zcml
new file mode 100644 (file)
index 0000000..51407c3
--- /dev/null
@@ -0,0 +1,50 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           i18n_domain="appmain">
+
+  <include package="appmain" />
+
+  <!-- Remove this reference to disable the APIDoc tool.
+       You should do this for production -->
+  <include file="apidoc.zcml" />
+
+  <include package="zope.securitypolicy" file="meta.zcml" />
+  <include package="zope.app.securitypolicy" />
+  <securityPolicy 
+      component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+  <unauthenticatedPrincipal id="zope.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" />
+
+  <!-- Initial administrator account.  Disable this for production -->
+  <principal id="zope.manager"
+             title="Manager"
+             login="admin"
+             password_manager="Plain Text"
+             password="admin"
+             />
+
+  <!-- With the default zope securitypolicy, this is a
+       special role that every user has -->
+  <role id="zope.Anonymous"
+        title="Everybody"
+        description="All users have this role implicitly" />
+
+  <!-- Replace the following directives if you don't want public access -->
+  <grant permission="zope.View"
+         role="zope.Anonymous" />
+  <grant permission="zope.app.dublincore.view"
+         role="zope.Anonymous" />
+    
+  <role id="zope.Manager" title="Site Manager" />
+  <role id="zope.Member" title="Site Member" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager"
+         principal="zope.manager" />
+
+</configure>
diff --git a/skel-zope3/src/appmain/__init__.py b/skel-zope3/src/appmain/__init__.py
new file mode 100644 (file)
index 0000000..d67d458
--- /dev/null
@@ -0,0 +1 @@
+# Make this directory a package
diff --git a/skel-zope3/src/appmain/configure.zcml b/skel-zope3/src/appmain/configure.zcml
new file mode 100644 (file)
index 0000000..b176532
--- /dev/null
@@ -0,0 +1,27 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           i18n_domain="appmain">
+
+  <include package="zope.security" file="meta.zcml" />
+  <include package="zope.app.zcmlfiles" file="meta.zcml" />
+
+  <include package="zope.publisher" />
+  <include package="zope.traversing" />
+  <include package="zope.traversing.browser" />
+  <include package="zope.app.zcmlfiles" />
+
+  <!-- The following packages aren't needed from the beginning, but
+       end up being used in most applications -->
+  <include package="zope.i18n" file="meta.zcml" />
+  <include package="zope.annotation" />
+  <include package="zope.copypastemove" />
+  <include package="zope.formlib" />
+  <include package="zope.i18n.locales" />
+  <include package="zope.app.authentication" />
+  <include package="zope.app.session" />
+  <include package="zope.app.intid" />
+  <include package="zope.app.keyreference" />
+  <include package="zope.app.catalog" />
+
+  <!-- Add your own component registrations here -->
+
+</configure>
diff --git a/skel-zope3/src/appmain/ftesting.zcml b/skel-zope3/src/appmain/ftesting.zcml
new file mode 100644 (file)
index 0000000..9d5b407
--- /dev/null
@@ -0,0 +1,50 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:meta="http://namespaces.zope.org/meta"
+           i18n_domain="appmain">
+
+  <!-- Turn on the devmode -->
+  <meta:provides feature="devmode" />
+  <include package="appmain" />
+
+  <include package="zope.app.securitypolicy" file="meta.zcml" />
+  <include package="zope.app.securitypolicy" />
+  <securityPolicy 
+      component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+  <!-- Test Principals -->
+
+  <unauthenticatedPrincipal id="zope.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 that tests generally run as -->
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw"
+      />
+  <!-- Bootstrap principal used to make local grant to the principal above -->
+  <principal
+      id="zope.globalmgr"
+      title="Manager"
+      login="globalmgr"
+      password="globalmgrpw"
+      />
+
+  <grant permission="zope.View"
+         principal="zope.Anybody" />
+  <grant permission="zope.app.dublincore.view"
+         principal="zope.Anybody" />
+
+  <role id="zope.Manager" title="Site Manager" />
+  <role id="zope.Member" title="Site Member" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager" principal="zope.globalmgr" />
+
+</configure>
diff --git a/skel-zope3/src/appmain/startup.py b/skel-zope3/src/appmain/startup.py
new file mode 100644 (file)
index 0000000..478af5d
--- /dev/null
@@ -0,0 +1,35 @@
+import os
+import sys
+import code
+import zdaemon.zdctl
+import zope.app.wsgi
+import zope.app.debug
+
+def application_factory(global_conf, conf='zope.conf'):
+    zope_conf = os.path.join(global_conf['here'], conf)
+    return zope.app.wsgi.getWSGIApplication(zope_conf)
+
+def interactive_debug_prompt(zope_conf='zope.conf'):
+    db = zope.app.wsgi.config(zope_conf)
+    debugger = zope.app.debug.Debugger.fromDatabase(db)
+    # Invoke an interactive interpreter shell
+    banner = ("Welcome to the interactive debug prompt.\n"
+              "The 'root' variable contains the ZODB root folder.\n"
+              "The 'app' variable contains the Debugger, 'app.publish(path)' "
+              "simulates a request.")
+    code.interact(banner=banner, local={'debugger': debugger,
+                                        'app':      debugger,
+                                        'root':     debugger.root()})
+
+class ControllerCommands(zdaemon.zdctl.ZDCmd):
+
+    def do_debug(self, rest):
+        interactive_debug_prompt()
+
+    def help_debug(self):
+        print "debug -- Initialize the application, providing a debugger"
+        print "         object at an interactive Python prompt."
+
+def zdaemon_controller(zdaemon_conf='zdaemon.conf'):
+    args = ['-C', zdaemon_conf] + sys.argv[1:]
+    zdaemon.zdctl.main(args, options=None, cmdclass=ControllerCommands)
diff --git a/skel-zope3/src/appmain/testing.py b/skel-zope3/src/appmain/testing.py
new file mode 100644 (file)
index 0000000..4178830
--- /dev/null
@@ -0,0 +1,21 @@
+import os.path
+from zope.testing import doctest
+from zope.app.testing import functional
+
+ftesting_zcml = os.path.join(os.path.dirname(__file__), 'ftesting.zcml')
+FunctionalLayer = functional.ZCMLLayer(ftesting_zcml, __name__,
+                                       'FunctionalLayer')
+
+def FunctionalDocTestSuite(module=None, **kw):
+    module = doctest._normalize_module(module)
+    suite = functional.FunctionalDocTestSuite(module, **kw)
+    suite.layer = FunctionalLayer
+    return suite
+
+def FunctionalDocFileSuite(path, **kw):
+    suite = functional.FunctionalDocFileSuite(path, **kw)
+    suite.layer = FunctionalLayer
+    return suite
+
+class FunctionalTestCase(functional.FunctionalTestCase):
+    layer = FunctionalLayer
diff --git a/skel-zope3/zdaemon.conf b/skel-zope3/zdaemon.conf
new file mode 100644 (file)
index 0000000..cae6a23
--- /dev/null
@@ -0,0 +1,8 @@
+<runner>
+  program bin/paster serve deploy.ini
+  daemon on
+  transcript log/zdaemon.log
+  socket-name var/zdaemonsock
+  # Enable this to run the child process as a different user
+  # user zope
+</runner>
diff --git a/skel-zope3/zope.conf b/skel-zope3/zope.conf
new file mode 100644 (file)
index 0000000..175931d
--- /dev/null
@@ -0,0 +1,46 @@
+# Identify the component configuration used to define the site:
+site-definition site.zcml
+
+<zodb>
+  # Wrap standard FileStorage with BlobStorage proxy to get ZODB blobs
+  # support.
+  # This won't be needed with ZODB 3.9, as its FileStorage supports
+  # blobs by itself. If you use ZODB 3.9, remove the proxy and specify
+  # the blob-dir parameter right in in filestorage, just after path.
+  <blobstorage>
+    blob-dir var/blobs
+    <filestorage>
+      path var/Data.fs
+    </filestorage>
+  </blobstorage>
+
+# Uncomment this if you want to connect to a ZEO server instead:
+#  <zeoclient>
+#    server localhost:8100
+#    storage 1
+#    # ZEO client cache, in bytes
+#    cache-size 20MB
+#    # Uncomment to have a persistent disk cache
+#    #client zeo1
+#  </zeoclient>
+</zodb>
+
+<eventlog>
+  # This sets up logging to both a file and to standard output (STDOUT).
+  # The "path" setting can be a relative or absolute filesystem path or
+  # the tokens STDOUT or STDERR.
+
+  <logfile>
+    path log/z3.log
+    formatter zope.exceptions.log.Formatter
+  </logfile>
+
+  <logfile>
+    path STDOUT
+    formatter zope.exceptions.log.Formatter
+  </logfile>
+</eventlog>
+
+# Comment this line to disable developer mode.  This should be done in
+# production
+devmode on