|
5 | 5 | import stat
|
6 | 6 | import uuid
|
7 | 7 | from functools import partial
|
| 8 | +from tempfile import NamedTemporaryFile |
| 9 | + |
| 10 | +import requests |
8 | 11 | from typing import Any, Callable, Dict, Iterable, List, Set, Text, Tuple, Union
|
9 | 12 |
|
10 | 13 | import schema_salad.validate as validate
|
@@ -139,6 +142,15 @@ def trim_listing(obj):
|
139 | 142 | if obj.get("location", "").startswith("file://") and "listing" in obj:
|
140 | 143 | del obj["listing"]
|
141 | 144 |
|
| 145 | +# Download http Files |
| 146 | +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=1024): |
| 150 | + if chunk: # filter out keep-alive new chunks |
| 151 | + f.write(chunk) |
| 152 | + r.close() |
| 153 | + return f.name |
142 | 154 |
|
143 | 155 | class PathMapper(object):
|
144 | 156 | """Mapping of files from relative path provided in the file to a tuple of
|
@@ -208,15 +220,18 @@ def visit(self, obj, stagedir, basedir, copy=False, staged=False):
|
208 | 220 | self._pathmap[obj["location"]] = MapperEnt(obj["contents"], tgt, "CreateFile", staged)
|
209 | 221 | else:
|
210 | 222 | with SourceLine(obj, "location", validate.ValidationException):
|
211 |
| - # Dereference symbolic links |
212 | 223 | deref = ab
|
213 |
| - if urllib.parse.urlsplit(deref).scheme not in ['http','https']: |
| 224 | + if urllib.parse.urlsplit(deref).scheme in ['http','https']: |
| 225 | + deref = downloadHttpFile(path) |
| 226 | + else: |
| 227 | + # Dereference symbolic links |
214 | 228 | st = os.lstat(deref)
|
215 | 229 | while stat.S_ISLNK(st.st_mode):
|
216 | 230 | rl = os.readlink(deref)
|
217 | 231 | deref = rl if os.path.isabs(rl) else os.path.join(
|
218 | 232 | os.path.dirname(deref), rl)
|
219 | 233 | st = os.lstat(deref)
|
| 234 | + |
220 | 235 | self._pathmap[path] = MapperEnt(deref, tgt, "WritableFile" if copy else "File", staged)
|
221 | 236 | self.visitlisting(obj.get("secondaryFiles", []), stagedir, basedir, copy=copy, staged=staged)
|
222 | 237 |
|
|
0 commit comments