Pipelining tar create and tar extract the "Python" way...

R

Ray Van Dolson

Hi all;

In the land'o'shell, I can do something like the following:

tar cvf - SrcDir | (cd /dest ; tar xvf -)

I'd like to learn the "Python" way to reproduce the above. Obviously I
could use the subprocess module and just call that exact command above,
but is there a way to do this with the tarfile module?

I realize I can use a StringIO object as the fileobj param then do the
extraction with the same StringIO object... but that's obviously not
the same as doing this all via a pipe as in the shell command.

I could see doing it with a fifo of some sort and having a consumer
process running that reads from the fifo and extracts with the tarfile
command as well... but that sounds overly complex.

I'd like to learn how to achieve this purely for curiosity's sake. I
realize that while the shell tar command is one of the faster ways to
recursively copy file trees around, there might be better ways to do
this from within python.. :)

Thanks,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,247
Latest member
crypto tax software1

Latest Threads

Top