Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Pipelining tar create and tar extract the "Python" way...

Reply
Thread Tools

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

 
 
Ray Van Dolson
Guest
Posts: n/a
 
      09-25-2009
On Wed, Sep 23, 2009 at 04:22:36PM -0700, Ray Van Dolson wrote:
> On Wed, Sep 23, 2009 at 03:52:11PM -0700, Ray Van Dolson wrote:
> > Hi all;
> >
> > In the land'o'shell, I can do something like the following:
> >
> > tar cvf - SrcDir | (cd /dest ; tar xvf -)
> >

>
> Bad form replying to my own post... while I'd still like to know if
> this is possible to do with the tarfile class, it seems like using
> subprocess.Popen() and calling tar from there with stdout set to PIPE
> is probably the way to go.
>
> I think this will result in the fastest way to copy files around.
> Sounds like shutil.copytree() may not be all that robust (and probably
> not very fast) in my version of Python (2.4.3 on RHEL5).
>
> Still open to creative suggestions...
>


Never found a way to do this with the tarfile class directly, but used
Popen() to call tar:

# Time for some fancy shmancy calls to tar. First create the process that
# will generate our tar file and set it to output to a PIPE.
p1 = Popen(["tar", "cf", "-", "."], cwd=u['homedir'], stdout=PIPE)

# Next, set up our consumer tar process. This one should extract its data
# in the destination directory.
p2 = Popen(["tar", "xf", "-"], cwd=new_homedir, stdin=p1.stdout)

# Go!
err = p2.communicate()[1]

Nothing groundbreaking as this is from the examples in the
documentation, but just in case anyone else stumbles across this..

Ray
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipelining tar create and tar extract the "Python" way... Ray Van Dolson Python 0 09-23-2009 10:52 PM
os.system('tar -c * | tar -C dst') ##Any other suggestions... list.repository@gmail.com Python 2 04-24-2007 10:29 PM
Version of TAR in tarfile module? TAR 1.14 or 1.15 port to Windows? Claudio Grondi Python 4 08-20-2005 08:01 PM
trouble with Archive::Tar : Can not read compressed format in tar-mode benoit Guyon Perl Misc 2 07-26-2005 01:53 PM
extract tar files? Bobby Janow Cisco 2 07-15-2003 12:49 PM



Advertisments