Return absolute path of file in the DataSource directory. If `path` is a URL, then `abspath` will return either the location the file exists locally or the location it would exist when opened using the `open` method. Parameters ---------- pa
(self, path)
| 369 | return None |
| 370 | |
| 371 | def abspath(self, path): |
| 372 | """ |
| 373 | Return absolute path of file in the DataSource directory. |
| 374 | |
| 375 | If `path` is a URL, then `abspath` will return either the location |
| 376 | the file exists locally or the location it would exist when opened |
| 377 | using the `open` method. |
| 378 | |
| 379 | Parameters |
| 380 | ---------- |
| 381 | path : str or pathlib.Path |
| 382 | Can be a local file or a remote URL. |
| 383 | |
| 384 | Returns |
| 385 | ------- |
| 386 | out : str |
| 387 | Complete path, including the `DataSource` destination directory. |
| 388 | |
| 389 | Notes |
| 390 | ----- |
| 391 | The functionality is based on `os.path.abspath`. |
| 392 | |
| 393 | """ |
| 394 | # We do this here to reduce the 'import numpy' initial import time. |
| 395 | from urllib.parse import urlparse |
| 396 | |
| 397 | # TODO: This should be more robust. Handles case where path includes |
| 398 | # the destpath, but not other sub-paths. Failing case: |
| 399 | # path = /home/guido/datafile.txt |
| 400 | # destpath = /home/alex/ |
| 401 | # upath = self.abspath(path) |
| 402 | # upath == '/home/alex/home/guido/datafile.txt' |
| 403 | |
| 404 | # handle case where path includes self._destpath |
| 405 | splitpath = path.split(self._destpath, 2) |
| 406 | if len(splitpath) > 1: |
| 407 | path = splitpath[1] |
| 408 | scheme, netloc, upath, uparams, uquery, ufrag = urlparse(path) |
| 409 | netloc = self._sanitize_relative_path(netloc) |
| 410 | upath = self._sanitize_relative_path(upath) |
| 411 | return os.path.join(self._destpath, netloc, upath) |
| 412 | |
| 413 | def _sanitize_relative_path(self, path): |
| 414 | """Return a sanitised relative path for which |