Hi, I am trying to call 'zip'(linux) from within my python external method. The is what I do: ### SRC ### import os src_dir = 'some_dir' cmd_apth = '/usr/bin/zip' zip_file_name = 'res.zip' os.chdir(src_dir) result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') print result ### END SRC ### the result is always 12 (zip error: Nothing to do). zip creates the directory structures in the zip file but does not put in the actual files. Now if I do an os.system instead of an os.spawnl it works, however I do not want to use it. What is going on here?? Also I have been able to use 'unzip'(Linux) in the same manner without a hitch. So what am I doing wrong here?? Why shouldnt it work?? TIA AM PS: I have played around with the Python ZipFile and zlib module. Didnt feel comfy so going with this as of now, will probably switch over later. ------------------------------------------------------------------------
You'd probably have better luck asking the Python list. This doesn't have anything to do with Zope. One suggestion: I'm not sure os.chdir has any affect on spawnl. Try passing it absolute paths instead. -Casey On Saturday 10 August 2002 05:57 am, list_subscriber@neurobs.com wrote:
Hi, I am trying to call 'zip'(linux) from within my python external method. The is what I do:
### SRC ###
import os
src_dir = 'some_dir' cmd_apth = '/usr/bin/zip' zip_file_name = 'res.zip'
os.chdir(src_dir) result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') print result
### END SRC ###
the result is always 12 (zip error: Nothing to do). zip creates the directory structures in the zip file but does not put in the actual files.
Now if I do an os.system instead of an os.spawnl it works, however I do not want to use it.
What is going on here?? Also I have been able to use 'unzip'(Linux) in the same manner without a hitch.
So what am I doing wrong here?? Why shouldnt it work??
TIA AM
PS: I have played around with the Python ZipFile and zlib module. Didnt feel comfy so going with this as of now, will probably switch over later.
------------------------------------------------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
List Subscriber @ Neurobs wrote:
Now if I do an os.system instead of an os.spawnl it works, however I do not want to use it.
try using popen instead (or popen2 or popen3 depending on what you want...)
PS: I have played around with the Python ZipFile and zlib module. Didnt feel comfy
Why not? I've made extensive use of ZipFile in the past with lots of success... cheers, Chris
List Subscriber @ Neurobs writes:
I am trying to call 'zip'(linux) from within my python external method. The is what I do:
### SRC ###
import os
src_dir = 'some_dir' cmd_apth = '/usr/bin/zip' zip_file_name = 'res.zip'
os.chdir(src_dir) result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') print result
### END SRC ###
the result is always 12 (zip error: Nothing to do). zip creates the directory structures in the zip file but does not put in the actual files. Unix processes want an additional "argument 0" which by default is the name of the program file.
Try: result = os.spawnl(os.P_WAIT,cmd_path,'zip','-rv',zip_file_name,'.') Dieter
Unix processes want an additional "argument 0" which by default is the name of the program file.
I found that out, however, heres a puzzle then: I am doing exactly the same thing while unzipping uploaded files.... ie in the code replace '/usr/bin/zip' with '/usr/bin/unzip' and hte args and the other stuff... and that seems to work everytime. If agree about the argv[0] thingy, however then my unzipping shouldnt work either. Re: Dennis' solution of using os.system, the docs say if I do a system it replaces the calling thread (I dont yet understand the meaning of replace in this context) and only resumes after returning. In a web server environ wouldnt that be dangerous as it might replace Zope's calling thread even if for some time. I confess I dont know how exactly the calling mechaninsm for external methods work, but if I was right I would have a sequential process which would be bad for a web-site I think. Re:Chris, I will try popen adn Zipfile again. Thanks all. AM
Ah, you didn't mention what you were trying to accomplish, only a mechanism. os.system() is blocking. I suppose the quick and simple hack would be to append a '&' to the command string and fire off an independent process. I don't see any simple way to test completion since there is nothing like "WAIT". -dra On Sun, 11 Aug 2002, List Subscriber @ Neurobs wrote:
Unix processes want an additional "argument 0" which by default is the name of the program file.
I found that out, however, heres a puzzle then:
I am doing exactly the same thing while unzipping uploaded files.... ie in the code replace '/usr/bin/zip' with '/usr/bin/unzip' and hte args and the other stuff... and that seems to work everytime. If agree about the argv[0] thingy, however then my unzipping shouldnt work either.
Re: Dennis' solution of using os.system, the docs say if I do a system it replaces the calling thread (I dont yet understand the meaning of replace in this context) and only resumes after returning. In a web server environ wouldnt that be dangerous as it might replace Zope's calling thread even if for some time. I confess I dont know how exactly the calling mechaninsm for external methods work, but if I was right I would have a sequential process which would be bad for a web-site I think.
Re:Chris, I will try popen adn Zipfile again.
Thanks all. AM
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Casey Duncan -
Chris Withers -
Dennis Allison -
Dieter Maurer -
List Subscriber @ Neurobs