Question

I am currently working on adding some features to a plone website and I would like to be able to run a python script using content rules. For example, I've written an article and I want to publish it : using a rule triggered by a condition I want to run a certain script which is not related to the object.

I have already installed Runscript but the problem is that apparently the script has to be related to the object that triggered the action.

I have a simple script that just opens a text file to write 'Hello World' in it :

with open("hello.txt", "w") as fichier:
    fichier.write("Hello world")

and plone give me the following error on my script (which works outside of plone) :

Module script, line 1, in hello
<FSPythonScript at /Plone2/hello used for /Plone2/news/azertyazert> Line 1
NameError: global name 'open' is not defined

On other scripts I also get the page I don't have sufficient rights to change the state of the article (thus triggering the condition rule).

Anyway, that was with Runscript, does anyone know either a another way to do execute scripts when rules are triggered or how to make runscript any script ?

Was it helpful?

Solution

Python scripts inside Zope / Plone run in a restricted environment. The error is thrown because you cannot open files from the filesystem there.

Use an External Method instead to point to a file-system stored script if you want to execute Python code that is not restricted.

The runscript action only uses the object as a context. Your script is free to ignore that context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top