[Zope] adding a python script from a python script

Jason Cunliffe jasonic@nomadicsltd.com
Sun, 1 Apr 2001 01:07:11 -0500


----- Original Message -----
From: Ronald L. Chichester <complaw@hal-pc.org>


> This is a frequently asked question.
>
> There is a good write up about using Python Scripts in the ZopeBook
>
> Chapter 5 (Creating Basic Zope Applications (has examples)):
>
> http://www.zope.org/Members/michel/ZB/
>
> The API Reference (Appendix B):
>
> http://www.zope.org/Members/michel/ZB/AppendixB.dtml

Ron

Thanks for the solid tips, but alas it's hardly a well answered FAQ yet. I
had looked at the links above already. But checked them again still finding
nothing to help me.
So I tried a search on zope.org for 'manage_addPythonScript'
da:-( 

Then I entered 'manage_addPythonScript' in zope.org Resources which returned 3 links including my post and your reply.. but hitting  'next' led to some more complex techniques in a post 
From:  Jim Washington <jwashin@v...>
Date:  Mon Jan 29, 2001 7:54pm
Subject:  Re: [Zope] porting from Python Methods to PythonScripts in 2.3.0;LoginManager too
http://groups.yahoo.com/group/zope/message/50218

But buried there lies the answer..
----------------------------------------------
How-To add a Python Script from a Python script

1. create Python Script "addPyScript" for example
2. in the parameter field include idname='mypyscript'
3. in the body of the script enter:

container.manage_addProduct['PythonScripts'].manage_addPythonScript(idname)
-----------------------------------------------

Ok So far so good. Since I am setting a named default, I get an error mesasge if I try it again
Error Type: Bad Request
Error Value: The id "mypyscript" is invalid--it is already in use.
So I need to check first from the pythonscript if such an object already exists in the current folder. In DTML this would be the regular

<dtml-if expr="mypyscript">
  That object already exists. Choose another name.
<dtml-else>
  ... manage_addPythonScript.. code goes here
</dtml-if> 

Please how do I do this basic task in Python Script?
I tried modifying the body ab
ove like this:

if idname:
  return 'An object called %s already exists. Please select a new name' %
idname
else:

container.manage_addProduct['PythonScripts'].manage_addPythonScript(idname)

but that is not right. How to get Python script to take the value of the
parameter field, and check for an object of that name in the same folder?

Till now, I cannot seem to find any good place for reading Python Script
examples.
I suggest it could really helpful to add a separate section at
http://www.zope.org/Documentation called 'Python Scripts'

thanks
- Jason
___________________________________________________________
Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']