0

I'm trying to write a short script that will recover a repository. The backup script generates dump files that are gzipped.

To apply a dump I need to call this command:

svnadmin load < myfile 

but since myfile is a gzipped one, I need to unzip it for the command to work.

Now here comes my question, is the command on top same as

subprocess.call(['svnadmin','load', myfilecontents]) 

This way I will avoid the need to unzip the file, to a temporary location. or should I be using

subprocess.call(['svnadmin','load'],stdin=gzip.open(myfile)) 
1
  • 2
    zcat myfile | svnadmin load is more likely to be the command you want to model with subprocess... (or gzip -dc, if for some reason, your distro of choice doesn't provide zcat) Commented Nov 12, 2013 at 19:55

1 Answer 1

1

You can't point stdin at a GzipFile, but you can copy the data yourself

In [5]: cmd=subprocess.Popen(["od", "-cx"], stdin=subprocess.PIPE) In [6]: data=gzip.open("/tmp/hello.gz") In [8]: cmd.stdin.write(data.read()) In [9]: cmd.stdin.close() 0000000 h i \n 6968 000a 0000003 

Alternatively, you could use Popen.communicate():

In [11]: cmd=subprocess.Popen(["od", "-cx"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) In [12]: data=gzip.open("/tmp/hello.gz") In [13]: cmd.communicate(data.read()) Out[13]: ('0000000 h i \\n\n 6968 000a\n0000003\n', '') 
Sign up to request clarification or add additional context in comments.

1 Comment

Agreed, and if twalberg creates an answer based on his comment, I'd probably upvote it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.