How to execute code at startup?
I have a very simple script that copies my production Zope instance to a fresh test instance. I have some Python code that I need to execute when the test instance starts for the first time (it only needs to execute once, but it won't hurt Zope if it executes every time the test instance starts. I usually execute this code interactively, from the Zope debugger: app.restrictedTraverse("/irtnog/portal_cache_settings").setCacheConfig ('zope') Is there any way to execute this code (or something similar) automatically? I guess the alternative is that I could script the process of entering the Zope debugger and running the above using Expect or something. Best wishes, Matthew -- "Rogues are very keen in their profession, and know already much more than we can teach them respecting their several kinds of roguery." - A. C. Hobbs in _Locks and Safes_ (1853)
Matthew X. Economou, on 2007-06-12:
I have a very simple script that copies my production Zope instance to a fresh test instance. I have some Python code that I need to execute when the test instance starts for the first time (it only needs to execute once, but it won't hurt Zope if it executes every time the test instance starts. I usually execute this code interactively, from the Zope debugger:
app.restrictedTraverse("/irtnog/portal_cache_settings").setCacheConfig ('zope')
Is there any way to execute this code (or something similar) automatically? I guess the alternative is that I could script the process of entering the Zope debugger and running the above using Expect or something.
The first approach that spring to mind is hackish. In your script that copies your production instance, add a line that copies an extra product to the Products directory. That product should probably be named 'ZZZHack' so that it gets loaded only at the very end after all other products have been loaded. Then you add a line like the above in the __init__.py of that product. Second, probably better, approach that comes to mind: forget about that Product. After you copied the instance, call: bin/zopectl run setcache.py where setcache.py only contains that line above I think. Maybe add "import transaction; transaction.commit()" after that. -- Maurits van Rees | http://maurits.vanrees.org/ [NL] Work | http://zestsoftware.nl/ "Do not worry about your difficulties in computers, I can assure you mine are still greater."
Perplexing problem. I'm migrating a site from Zope 2.2 to: Zope Version (Zope 2.9.7-final, python 2.4.4, linux2) Python Version 2.4.4 (#2, Apr 5 2007, 18:43:10) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] System Platform linux2 From the old site, I exported .zexp files, and simply imported them into the new site (in the same folder structure). In the root directory, all of the imported files and folders work as expected. However, when I go into an imported folder, and access one of it's folders, my users temporarily "lose" their authentication. As a diagnostic measure, I wrote some code to display their username for each page. In the pages/folders in the root directory, it displays their proper username. However, when I drill down into the site (e.g., folder of a folder), the username goes to "Anonymous User" and the code (which changes what is displayed based on the user's role), displays according to an anonymous user rather than the actual username. Note, however, that the true authentication is not lost. If the user goes to a folder/page closer to the root folder, the display again shows the user's proper username and the display is according to their proper assigned role. When I imported, I was as the "admin" user, and admin took ownership. I changed ownership to one of the users, and the code (and display). Changing owership from admin to another user didn't help, however. Any idea what the problem is. I looked on the changelogs on upgrading, but didn't find anything that explains this problem. TIA, Ron
--On 12. Juni 2007 10:36:59 -0400 "Matthew X. Economou" <xenophon@irtnog.org> wrote:
I have a very simple script that copies my production Zope instance to a fresh test instance. I have some Python code that I need to execute when the test instance starts for the first time (it only needs to execute once, but it won't hurt Zope if it executes every time the test instance starts. I usually execute this code interactively, from the Zope debugger:
app.restrictedTraverse("/irtnog/portal_cache_settings").setCacheConfig ('zope')
Is there any way to execute this code (or something similar) automatically? I guess the alternative is that I could script the process of entering the Zope debugger and running the above using Expect or something.
Why don't you read the related configuration inside *your* code from some configuration file or use a persistent configuration. You can't perform such an operation during the startup phase of Zope. -aj
participants (4)
-
Andreas Jung -
Matthew X. Economou -
Maurits van Rees -
Ron Chichester