app = Zope.app() backwards incompatibility notice / discussion
The extant "import Zope; app = Zope.app()" dance to get a hold of the Zope root object stopped working long ago on the 2.7 branch and HEAD due to the new configuration machinery, which implies that users be explicit about configuration settings rather than allowing Zope to guess. Up til now, the dance to get Zope 2.7 to start properly from within a script was byzantine and obscure. I've made a checkin which makes it a little easier (or at least I'm about to as soon as the full unit test suite comes back passed ;-). Code which used to do: import Zope app = Zope.app() Will need to do this under 2.7b4+: import Zope Zope.configure('/path/to/configfile') app = Zope.app() (I wont bother telling you what the dance was for 2.7 before now, it was pretty awful). I realize this is suboptimal from a backwards compatibility perspective, but I'm not sure how to make it any better, seeing as the config file has some fairly important information in it (like which databases to use) and guessing would be very bad in this context. Jim Roepke suggested that if an "ZOPE_CONFIG" envvar was set with the config file path, that "import Zope; Zope.app()" could be made to "just work", but I'm not sure this is any better than requiring that developers change their scripts. Guessing at the config file location is also fraught with problems, and I'd be hesitant to do it. I'm apt just to recommend that we require that developers add the "Zope.configure(filename)" line to their scripts as opposed to doing anything more magical. I'm sure there will be indignant wails about it, but c'est la vie. ;-) Note that FWIW, you can also do (on UNIX): zopectl run <scriptname> .. which will run a script with the name "app" set up as the root Zope application object. This might be the easiest way to run scripts which need to operate against Zope objects going forward. - C
Chris McDonough wrote Code which used to do:
import Zope app = Zope.app()
Will need to do this under 2.7b4+:
import Zope Zope.configure('/path/to/configfile') app = Zope.app()
Can we get an exception in the first case that states something like "No config file, use Zope.configure('configfile')"? Anthony -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.
On Sun, 2003-12-21 at 19:43, Anthony Baxter wrote:
Can we get an exception in the first case that states something like "No config file, use Zope.configure('configfile')"?
I think that can be arranged. Or something that smells like it anyway...
I do this dance a lot and this sounds fine to me. I tried using zopectl run with my scripts but you couldn't pass parameters to the script (which lowered the usefulness for me). -EAD On Dec 21, 2003, at 6:16 PM, Chris McDonough wrote:
The extant "import Zope; app = Zope.app()" dance to get a hold of the Zope root object stopped working long ago on the 2.7 branch and HEAD due to the new configuration machinery, which implies that users be explicit about configuration settings rather than allowing Zope to guess.
Up til now, the dance to get Zope 2.7 to start properly from within a script was byzantine and obscure. I've made a checkin which makes it a little easier (or at least I'm about to as soon as the full unit test suite comes back passed ;-).
Code which used to do:
import Zope app = Zope.app()
Will need to do this under 2.7b4+:
import Zope Zope.configure('/path/to/configfile') app = Zope.app()
(I wont bother telling you what the dance was for 2.7 before now, it was pretty awful).
I realize this is suboptimal from a backwards compatibility perspective, but I'm not sure how to make it any better, seeing as the config file has some fairly important information in it (like which databases to use) and guessing would be very bad in this context.
Jim Roepke suggested that if an "ZOPE_CONFIG" envvar was set with the config file path, that "import Zope; Zope.app()" could be made to "just work", but I'm not sure this is any better than requiring that developers change their scripts. Guessing at the config file location is also fraught with problems, and I'd be hesitant to do it.
I'm apt just to recommend that we require that developers add the "Zope.configure(filename)" line to their scripts as opposed to doing anything more magical. I'm sure there will be indignant wails about it, but c'est la vie. ;-)
Note that FWIW, you can also do (on UNIX):
zopectl run <scriptname>
.. which will run a script with the name "app" set up as the root Zope application object. This might be the easiest way to run scripts which need to operate against Zope objects going forward.
- C
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Chris McDonough wrote at 2003-12-21 18:16 -0500:
... Will need to do this under 2.7b4+:
import Zope Zope.configure('/path/to/configfile') app = Zope.app() ... Jim Roepke suggested that if an "ZOPE_CONFIG" envvar was set with the config file path, that "import Zope; Zope.app()" could be made to "just work",
A very good suggestion!
but I'm not sure this is any better than requiring that developers change their scripts.
For developpers, it is much better: Add an environment variable at one (or a few) central place versus change lots of scripts.
Guessing at the config file location is also fraught with problems, and I'd be hesitant to do it.
The suggestion was to use the value of "ZOPE_CONFIG" as config file path. Thus, you do not need to guess... -- Dieter
Whatever happened to the ZOPE_CONFIG env idea? What I have found is that I started putting Zope.config(os.getenv("ZOPE_CONFIG")) in all my scripts. Why can't his happen within Zope.app()? Something like this. *** lib/python/Zope/__init__.py.orig 2003-12-21 19:24:25.000000000 -0500 --- lib/python/Zope/__init__.py 2004-02-16 14:15:48.000000000 -0500 *************** *** 45,52 **** --- 45,59 ---- from Zope.App.startup import startup as _startup _startup() + from Zope.Startup.run import configure + class ZopeConfig(Exception):pass + def app(*args, **kw): """Utility for scripts to open a connection to the database""" + configfile = os.getenv("ZOPE_CONFIG") + if not configfile: + raise ZopeConfig, "ERROR: ZOPE_CONFIG environment variable not found" + configure(configfile) startup() return bobo_application(*args, **kw) *************** *** 56,62 **** import ZPublisher return ZPublisher.test('Zope', *args, **kw) - from Zope.Startup.run import configure # Zope.App.startup.startup() sets the following variables in this module. DB = None --- 63,68 ---- -EAD On Dec 22, 2003, at 1:37 PM, Dieter Maurer wrote:
Chris McDonough wrote at 2003-12-21 18:16 -0500:
... Will need to do this under 2.7b4+:
import Zope Zope.configure('/path/to/configfile') app = Zope.app() ... Jim Roepke suggested that if an "ZOPE_CONFIG" envvar was set with the config file path, that "import Zope; Zope.app()" could be made to "just work",
A very good suggestion!
but I'm not sure this is any better than requiring that developers change their scripts.
For developpers, it is much better:
Add an environment variable at one (or a few) central place versus change lots of scripts.
Guessing at the config file location is also fraught with problems, and I'd be hesitant to do it.
The suggestion was to use the value of "ZOPE_CONFIG" as config file path. Thus, you do not need to guess...
-- Dieter
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Nothing happened with it because by the time I got around to putting it in, the 2.7 branch was frozen for changes. Not sure about your patch, as Zope.app() can be called outside of the context of a script. Also, if the configuration has already been performed before the call to Zope.app(), it shouldn't fail because it can't find the ZOPE_CONFIG envvar. IOW, ZOPE_CONFIG should not be required, but if it is defined in the environment when called from a script, it should be used. If you can make that happen, and put the patch in the collector, I will see to it that it gets into 2.7.1. - C On Mon, 2004-02-16 at 14:29, Erik A.Dahl wrote:
Whatever happened to the ZOPE_CONFIG env idea? What I have found is that I started putting
Zope.config(os.getenv("ZOPE_CONFIG"))
in all my scripts. Why can't his happen within Zope.app()? Something like this.
*** lib/python/Zope/__init__.py.orig 2003-12-21 19:24:25.000000000 -0500 --- lib/python/Zope/__init__.py 2004-02-16 14:15:48.000000000 -0500 *************** *** 45,52 **** --- 45,59 ---- from Zope.App.startup import startup as _startup _startup()
+ from Zope.Startup.run import configure + class ZopeConfig(Exception):pass + def app(*args, **kw): """Utility for scripts to open a connection to the database""" + configfile = os.getenv("ZOPE_CONFIG") + if not configfile: + raise ZopeConfig, "ERROR: ZOPE_CONFIG environment variable not found" + configure(configfile) startup() return bobo_application(*args, **kw)
*************** *** 56,62 **** import ZPublisher return ZPublisher.test('Zope', *args, **kw)
- from Zope.Startup.run import configure
# Zope.App.startup.startup() sets the following variables in this module. DB = None --- 63,68 ----
-EAD
On Dec 22, 2003, at 1:37 PM, Dieter Maurer wrote:
Chris McDonough wrote at 2003-12-21 18:16 -0500:
... Will need to do this under 2.7b4+:
import Zope Zope.configure('/path/to/configfile') app = Zope.app() ... Jim Roepke suggested that if an "ZOPE_CONFIG" envvar was set with the config file path, that "import Zope; Zope.app()" could be made to "just work",
A very good suggestion!
but I'm not sure this is any better than requiring that developers change their scripts.
For developpers, it is much better:
Add an environment variable at one (or a few) central place versus change lots of scripts.
Guessing at the config file location is also fraught with problems, and I'd be hesitant to do it.
The suggestion was to use the value of "ZOPE_CONFIG" as config file path. Thus, you do not need to guess...
-- Dieter
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Chris McDonough wrote:
Note that FWIW, you can also do (on UNIX):
zopectl run <scriptname>
.. which will run a script with the name "app" set up as the root Zope application object. This might be the easiest way to run scripts which need to operate against Zope objects going forward.
- C
I tried this, but I'm getting local variable 'app' referenced before assignment error. Portion of my script: def main(): # import Zope # Zope.configure('/home/local/plone/test2.7zope/etc/zope.conf') # Zope.startup() # app=Zope.app() from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy, AnonymousUser, OmnipotentUser _policy=PermissiveSecurityPolicy() _oldpolicy=setSecurityPolicy(_policy) newSecurityManager(None, OmnipotentUser().__of__(app)) - Gerry
participants (5)
-
Anthony Baxter -
Chris McDonough -
Dieter Maurer -
Erik A.Dahl -
Gerry Kirk