|
6 | 6 | import fnmatch |
7 | 7 | import os |
8 | 8 | import shutil |
| 9 | +import subprocess |
9 | 10 | import sys |
10 | 11 | import tempfile |
11 | 12 | import time |
@@ -96,17 +97,28 @@ def write_file(path, content, force=True): |
96 | 97 | f.write(content) |
97 | 98 |
|
98 | 99 |
|
99 | | -def untar_to(url, path=None, tar_args=None): |
100 | | - download_cmd = " ".join(download_command(url, quote_url=True)) |
| 100 | +def untar_to(url, tar_args=None, path=None, dest_dir=None): |
101 | 101 | if tar_args: |
| 102 | + assert not (path and dest_dir) |
| 103 | + if dest_dir: |
| 104 | + if not os.path.exists(dest_dir): |
| 105 | + os.makedirs(dest_dir) |
| 106 | + tar_args.extend(['-C', dest_dir]) |
102 | 107 | if path: |
103 | | - if not os.path.exists(path): |
104 | | - os.makedirs(path) |
| 108 | + tar_args.append('-O') |
105 | 109 |
|
106 | | - untar_cmd = "tar %s" % tar_args |
107 | | - shell("%s | %s" % (download_cmd, untar_cmd)) |
| 110 | + download_cmd = download_command(url) |
| 111 | + download_p = commands.shell_process(download_cmd, stdout=subprocess.PIPE) |
| 112 | + untar_cmd = ['tar'] + tar_args |
| 113 | + if path: |
| 114 | + with open(path, 'w') as fh: |
| 115 | + shell(untar_cmd, stdin=download_p.stdout, stdout=fh) |
| 116 | + else: |
| 117 | + shell(untar_cmd, stdin=download_p.stdout) |
| 118 | + download_p.wait() |
108 | 119 | else: |
109 | | - shell("%s > '%s'" % (download_cmd, path)) |
| 120 | + cmd = download_command(url, to=path) |
| 121 | + shell(cmd) |
110 | 122 |
|
111 | 123 |
|
112 | 124 | def find_matching_directories(path, pattern, recursive): |
|
0 commit comments