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

Discussion in 'Python' started by Ray Van Dolson, Sep 23, 2009.

  1. 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
     
    Ray Van Dolson, Sep 23, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claudio Grondi
    Replies:
    4
    Views:
    557
    Claudio Grondi
    Aug 20, 2005
  2. Replies:
    2
    Views:
    427
    Michael Hoffman
    Apr 24, 2007
  3. Ray Van Dolson
    Replies:
    0
    Views:
    826
    Ray Van Dolson
    Sep 25, 2009
  4. Simon Mullis
    Replies:
    2
    Views:
    110
    Simon Mullis
    Sep 28, 2007
  5. benoit Guyon
    Replies:
    2
    Views:
    219
    benoit Guyon
    Jul 26, 2005
Loading...

Share This Page