This package provides some working examples of Zope/CMF/Plone scripting.
[Disclaimer: this is old stuff put here for reference only - I've not even tested whether the scripts still run but reading the code of the example scripts should hopefully be worthwhile.]
Welcome to ScriptingCMF
This package is not a Zope/CMF/Plone product in the strict sense but it rather tries to provide some working examples of Zope/CMF/Plone scripting.
Scripting Zope can be done in at least two qualitative different ways which are refered to here as 'local' scripting versus 'remote' scripting. For that reason the package contains to main scripts/modules, namely 'ScriptSite.py' and 'rscript_site.py'. All other files of the package are needed by these scripts and have to be placed as described below.
The source code of these scripts is actually meant to be read. It contains a lot of explainatory comments and I tried hard to keep it as readable as possible. This is particular the case for 'ScriptSite.py'. I propose to call files like these 'executable documentation'.
Zope/CMF/Plone Scripting in general: Everything that users as well as managers of a Zope/CMF/Plone site can do through the web can (of course) also be scripted. All one needs to know is the API of the Zope/CMF/Plone framework. Unfortunately, this API is not perfectly well documented. Given the (sparse) documentation currently (as of August 2003) available, what's almost always missing are WORKING EXAMPLES. That is the main reason why this package exists.
'remote' Scripting (from the 'outside')
Whenever a web form is filled in and submitted to the server this results in an appropriate HTTP request to the server. Such an HTTP request can also be submitted by a script as soon as the scripting framework (language) provides a means for issuing a web request.
'rscript_site.py' demonstrates this approach. This is a Python script that can be invoked at a UNIX shell or DOS prompt right away to manipulate a remote server running a Zope site (but with CMF/Plone and some other products installed; see below for details). It uses Pythons 'urllib' to issue the web requests. User credentials are submitted via basic HTTP authentication. See the source code of 'rscript_site.py' for more.
You are encouraged to use this script if you want to find out what's going on here interactively. The script halts after each server call to let you explore its consequences. Then, read its source code and try to understand in a bit more detail how it did what it did.
'local' Scripting (from the 'inside')
An alternative approach to scripting Zope is to provide a script for execution to the framework itself by means of an 'External Method'. (Note: Don't be confused by me considering this also as scripting from the 'inside'. This is because of different perspectives. I mean 'inside' and 'outside' with respect to the server and therefore usually the machines the server and the script are running on whereas Zope calls methods 'external' that are not located inside the ZODB but that 'live' in the file system.) This approach is demonstrated by 'ScriptSite.py'. To explore it, you need to place 'ScriptSite.py' into the 'INSTANCE_HOME/Extensions' folder (e.g., '/usr/local/zope-2.6.3/Extensions') together with a copy of or link to the 'ScriptingResources' directory that comes with this distribution. Via Zope's management interface (the ZMI) you then define an external method with the properties listed below in Zope's root folder. This is the one where the 'Control_Panel' is also located. The properties of the 'External Method' are:
id: install_ScriptedSite title: from 'www.neuroinf.de/LabTools' module: ScriptSite function: script_site
Now run the method by selecting its 'test' tab. Depending on your local installation you may have to adjust some file pathes. See the source of 'ScriptedSite.py' for details.
Again, this source file is meant to be read anyway. It contains the most extensive comments.
What you should have installed
For both kinds of scripting demos you need to have at least a Zope site with CMF installed in the file system of your server (place all products in 'ZOPEHOME/lib/python/Products'). There is no need to have a CMF or Plone site instanciated in the ZODB. This will be done by the scripts.
For optimal usage of these scripts, it is recommended that you get Plone also (the user experience when browsing the site is just so much better) plus two third party products, i.e.,
o CMFBibliography (from http://www.neuroinf.de/LabTools)
as well aso CMFSin (from http://sourceforge.net/projects/collective)
Unpack them to 'ZOPEHOME/lib/python/Products'. The rest of the installation will be done by the scripts.
- Depending on your combination of CMF and Plone versions there can be a problem with 'ScriptSite.py's 'addUsers' function. See its source code for a more detailed comment and how to resolve this.
- I still don't know how to add a comment via 'rscript_site.py'.
Enjoy! Berlin, September 2003
Released Jan 18, 2010 — tested with Plone 2.0, Plone 1.0
Re-release of the version originally published on neuroinf.de in 2003
More about this release…
- Get scriptingCMF for all platforms
- If you are using Plone 3.2 or higher, you probably want to install this product with buildout. See our tutorial on installing add-on products with buildout for more information.