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

2009-09-25 Thread Ray Van Dolson
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-09-23 Thread 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
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-09-23 Thread Ray Van Dolson
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... :)

Ray
-- 
http://mail.python.org/mailman/listinfo/python-list


Python alternatives to Text::SimpleTable?

2009-02-28 Thread Ray Van Dolson
So I'm looking for an easy (read: lazy) way to generate output in nice
ASCII tables like the Text::SimpleTable[1] module in perl.  I've come
across two so far in the Python world that look promising[2][3] but I'm
wondering if anyone else out there has some recommendations for me.

Thanks,
Ray

[1] http://search.cpan.org/dist/Text-SimpleTable/lib/Text/SimpleTable.pm
[2] http://pypi.python.org/pypi/text_table/0.02
[3] http://jefke.free.fr/stuff/python/texttable/
--
http://mail.python.org/mailman/listinfo/python-list