|
8 | 8 | from tempfile import NamedTemporaryFile
|
9 | 9 |
|
10 | 10 | import requests
|
| 11 | +from cachecontrol import CacheControl |
| 12 | +from cachecontrol.caches import FileCache |
11 | 13 | from typing import Any, Callable, Dict, Iterable, List, Set, Text, Tuple, Union
|
12 | 14 |
|
13 | 15 | import schema_salad.validate as validate
|
@@ -144,13 +146,28 @@ def trim_listing(obj):
|
144 | 146 |
|
145 | 147 | # Download http Files
|
146 | 148 | def downloadHttpFile(httpurl):
|
147 |
| - r = requests.get(httpurl, stream=True) |
148 |
| - with NamedTemporaryFile(mode='wb', delete=False) as f: |
149 |
| - for chunk in r.iter_content(chunk_size=16384): |
150 |
| - if chunk: # filter out keep-alive new chunks |
151 |
| - f.write(chunk) |
152 |
| - r.close() |
153 |
| - return f.name |
| 149 | + cache_session = None |
| 150 | + if "HOME" in os.environ: |
| 151 | + cache_session = CacheControl( |
| 152 | + requests.Session(), |
| 153 | + cache=FileCache( |
| 154 | + os.path.join(os.environ["HOME"], ".cache", "cwltool"))) |
| 155 | + elif "TMP" in os.environ: |
| 156 | + cache_session = CacheControl( |
| 157 | + requests.Session(), |
| 158 | + cache=FileCache(os.path.join(os.environ["TMP"], ".cache", "cwltool"))) |
| 159 | + else: |
| 160 | + cache_session = CacheControl( |
| 161 | + requests.Session(), |
| 162 | + cache=FileCache("/tmp", ".cache", "cwltool")) |
| 163 | + |
| 164 | + r = cache_session.get(httpurl, stream=True) |
| 165 | + with NamedTemporaryFile(mode='wb', delete=False) as f: |
| 166 | + for chunk in r.iter_content(chunk_size=16384): |
| 167 | + if chunk: # filter out keep-alive new chunks |
| 168 | + f.write(chunk) |
| 169 | + r.close() |
| 170 | + return f.name |
154 | 171 |
|
155 | 172 | class PathMapper(object):
|
156 | 173 | """Mapping of files from relative path provided in the file to a tuple of
|
|
0 commit comments