[Ipython-tickets] [IPython] #137: pushModule on windows fail because tar command doesn't exists
IPython
ipython-tickets@scipy....
Sat Jun 16 12:06:19 CDT 2007
#137: pushModule on windows fail because tar command doesn't exists
----------------------+-----------------------------------------------------
Reporter: pep | Owner: fperez
Type: defect | Status: closed
Priority: normal | Milestone:
Component: chainsaw | Version:
Severity: normal | Resolution: wontfix
Keywords: |
----------------------+-----------------------------------------------------
Changes (by bgranger):
* status: new => closed
* resolution: => wontfix
Old description:
> By the way, I've tried your pushModule method, but it doesn't works
> under windows client because tar binary doesn't exist!
> example:[[BR]]
> import fileserver[[BR]]
> rc.pushModule(fileserver)[[BR]]
>
> In [11]: rc.pushModule(fileserver)[[BR]]
> Locating the module...[[BR]]
> Module (fileserver) found in:[[BR]]
>
> 'tar' n'est pas reconnu en tant que commande interne[[BR]]
> ou externe, un programme exécutable ou un fichier de commandes.[[BR]]
> ---------------------------------------------------------------------------[[BR]]
> <type 'exceptions.IOError'> Traceback (most recent call
> last)[[BR]]
> C:\Python25\Scripts\<ipython console> in <module>()[[BR]]
> C:\Python25\lib\site-packages\ipython1\kernel\controllervanilla.py in
> pushModule(self, mod)[[BR]]
> 1291 """[[BR]]
> 1292[[BR]]
> -> 1293 tarball_name, fileString = tarModule(mod)[[BR]]
> 1294 self._pushModuleString(tarball_name, fileString)[[BR]]
> 1295[[BR]]
> C:\Python25\lib\site-packages\ipython1\kernel\util.py in
> tarModule(mod)[[BR]]
> 79 # Read the tarball into a binary string[[BR]]
> 80 tarball_name = module_name + ".tar"[[BR]]
> ---> 81 tar_file = open(tarball_name,'rb')[[BR]]
> 82 fileString = tar_file.read()[[BR]]
> 83 tar_file.close()[[BR]]
> <type 'exceptions.IOError'>: [Errno 2] No such file or
> directory:'fileserver.tar'>[[BR]]
>
>
> Can't we use here the tarfile python library to make your pushModule
> method work under windows?[[BR]]
> something like this perhaps?:[[BR]]
>
> #code for client side[[BR]]
> import tarfile[[BR]]
> f_ptr = tarfile.open('mytarfile.tar','w')[[BR]]
> f_ptr.add('server.py')[[BR]]
> f_ptr.close()[[BR]]
>
> #code for remote server side[[BR]]
> import tarfile[[BR]]
> f_ptr = tarfile.open('mytarfile.tar','r')[[BR]]
> for tarinfo in f_ptr:[[BR]]
> f_ptr.extract(tarinfo,r'./')[[BR]]
> f_ptr.close()[[BR]]
>
> The method will not be very efficient because of file write time, so if
> you've got a better idea?[[BR]]
> Frm this link here are more infos:[[BR]]
> http://www.gossamer-threads.com/lists/python/python/554820?page=last
> [[BR]]
>
> You can create a TarInfo object directly, and use addfile with a StringIO
> object: [[BR]]
>
> import tarfile[[BR]]
> from cStringIO import StringIO [[BR]]
>
> data = "Some text, maybe containing\ntwo or more lines\n" + "The quick
> brown fox jumps over the lazy dog\n" * 20
> fobj = StringIO(data) [[BR]]
>
> tar = tarfile.open("sample.tar", "w") [[BR]]
> tarinfo = tarfile.TarInfo("foo.txt") [[BR]]
> tarinfo.size = len(data) [[BR]]
> tar.addfile(tarinfo, fobj) [[BR]]
> tar.close() [[BR]]
>
> tar = tarfile.open("sample.tar", "r") [[BR]]
> tar.list() [[BR]]
> foo = tar.extractfile("foo.txt") [[BR]]
> data_read = foo.read() [[BR]]
> print "foo.txt:\n%s" % data_read [[BR]]
> tar.close() [[BR]]
> assert data == data_read [[BR]]
New description:
By the way, I've tried your pushModule method, but it doesn't works
under windows client because tar binary doesn't exist!
example:[[BR]]
import fileserver[[BR]]
rc.pushModule(fileserver)[[BR]]
In [11]: rc.pushModule(fileserver)[[BR]]
Locating the module...[[BR]]
Module (fileserver) found in:[[BR]]
'tar' n'est pas reconnu en tant que commande interne[[BR]]
ou externe, un programme exécutable ou un fichier de commandes.[[BR]]
---------------------------------------------------------------------------[[BR]]
<type 'exceptions.IOError'> Traceback (most recent call
last)[[BR]]
C:\Python25\Scripts\<ipython console> in <module>()[[BR]]
C:\Python25\lib\site-packages\ipython1\kernel\controllervanilla.py in
pushModule(self, mod)[[BR]]
1291 """[[BR]]
1292[[BR]]
-> 1293 tarball_name, fileString = tarModule(mod)[[BR]]
1294 self._pushModuleString(tarball_name, fileString)[[BR]]
1295[[BR]]
C:\Python25\lib\site-packages\ipython1\kernel\util.py in
tarModule(mod)[[BR]]
79 # Read the tarball into a binary string[[BR]]
80 tarball_name = module_name + ".tar"[[BR]]
---> 81 tar_file = open(tarball_name,'rb')[[BR]]
82 fileString = tar_file.read()[[BR]]
83 tar_file.close()[[BR]]
<type 'exceptions.IOError'>: [Errno 2] No such file or
directory:'fileserver.tar'>[[BR]]
Can't we use here the tarfile python library to make your pushModule
method work under windows?[[BR]]
something like this perhaps?:[[BR]]
#code for client side[[BR]]
import tarfile[[BR]]
f_ptr = tarfile.open('mytarfile.tar','w')[[BR]]
f_ptr.add('server.py')[[BR]]
f_ptr.close()[[BR]]
#code for remote server side[[BR]]
import tarfile[[BR]]
f_ptr = tarfile.open('mytarfile.tar','r')[[BR]]
for tarinfo in f_ptr:[[BR]]
f_ptr.extract(tarinfo,r'./')[[BR]]
f_ptr.close()[[BR]]
The method will not be very efficient because of file write time, so if
you've got a better idea?[[BR]]
Frm this link here are more infos:[[BR]]
http://www.gossamer-threads.com/lists/python/python/554820?page=last
[[BR]]
You can create a TarInfo object directly, and use addfile with a StringIO
object: [[BR]]
import tarfile[[BR]]
from cStringIO import StringIO [[BR]]
data = "Some text, maybe containing\ntwo or more lines\n" + "The quick
brown fox jumps over the lazy dog\n" * 20
fobj = StringIO(data) [[BR]]
tar = tarfile.open("sample.tar", "w") [[BR]]
tarinfo = tarfile.TarInfo("foo.txt") [[BR]]
tarinfo.size = len(data) [[BR]]
tar.addfile(tarinfo, fobj) [[BR]]
tar.close() [[BR]]
tar = tarfile.open("sample.tar", "r") [[BR]]
tar.list() [[BR]]
foo = tar.extractfile("foo.txt") [[BR]]
data_read = foo.read() [[BR]]
print "foo.txt:\n%s" % data_read [[BR]]
tar.close() [[BR]]
assert data == data_read [[BR]]
Comment:
pushModule has been removed because it was too buggy.
--
Ticket URL: <http://projects.scipy.org/ipython/ipython/ticket/137#comment:1>
IPython <http://ipython.scipy.org>
The IPython interactive Python system
More information about the Ipython-tickets
mailing list