36 NAME=
"download_checkmd5.py" 38 import urllib, hashlib, os, sys
39 from optparse
import OptionParser
42 parser = OptionParser(usage=
"usage: %prog URI dest [md5sum]", prog=NAME)
43 options, args = parser.parse_args()
48 uri, dest, md5sum = args
50 parser.error(
"wrong number of arguments")
53 d = os.path.dirname(dest)
54 if len(d)
and not os.path.exists(d):
58 if not os.path.exists(dest):
59 sys.stdout.write(
'[rosbuild] Downloading %s to %s...'%(uri, dest))
61 urllib.urlretrieve(uri, dest)
62 sys.stdout.write(
'Done\n')
66 m = hashlib.md5(open(dest).read())
69 print(
'[rosbuild] Checking md5sum on %s'%(dest))
73 print(
'[rosbuild] WARNING: md5sum mismatch (%s != %s); re-downloading file %s' % (d, md5sum, dest))
77 urllib.urlretrieve(uri, dest)
78 m = hashlib.md5(open(dest).read())
82 print(
'[rosbuild] ERROR: md5sum mismatch (%s != %s) on %s; aborting' % (d, md5sum, dest))
88 if __name__ ==
'__main__':