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