[Zope-CVS] CVS: Products/OSCOM/NOTSite/Extensions - enable_set_trace.py:1.1

Tres Seaver tseaver@zope.com
Thu, 29 May 2003 14:49:55 -0400


Update of /cvs-repository/Products/OSCOM/NOTSite/Extensions
In directory cvs.zope.org:/tmp/cvs-serv952/Extensions

Added Files:
	enable_set_trace.py 
Log Message:


  - Repair skins breakage:

    o 'story_edit' marshalling error.

  - Implement "most recent 15" for section fronts.

  - Make CMS breadcrumbs emit CMS-centric URLs.

  - Expose effective / expires dates for stories.

  - Compute section list slot.

  - Implement "Tease Story" action for stories.

  - Add knobs to change the includable types for a section (currently
    needs help from ZMI to set property).

  - Add handling for "NITF" as text_format value.

  - First pass at NITF-HTML rendering.

  - *Don't* make folders / sections workflowed.


=== Added File Products/OSCOM/NOTSite/Extensions/enable_set_trace.py ===
"""Enable use of pdb.set_trace() for TTW debugging in python scripts,
templates, etc.

NOTE WELL that you don't want to have external methods for these exposed on
a production site - eg, calls of them accidentally left in production code
will cause them to consume zope threads, to quick starvation.

To use, Add a python "external method" in your workbench home pointing to
the function you want to make available through-the-web.  Settings for the
external method are indicated in comments before each function.

Usage guidance - when i want to step through a TTW python script and given the
choice of both functions, i strongly prefer adding the following line to my
script:

  context.enable_set_trace(); import pdb; pdb.set_trace()

The advantage over "context.trace_here()" is that the first step out of the
pdb module is into the body of the TTW script, rather than having to navigate
from the trace_here() external method code through the script execution
machinery into the target script.
"""


# id: enable_set_trace
# Module name: BCWorkbench.enable_set_trace
# Function name: enable_set_trace
def enable_set_trace():
    """After running this function, through-the-web methods on your site will
    allow import of pdb and call of pdb.set_trace().

    This will last until you restart the site, at which point you'll have to
    recall this function.

    (You could also call this script from your scripts, and then do an import
    pdb; pdb.set_trace().  That way you don't have to separately call this
    function yourself, it'll get called at the right time even after restarts.
    I think i like this mode best, above trace_here as well, for most
    situations.)
    """

    import AccessControl
    AccessControl.ModuleSecurityInfo('pdb').declarePublic('set_trace')

    return "You can now use import pdb and do a pdb.set_trace() ttw"

# id: trace_here
# Module name: BCWorkbench.enable_set_trace
# Function name: trace_here
def trace_here(self, *args):
    """This script is meant to be called directly.  You can pass it args to
    examine while in the function, and then step through back into the ttw
    method that called it."""
    import pdb; pdb.set_trace()
    args