[Checkins] SVN: grokcore.startup/trunk/src/grokcore/startup/ refactor calling the command line interpreter. always use the "classic" one for executing scripts.
Jan Wijbrand Kolman
cvs-admin at zope.org
Tue May 1 15:58:38 UTC 2012
Log message for revision 125504:
refactor calling the command line interpreter. always use the "classic" one for executing scripts.
Changed:
U grokcore.startup/trunk/src/grokcore/startup/README.txt
U grokcore.startup/trunk/src/grokcore/startup/debug.py
U grokcore.startup/trunk/src/grokcore/startup/startup.py
-=-
Modified: grokcore.startup/trunk/src/grokcore/startup/README.txt
===================================================================
--- grokcore.startup/trunk/src/grokcore/startup/README.txt 2012-05-01 15:08:57 UTC (rev 125503)
+++ grokcore.startup/trunk/src/grokcore/startup/README.txt 2012-05-01 15:58:34 UTC (rev 125504)
@@ -260,7 +260,7 @@
>>> import shutil
>>> shutil.rmtree(temp_dir)
-``get_debugger(zope_conf_path)``
+``interactive_debug_prompt(zope_conf_path)``
--------------------------------------------
Get an interactive console with a debugging shell started.
@@ -289,10 +289,10 @@
in the ``[interactive_debugger]`` section of your ``buildout.cfg``.
>>> import zope.app.appsetup.appsetup
- >>> # Ugh - allow a reconfiguration of an app.
>>> zope.app.appsetup.appsetup._configured = False
>>> temp_dir = tempfile.mkdtemp()
+
>>> sitezcml = os.path.join(temp_dir, 'site.zcml')
>>> open(sitezcml, 'w').write(
... """<configure xmlns="http://namespaces.zope.org/zope">
@@ -336,10 +336,10 @@
... pprint(__file__)
... pprint(__name__)""")
>>>
- >>> sys.argv = ['get_debugger', script]
+ >>> sys.argv = ['interactive_debugger', script]
>>> from grokcore.startup import interactive_debug_prompt
>>> try:
- ... interactive_debug_prompt(zope_conf=zopeconf)
+ ... interactive_debug_prompt(zopeconf)
... except SystemExit:
... # Catch the exit from the interactive prompt as it would
... # exit this test as well.
Modified: grokcore.startup/trunk/src/grokcore/startup/debug.py
===================================================================
--- grokcore.startup/trunk/src/grokcore/startup/debug.py 2012-05-01 15:08:57 UTC (rev 125503)
+++ grokcore.startup/trunk/src/grokcore/startup/debug.py 2012-05-01 15:58:34 UTC (rev 125504)
@@ -30,9 +30,8 @@
class GrokDebug(object):
- def __init__(self, zope_conf='parts/etc/zope.debug.conf'):
- db = zope.app.wsgi.config(zope_conf)
- debugger = zope.app.debug.Debugger.fromDatabase(db)
+ def __init__(self, debugger):
+ debugger = debugger
self.app = debugger
self.root = debugger.root()
self.context = self.root
@@ -179,8 +178,8 @@
if obj.__name__.startswith(tail)]
-def ipython_debug_prompt(zope_conf):
- grokd = GrokDebug(zope_conf)
+def ipython_debug_prompt(debugger):
+ grokd = GrokDebug(debugger)
banner = textwrap.dedent(
"""\
IPython shell for Grok.
Modified: grokcore.startup/trunk/src/grokcore/startup/startup.py
===================================================================
--- grokcore.startup/trunk/src/grokcore/startup/startup.py 2012-05-01 15:08:57 UTC (rev 125503)
+++ grokcore.startup/trunk/src/grokcore/startup/startup.py 2012-05-01 15:58:34 UTC (rev 125504)
@@ -32,47 +32,47 @@
# Return the created application
return app
-def _classic_debug_prompt(zope_conf):
- db = zope.app.wsgi.config(zope_conf)
- debugger = zope.app.debug.Debugger.fromDatabase(db)
+def _classic_debug_prompt(debugger):
globals_ = {
'debugger': debugger,
'app': debugger,
'root': debugger.root()}
+ # Invoke an interactive interpreter prompt
+ 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=globals_)
+def _ipython_debug_prompt(debugger):
+ from grokcore.startup.debug import ipython_debug_prompt
+ return ipython_debug_prompt(debugger)
+
+def interactive_debug_prompt(zope_conf):
+ db = zope.app.wsgi.config(zope_conf)
+ debugger = zope.app.debug.Debugger.fromDatabase(db)
if len(sys.argv) > 1:
# There're arguments passed to the command. We replicate the
# "old" zopectl run command behaviour that would execfile()
# the second argument.
-
+ globals_ = {
+ 'debugger': debugger,
+ 'app': debugger,
+ 'root': debugger.root()}
# The current first argument is the interactive_debugger command
# itself. Pop it from the args list and as a result, the script
# to run is the first argument.
del sys.argv[0]
-
globals_['__name__'] = '__main__'
globals_['__file__'] = sys.argv[0]
execfile(sys.argv[0], globals_)
-
# Housekeeping.
db.close()
sys.exit()
-
- # Invoke an interactive interpreter prompt
- 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=globals_)
-
-def _ipython_debug_prompt(zope_conf):
- from grokcore.startup.debug import ipython_debug_prompt
- return ipython_debug_prompt(zope_conf)
-
-def interactive_debug_prompt(zope_conf):
+ # Start the interpreter.
try:
import IPython
except ImportError:
- return _classic_debug_prompt(zope_conf)
- return _ipython_debug_prompt(zope_conf)
+ return _classic_debug_prompt(debugger)
+ return _ipython_debug_prompt(debugger)
More information about the checkins
mailing list