summaryrefslogtreecommitdiff
path: root/src/python/gudhi/datasets
diff options
context:
space:
mode:
authorHind-M <hind.montassif@gmail.com>2021-06-04 15:06:57 +0200
committerHind-M <hind.montassif@gmail.com>2021-06-04 15:06:57 +0200
commitf7b4d9f3ed0b0c386204077ea53a22e2dba527fc (patch)
treed723c78668d90cfef06a2c05033d249a6ff32521 /src/python/gudhi/datasets
parentbbe2e25a204be50eb422db71b4cf314b92797d4e (diff)
Check if the wanted file already exists locally before downloading
Diffstat (limited to 'src/python/gudhi/datasets')
-rw-r--r--src/python/gudhi/datasets/remote.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/python/gudhi/datasets/remote.py b/src/python/gudhi/datasets/remote.py
index fdd20f74..b266467d 100644
--- a/src/python/gudhi/datasets/remote.py
+++ b/src/python/gudhi/datasets/remote.py
@@ -60,20 +60,24 @@ def fetch(url, filename, dirname = "remote_datasets", file_checksum = None):
file_path: string
Full path of the created file.
"""
- if not exists(dirname):
- makedirs(dirname)
file_path = join(dirname, filename)
- urlretrieve(url, file_path)
-
- if file_checksum is not None:
- checksum = _checksum_sha256(file_path)
- if file_checksum != checksum:
- raise IOError("{} has a SHA256 checksum : {}, "
- "different from expected : {}."
- "The file may be corrupted or the given url may be wrong !".format(file_path, checksum,
- file_checksum))
+ # Check that an existing file does not already exist at file_path
+ if not exists(file_path):
+ # Create directory if not existing
+ if not exists(dirname):
+ makedirs(dirname)
+
+ urlretrieve(url, file_path)
+
+ if file_checksum is not None:
+ checksum = _checksum_sha256(file_path)
+ if file_checksum != checksum:
+ raise IOError("{} has a SHA256 checksum : {}, "
+ "different from expected : {}."
+ "The file may be corrupted or the given url may be wrong !".format(file_path, checksum,
+ file_checksum))
return file_path