Commit b1a01049 authored by Jens Kroeger's avatar Jens Kroeger
Browse files

Merge branch 'improve_download_script' into 'master'

Improve test data download script to always remove untarred folder

See merge request !174
parents 5769e32b fe0df33b
Pipeline #1102967 passed with stages
in 17 minutes and 49 seconds
#!/usr/bin/env python
#
# download raw test data files or not (depending on the moon position)
# Download raw test data files, check integrity and untar
from __future__ import print_function, unicode_literals
import hashlib
......@@ -8,6 +8,7 @@ import io
import os
import os.path
import urllib
import shutil
import sys
import tarfile
try:
......@@ -37,6 +38,8 @@ def check(path, checksum):
if not os.path.isfile(path):
return False
if not sha256(path) == checksum:
print('\'%s\' exists, wrong checksum, deleting' % path)
os.remove(path)
return False
print('\'%s\' checksum ok' % path)
return True
......@@ -64,5 +67,14 @@ if __name__ == '__main__':
else:
datasets = {_: DATASETS[_] for _ in sys.argv[1:]}
for name, checksum in datasets.items():
# Download tarball if necessary
download(name=name, checksum=checksum)
# Delete existing untarred files
target = os.path.join(BASE_TARGET, name)
if os.path.exists(target) and os.path.isdir(target):
print('\'%s\' deleting existing folder' % target)
shutil.rmtree(target)
# Untar anew from tarball
untar(name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment