diff options
author | Scott Roland <scott@hackonteur.com> | 2015-12-05 00:06:48 +0000 |
---|---|---|
committer | Scott Roland <scott@hackonteur.com> | 2015-12-05 00:06:48 +0000 |
commit | dd5a31bf62887cccf61b57b24ea680429f18c657 (patch) | |
tree | 885f477bf480ce89f2d57a00cc3f64ae232cd20d /contrib | |
parent | cb8e8fb360ccdb6a1633cac4c9f4945e0823d776 (diff) | |
download | tigervnc-dd5a31bf62887cccf61b57b24ea680429f18c657.tar.gz tigervnc-dd5a31bf62887cccf61b57b24ea680429f18c657.zip |
Replace external wget with native Python version
This makes it easier to handle common exceptions. I was motivated
because the Mesa URL is currently broken and wasn't handled well.
Implementation mostly copied from here:
http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/xorg/download-xorg-7.5 | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/contrib/xorg/download-xorg-7.5 b/contrib/xorg/download-xorg-7.5 index 702b3c2b..65967d28 100755 --- a/contrib/xorg/download-xorg-7.5 +++ b/contrib/xorg/download-xorg-7.5 @@ -3,6 +3,8 @@ import os import glob +import sys +import urllib2 #INDI = "http://ftp.sunet.se/pub/X11/ftp.x.org/individual" INDI = "http://ftp.x.org/pub/individual/" @@ -63,6 +65,39 @@ packages = { "freetype": "http://downloads.sourceforge.net/freetype/freetype-2.4.2.tar.bz2", } +# Python-based replacement for wget, which allows us to catch exceptions +def webget(url, file_name): + file_name = "%s/%s" % (os.getcwd(), file_name) + print "Downloading: %s" % (url) + try: + u = urllib2.urlopen(url) + except urllib2.URLError: + print sys.exc_info()[0] + sys.exit("ERROR: Unable to open URL: %s" % url) + try: + f = open(file_name, 'wb') + except IOError: + sys.exit("ERROR: Unable to save to: %s" % file_name) + else: + meta = u.info() + file_size = int(meta.getheaders("Content-Length")[0]) + print " Saving as: %s Bytes: %s" % (file_name, file_size) + + file_size_dl = 0 + block_sz = 4096 + while True: + buffer = u.read(block_sz) + if not buffer: + break + + file_size_dl += len(buffer) + f.write(buffer) + status = r" Progress: %7d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) + status = status + chr(8)*(len(status)+1) + print status, + + f.close() + print status def main(): @@ -79,7 +114,7 @@ def main(): else : fname = pkg + ".tar.gz" if not os.path.exists(fname): - assert 0 == os.spawnvp(os.P_WAIT, "wget", ["-N", "-c", "-O", fname, loc]) + webget(loc, fname) os.chdir(cwd) main() |