[Zope] RE: Creating Linux DIR

Tran, Mike MTran@shufflemaster.com
Tue, 25 Jun 2002 17:44:38 -0700


Howdy folks,

I've followed Kapil's suggestions below and created an external
method called mkdirLinux:

#mkdirLinux.py
#python script to make linux DIR
import os
script_command='mkdir /home/test/%s'

def mkdirLinux(arg):
   os.system(script_command%arg)
#end of mkdirLinux.py

Form Data:
<form action="doMkdir" method="post">
<input name="desiredDir" type="text" size="25">
<input type="submit" value="Submit!">
</form>

doMkdir method:
<dtml-if "portal_membership.getAuthenticatedMember().has_role('createDIR')">
<dtml-call "mkdirLinux(arg=desiredDir)">
<dtml-else>
<h3>Permission Denied!</h3>
</dtml-if>

The "doMkdir" method was called without any error.  However, the desired
Linux directory did not get created.  For testing purposes I've set
/home/test/ to chmod 777.

My Python is not very good.  Does anyone have any ideas what i am doing
wrong?
I just wanted to allow people with the role "createDIR" to create a linux
dir.

thanks,

Mike


> unrestricted python code  is needed (external method,
> or product). if you don't care about the response from
> the shell script then using os.system will do the
> trick.. please validate your input from the web before
> passing to something like this...
>
> import os
> script_command = 'mkdir /root/path/%s'
>
> def execute_my_script(arg):
>    os.system(script_command%arg)
>
> if you need to process output try one of the popen
> modules (see docs on python.org). ZCVS has a nice
> abstraction over this in its ShellCommandProcessor;
>
> hth
>
> -k
>
> --- "Tran, Mike" <mtran@shufflemaster.com> wrote:
> > Hi All,
> >
> > How do i create a method that will excute a shell
> > script when called?
> > I just wanted to run a local shell script when a
> > user clicks on a button.
> >
> > Appreciate any suggestion,
> >
> > Mike
>