[Zope-CMF] Examining portal_actions with the Zope app objectfrom the Python interpreter

Phil Glaser StillSmallVoice@DirectvInternet.com
Tue, 27 Aug 2002 20:47:53 -0400


Hi Chris,

The makerequest thing works like a charm for this. The pdb thing is good to
know about, too. I am grateful!

Just one more question: after I create this app object and then exit out of
the browser, Zope will not restart because it thinks Data.fs is locked. I
tried deleting just the three pid files in the var directory, but that did
not work, either. I finally discovered I could delete the Data.fs.lock file,
which does the trick. I did delete the app object before I exected the
interpreter, but that did not solve the problem. Is this just a fact of
life, or should I be doing something different to avoid locking Data.fs?

Many many thanks!!!

Regards,

Phil


> -----Original Message-----
> From: Chris McDonough [mailto:chrism@zope.com]
> Sent: Tuesday, August 27, 2002 6:49 PM
> To: Phil Glaser
> Cc: List Zope CMF List
> Subject: Re: [Zope-CMF] Examining portal_actions with the Zope app
> objectfrom the Python interpreter
>
>
> Hello Phil,
>
> This is an unfortunate dependency that some Zope machinery has on the
> web request.
>
> The quickest and surest way to get around this is to run Zope in such a
> way that it doesn't detach from the terminal ("./start -D
> STUPID_LOG_FILE=" will likely work.  Then insert a breakpoint into the
> source code in the method that is getting called.  In this case, you'd
> want to open the file on your hard disk named
> "CMF/CMFCore/ActionsTool.py", navigate to line 222 (at least in my copy
> it's 222, it might be somewhere else) and just under the "docstring"
> (indented the same amount as the following lines), insert the following:
>
> import pdb; pdb.set_trace()
>
> Then restart Zope and invoke the method that calls
> listFilteredActionsFor from a browser.  A pdb prompt will be shown on
> your terminal.  At that point, use "self" to refer to the actions tool.
> Use "self.getPhysicalRoot()" to get the "app" object.  "p" prints the
> value of an expression.  "n" steps to the next statement.  "s" skips
> into a method or function, and so on.  You can execute Zope line-by-line
> in this way to see what goes on.
>
> Instead of doing this, you might be able to "import Zope" (as you
> already know how to do) and get a hold of the "app" object.  Then wrap
> the app object in a fake request like so:
>
> from Testing.makerequest import makerequest
> app = makerequest(app)
>
> At this point, the call to listFilteredActionsFor *might* work but also
> might not.  Emulating a full web request is pretty hard and nobody has
> worked on it well enough for it to be foolproof, but this might come in
> handy for something else.
>
> HTH,
>
> - C
>
> On Tue, 2002-08-27 at 17:11, Phil Glaser wrote:
> > Fellow Seekers!
> >
> > At Alan's suggestion, and following the path of the yogis (or
> should I say
> > Zogies?) who have come before me, I am attempting to educate
> myself about
> > the intenerals of CMF by insantiating Zope from the Python
> command line and
> > examining with the objects directly. In particular, I'd like to see for
> > myself what's going on when the main_template does the following:
> >
> > <tal:block tal:define="global actions
> > python:here.portal_actions.listFilteredActionsFor(here)">
> >
> >
> > So, here's what I did:
> >
> > 1. Turned off Zope
> > 2. Fired up /usr/local/Zope/2-5-1/bin/python
> > 3. Imported os, os.path, sys, string
> > 4. Set apended '/usr/local/Zope/lib/python' to sys.path
> > 5. imported Zope (if you don't turn off Zope as above,
> importing Zope won't
> > work here)
> > 6. assigned Zope.app() to the local variable "app"
> >
> > I then examined app's namespace (__dict__) and marveled at how
> beautiful and
> > cool Zope is that it lets you do this. Surely the bliss that
> all beings seek
> > was closer at hand and I rejoiced that my practice of the
> Middle Way of Zope
> > Zen was beginning to pay off. I then navigated through the
> object hierarchy,
> > starting with the app object, until I got down to the
> portal_skins object.
> >
> > 7. Assigned the portal_skins object to a local variable named
> "portal_skins"
> > 8. Tried the following command:
> > portal_skins.portal_actions.listFilteredActionsFor(portal_skins.custom)
> >
> > The error messages I got back indicate that I'm getting closer
> to the bliss
> > I am seeking on this journey, but that "don't know mind" was blocking my
> > path; here's what I got:
> >
> >
> ******************************************************************
> **********
> > *******
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> >   File
> "/usr/local/zope/2-5-1/lib/python/Products/CMFCore/ActionsTool.py",
> > line 187, in listFilteredActionsFor
> >     ec = createExprContext(folder, portal, object)
> >   File
> "/usr/local/zope/2-5-1/lib/python/Products/CMFCore/Expression.py",
> > line 61, in createExprContext
> >     object_url = object.absolute_url()
> >   File "/usr/local/zope/2-5-1/lib/python/OFS/Traversable.py",
> line 48, in
> > absolute_url
> >     return join([req['SERVER_URL']] + req._script + path, '/')
> > KeyError: SERVER_URL
> >
> ******************************************************************
> **********
> > *******
> >
> > Obviously, because I'm not running the server in the usual way, there is
> > something that's missing from the context. What can I do to
> make this error
> > go away and get a result from listFilteredActionsFor() (and, hence, get
> > closer to The Unconditioned)?
> >
> > Also, the Python instance here does not respond to the usual
> escapes as far
> > as editing the interpreter command line (e.g., backspace does not work
> > properly, Ctrl-P does not give me the previous command, etc.).
> Is there some
> > way to fix this? (I'm in Linux 7.2)
> >
> > Many thanks!
> >
> > Regards,
> >
> > Phil
> >
> >
> > Philip Glaser
> > Principal and Software Architect
> > Sustainable Software Solutions, LLC
> > StillSmallVoice@DirectvInternet.com
> > www.sustainsoft.com
> > 973-951-9522
> >
> >
> >
> > _______________________________________________
> > Zope-CMF maillist  -  Zope-CMF@zope.org
> > http://lists.zope.org/mailman/listinfo/zope-cmf
> >
> > See http://collector.zope.org/CMF for bug reports and feature requests
>
>
>