Skip to content

Commit

Permalink
fix: use urlretreive when curl or wget are not available, closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Aug 11, 2017
1 parent c398091 commit 8531be1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ipyvolume/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
if not os.path.exists(data_dir):
os.makedirs(data_dir)

try:
from urllib import urlretrieve
except ImportError:
from urllib.request import urlretrieve


osname = dict(darwin="osx", linux="linux", windows="windows")[platform.system().lower()]

Expand Down Expand Up @@ -35,8 +40,8 @@ def download(self, force=False):
print("Download failed, exit code was: " +str(code) +" will try with curl")
code = os.system(self.download_command_curl())
if not os.path.exists(self.path):
print("Download failed again, exit code was: " +str(code) +" giving up")

print("Download failed again, exit code was: " +str(code) +" using urlretrieve")
self.download_urlretrieve()

def fetch(self):
self.download()
Expand All @@ -59,16 +64,18 @@ def fetch(self):
return self

def download_command_wget(self):
return "wget --progress=bar:force -c -P %s %s" % (data_dir, self.url)
return "wget --progress=bar:force -c -P %s %s" % (data_dir, self.url+"w")

def download_command_curl(self):
return "cd %s; curl -O -L %s" % (data_dir, self.url)
return "cd %s; curl -O -L %s" % (data_dir, self.url+"w")

def download_urlretrieve(self):
urlretrieve(self.url, self.path)

hdz2000 = Dataset("hdz2000")
aquariusA2 = Dataset("aquarius-A2")
egpbosLCDM = Dataset("egpbos-LCDM")
zeldovich = Dataset("zeldovich", density=False)
animated_stream = Dataset("stream-animation", density=False, numpy=True)

# low poly cat from: https://sketchfab.com/models/1e7143dfafd04ff4891efcb06949a0b4#
# low poly cat from: https://sketchfab.com/models/1e7143dfafd04ff4891efcb06949a0b4#

0 comments on commit 8531be1

Please sign in to comment.