Re: [Zope3-Users] Zope3 startup

2007-03-03 Thread Florian Lindner
Am Freitag, 2. März 2007 23:03 schrieb Marius Gedminas:
> On Fri, Mar 02, 2007 at 12:31:22PM -0500, Giovannetti, Mark wrote:
> > Thanks for confirming some of my questions!  Is there a book
> > that you would recommend that explains how python deals with
> > all this?
>
> I liked Mark Pilgrim's _Dive into Python_.  I don't remember if it goes
> into details about how Python modules work.

The book is available under GNU FDL: http://diveintopython.org

Regards,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Zope3 startup

2007-03-02 Thread Marius Gedminas
On Fri, Mar 02, 2007 at 12:31:22PM -0500, Giovannetti, Mark wrote:
> Thanks for confirming some of my questions!  Is there a book
> that you would recommend that explains how python deals with
> all this?

I liked Mark Pilgrim's _Dive into Python_.  I don't remember if it goes
into details about how Python modules work.

> > In fact, this is how Python imports modules: it executes the 
> > .py file of the module.  (It does this at most once during the 
> > program's execution, unless you explicitly ask it to reload 
> > modules.  Zope 3 never asks.)
> 
> Great, now I think I have a good handle on what is going on.  This
> also explains why I have to restart zope when I make code changes
> (something that puzzled me very briefly when I started learning).
> 
> So if I wanted to register utilities without using ZCML, I could
> place the provideUtility(...) calls in an __init__.py or directly
> within the utility's .py module.  Yes?

Yes, but only if you could make sure that your package or module was
imported during Zope 3 startup.

Grok uses a similar scheme, as far as I understand: you declare your
adapters and utilites in Python code, and then a single ZCML directive
in the grok: namespace loads your package and registers everything.

Does Grok have a website?  Google doesn't give me anything more useful
than these blog posts:

  http://faassen.n--tree.net/blog/view/weblog/2006/11/09/0
  http://faassen.n--tree.net/blog/view/weblog/2007/01/09/0
  
http://www.z3lab.org/sections/blogs/philipp-weitershausen/2007_01_09_you-thought-zope-3-wasn

Marius Gedminas
-- 
The laser etcher can accept most any image data, (think logos or screen dumps!)
and render it on a heat-sensitive surface. There's a big tunable exhaust fan,
so the thing can be dialed in to Not vaporize your laptop.
-- Stuart Kreitman


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


RE: [Zope3-Users] Zope3 startup

2007-03-02 Thread Giovannetti, Mark
Hi Marius,

Thanks for confirming some of my questions!  Is there a book
that you would recommend that explains how python deals with
all this?  I have read Apress' Beginning Python and I have read
bits and pieces of the online python docs.  I am willing to
pick up other python books if there are some good ones.

Other comments inline:

> From: Marius Gedminas
> On Wed, Feb 28, 2007 at 11:47:15AM -0500, Giovannetti, Mark wrote:
> > Hello,

[snip]

> > 
> > 1. At zope startup, each *-configure.zcml in etc/package-includes
> > is read.  
> > Q. The __init__.py file for each package is then executed, correct?
> > A. Yes, since my testing indicates this is the case.  I had problems
> > understanding this since the idiom is to just place a comment in 
> > the __init__ file and it seemed rather useless to a new user.
> 
> The __init__.py file is executed when you import a package.  That
> happens as a side effect when ZCML directives refer to classes and
> functions in packages.  The purpose of a __init__.py is to 
> define names that could be imported, and not to run some 
> initialization code.
> 
> In fact, this is how Python imports modules: it executes the 
> .py file of the module.  (It does this at most once during the 
> program's execution, unless you explicitly ask it to reload 
> modules.  Zope 3 never asks.)

Great, now I think I have a good handle on what is going on.  This
also explains why I have to restart zope when I make code changes
(something that puzzled me very briefly when I started learning).

So if I wanted to register utilities without using ZCML, I could
place the provideUtility(...) calls in an __init__.py or directly
within the utility's .py module.  Yes?

> 
> > 2. Each configure.zcml file in the package's root directory (the
> > one pointed to by the *-configure.zcml in package-includes) is
> > parsed.
> > Q. Does each class referred to in a  directive have
> > the class' entire module loaded/executed or is the class just
> > registered somewhere for future use?  
> > A. ?
> 
> Yes, the module is imported.

