[Checkins] SVN: z3c.recipe.paster/trunk/ building a debug recipe
Adam Groszer
agroszer at gmail.com
Fri Jan 22 08:15:24 EST 2010
Log message for revision 108390:
building a debug recipe
Changed:
U z3c.recipe.paster/trunk/CHANGES.txt
U z3c.recipe.paster/trunk/setup.py
A z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.py
A z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.txt
U z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py
-=-
Modified: z3c.recipe.paster/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.paster/trunk/CHANGES.txt 2010-01-22 12:02:44 UTC (rev 108389)
+++ z3c.recipe.paster/trunk/CHANGES.txt 2010-01-22 13:15:23 UTC (rev 108390)
@@ -5,6 +5,8 @@
0.5.1dev (unreleased)
---------------------
+- Added ``debug``, an interactive debug prompt.
+
- Fixed tests and fix all eggs in test setup.
- Fixed test normalizer.
Modified: z3c.recipe.paster/trunk/setup.py
===================================================================
--- z3c.recipe.paster/trunk/setup.py 2010-01-22 12:02:44 UTC (rev 108389)
+++ z3c.recipe.paster/trunk/setup.py 2010-01-22 13:15:23 UTC (rev 108390)
@@ -108,6 +108,7 @@
'setuptools',
'zc.recipe.egg',
'zope.app.wsgi',
+ 'zope.app.debug',
'zope.schema',
'zope.interface',
],
@@ -115,6 +116,7 @@
'zc.buildout': [
'serve = z3c.recipe.paster.serve:ServeSetup',
'paster = z3c.recipe.paster.paster:PasterSetup',
+ 'debug = z3c.recipe.paster.debug:DebugSetup',
]
},
)
Added: z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.py
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.py (rev 0)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.py 2010-01-22 13:15:23 UTC (rev 108390)
@@ -0,0 +1,94 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""Debug recipes for Zope3 apps
+
+$Id$
+"""
+
+import os
+import zc.buildout
+import zc.recipe.egg
+
+import code
+import zope.app.wsgi
+import zope.app.debug
+
+class DebugSetup:
+ """Paste serve setup script."""
+
+ def __init__(self, buildout, name, options):
+ self.app = 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 options.get('app') is None:
+ raise zc.buildout.UserError(
+ 'You have to define at the app (which has the eggs and zope.conf).')
+ self.app = options.get('app')
+ options['eggs'] = buildout[self.app]['eggs']
+
+ if not options.get('working-directory', ''):
+ options['location'] = buildout[self.app].get('location',
+ os.path.join(buildout['buildout']['parts-directory'], self.app))
+
+ 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
+ installed = []
+ if not os.path.exists(location):
+ os.mkdir(location)
+ installed.append(location)
+
+ zope_conf_path = os.path.join(location, 'zope.conf')
+
+ # setup paster script
+ if self.egg is not None:
+ extra_paths = self.egg.extra_paths
+ else:
+ extra_paths = []
+
+ eggs, ws = self.egg.working_set()
+
+ installed.extend(zc.buildout.easy_install.scripts(
+ [(self.name, 'z3c.recipe.paster.debug', 'main')],
+ ws, self.options['executable'],
+ self.buildout['buildout']['bin-directory'],
+ extra_paths = extra_paths,
+ arguments = "%r" % zope_conf_path,
+ ))
+
+ return installed
+
+ update = install
+
+
+def main(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()})
\ No newline at end of file
Property changes on: z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.py
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision
Added: svn:eol-style
+ native
Added: z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.txt
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.txt (rev 0)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.txt 2010-01-22 13:15:23 UTC (rev 108390)
@@ -0,0 +1,122 @@
+=======================
+z3c.recipe.paster:debug
+=======================
+
+This Zope 3 recipes offers a Debug script setup for Zope3 projects.
+
+
+Options
+-------
+
+The 'debug' recipe accepts the following options:
+
+app
+ The name of z3c.recipe.paster:serve application section.
+ All settings will be taken over from that.
+ The ``zope.conf`` generated by that section will be used.
+
+
+Test
+----
+
+Lets define a (bogus) egg that we can use in our application:
+
+ >>> mkdir('sample')
+ >>> write('sample', 'setup.py',
+ ... '''
+ ... from setuptools import setup
+ ... setup(name = 'sample')
+ ... ''')
+
+Now check if the setup was correct:
+
+ >>> ls('bin')
+ - buildout-script.py
+ - buildout.exe
+
+We'll create a ``buildout.cfg`` file that defines our paster configuration:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... develop = sample
+ ... parts = var myapp mydebug
+ ...
+ ... [var]
+ ... recipe = zc.recipe.filestorage
+ ...
+ ... [myapp]
+ ... eggs = sample
+ ... recipe = z3c.recipe.paster:serve
+ ... ini =
+ ... [app:main]
+ ... use = egg:sample
+ ...
+ ... [server:main]
+ ... use = egg:Paste#http
+ ... host = 127.0.0.1
+ ... port = 8080
+ ...
+ ... zope.conf =
+ ...
+ ... ${var:zconfig}
+ ...
+ ... <eventlog>
+ ... <logfile>
+ ... formatter zope.exceptions.log.Formatter
+ ... path ${buildout:directory}/parts/myapp/error.log
+ ... </logfile>
+ ... <logfile>
+ ... formatter zope.exceptions.log.Formatter
+ ... path STDOUT
+ ... </logfile>
+ ... </eventlog>
+ ...
+ ... devmode on
+ ...
+ ... site.zcml =
+ ... <include package="sample" file="app.zcml" />
+ ...
+ ... [mydebug]
+ ... recipe = z3c.recipe.paster:debug
+ ... app=myapp
+ ...
+ ... ''' % globals())
+
+ >>> ls('bin')
+ - buildout-script.py
+ - buildout.exe
+
+Now, Let's run the buildout and see what we get:
+
+ >>> print system(join('bin', 'buildout')),
+ Develop: '/sample-buildout/sample'
+ Installing var.
+ Installing myapp.
+ Generated script '/sample-buildout/bin/myapp'.
+ Installing mydebug.
+ Generated script '/sample-buildout/bin/mydebug'.
+
+Now check if the setup was correct:
+
+ >>> ls('bin')
+ - buildout-script.py
+ - buildout.exe
+ - myapp-script.py
+ - myapp.exe
+ - mydebug-script.py
+ - mydebug.exe
+
+Check the content of our new generated script.
+
+ >>> cat('bin', 'mydebug')
+ <BLANKLINE>
+ import sys
+ sys.path[0:0] = [
+ '/sample-buildout/sample',
+ ]
+ <BLANKLINE>
+ import z3c.recipe.paster.debug
+ <BLANKLINE>
+ if __name__ == '__main__':
+ z3c.recipe.paster.debug.main('/sample-buildout/parts/myapp/zope.conf')
Property changes on: z3c.recipe.paster/trunk/src/z3c/recipe/paster/debug.txt
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision
Added: svn:eol-style
+ native
Modified: z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py
===================================================================
--- z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py 2010-01-22 12:02:44 UTC (rev 108389)
+++ z3c.recipe.paster/trunk/src/z3c/recipe/paster/tests.py 2010-01-22 13:15:23 UTC (rev 108390)
@@ -73,6 +73,9 @@
zc.buildout.testing.install('zope.contenttype', test)
zc.buildout.testing.install_develop('z3c.recipe.paster', test)
+def setUpDebug(test):
+ setUp(test)
+ zc.buildout.testing.install('zope.app.debug', test)
checker = renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
@@ -102,4 +105,8 @@
setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
checker=checker),
+ doctest.DocFileSuite('debug.txt',
+ setUp=setUpDebug, tearDown=zc.buildout.testing.buildoutTearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ checker=checker),
))
More information about the checkins
mailing list