Cache the file specified by path. Creates a copy of the file in the datasource cache.
(self, path)
| 316 | return bool(scheme and netloc) |
| 317 | |
| 318 | def _cache(self, path): |
| 319 | """Cache the file specified by path. |
| 320 | |
| 321 | Creates a copy of the file in the datasource cache. |
| 322 | |
| 323 | """ |
| 324 | # We import these here because importing them is slow and |
| 325 | # a significant fraction of numpy's total import time. |
| 326 | import shutil |
| 327 | from urllib.request import urlopen |
| 328 | |
| 329 | upath = self.abspath(path) |
| 330 | |
| 331 | # ensure directory exists |
| 332 | if not os.path.exists(os.path.dirname(upath)): |
| 333 | os.makedirs(os.path.dirname(upath)) |
| 334 | |
| 335 | # TODO: Doesn't handle compressed files! |
| 336 | if self._isurl(path): |
| 337 | with urlopen(path) as openedurl: |
| 338 | with _open(upath, 'wb') as f: |
| 339 | shutil.copyfileobj(openedurl, f) |
| 340 | else: |
| 341 | shutil.copyfile(path, upath) |
| 342 | return upath |
| 343 | |
| 344 | def _findfile(self, path): |
| 345 | """Searches for ``path`` and returns full path if found. |