Thank you.

> 
> > 3. Utilities and such in zcml.
> > Q. Does each utility have its module executed to create the
> > instance (utilities are instances, right?)
> > A. I think so, but I'm not sure, see #2.
> 
> Yes, the module is imported.
> 
> > I hope someone can clear this up for me.  I never managed to
> > find a good explanation of the flow of control for zope3 
> > startup and initialization.  I have read both books already.
> 
> In brief, Zope 3 reads the configuration file (zope.conf), 
> finds out the
> name of the root zcml file (site.zcml, usually), then loads the ZCML
> configuration (which involves parsing all the zcml files that include
> each other, importing Python modules and accessing names defined in
> those), executes the configuration (which involves modifying global
> registries of adapters, utilities, security declarations 
> etc), opens or creates the ZODB database, and then starts 
> listening on network ports.
> 
> Marius Gedminas

I noticed that I could see this happening by watching the 
output of:

# tail -F zope-instance/log/transcript.log

if I add the following 'level debug' option to zope.conf 
(from a prior thread):


  # 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.
  level debug

  
path $LOGDIR/z3.log
formatter zope.exceptions.log.Formatter
  

  
path STDOUT
formatter zope.exceptions.log.Formatter
  


I can see all of the zcml files being called.

Mark

-- 
613-947-1359
System Scientist / Scientifique, spécialiste des systèmes
Canada Centre for Remote Sensing / Centre canadien de télédéction
Natural Resources Canada, 588 Booth Street, Ottawa, Ontario, Canada, K1A 0Y7
Ressources naturelles Canada, 588 rue Booth, Ottawa, Ontario, Canada, K1A 0Y7
Government of Canada / Gouvernement du Canada
  
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Zope3 startup

2007-02-28 Thread Marius Gedminas
On Wed, Feb 28, 2007 at 11:47:15AM -0500, Giovannetti, Mark wrote:
> Hello,
> 
> One of the problems that I've had learning zope 3 (and python
> at the same time) is that I did not understand how code 'got
> executed'.  This was a big stumbling block for someone coming
> from a non-object oriented background who was used to creating
> 'normal' websites--i.e. the html/cfm/whatever file is the 
> 'callable'.  This concept, to me, doesn't exist in zope3 as
> far as I can tell.
> 
> Some questions, then, regarding how parts of code get executed 
> in zope3.  If anyone has the time to answer them, or confirm
> my understanding, it would be appreciated.  My descriptions 
> are likely oversimplified/incorrect.
> 
> 1. At zope startup, each *-configure.zcml in etc/package-includes
> is read.  
> Q. The __init__.py file for each package is then executed, correct?
> A. Yes, since my testing indicates this is the case.  I had problems
> understanding this since the idiom is to just place a comment in 
> the __init__ file and it seemed rather useless to a new user.

The __init__.py file is executed when you import a package.  That
happens as a side effect when ZCML directives refer to classes and
functions in packages.  The purpose of a __init__.py is to define names
that could be imported, and not to run some initialization code.

In fact, this is how Python imports modules: it executes the .py file of
the module.  (It does this at most once during the program's execution,
unless you explicitly ask it to reload modules.  Zope 3 never asks.)

> 2. Each configure.zcml file in the package's root directory (the
> one pointed to by the *-configure.zcml in package-includes) is
> parsed.
> Q. Does each class referred to in a  directive have
> the class' entire module loaded/executed or is the class just
> registered somewhere for future use?  
> A. ?

Yes, the module is imported.

> 3. Utilities and such in zcml.
> Q. Does each utility have its module executed to create the
> instance (utilities are instances, right?)
> A. I think so, but I'm not sure, see #2.

Yes, the module is imported.

> I hope someone can clear this up for me.  I never managed to
> find a good explanation of the flow of control for zope3 
> startup and initialization.  I have read both books already.

In brief, Zope 3 reads the configuration file (zope.conf), finds out the
name of the root zcml file (site.zcml, usually), then loads the ZCML
configuration (which involves parsing all the zcml files that include
each other, importing Python modules and accessing names defined in
those), executes the configuration (which involves modifying global
registries of adapters, utilities, security declarations etc), opens or
creates the ZODB database, and then starts listening on network ports.

Marius Gedminas
-- 
Any sufficiently advanced magic is indistinguishable from technology.


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users