39 from optparse
import OptionParser
41 NAME =
'download_checkmd5.py'
45 parser = OptionParser(usage=
'usage: %prog URI dest [md5sum]', prog=NAME)
46 options, args = parser.parse_args()
51 uri, dest, md5sum = args
53 parser.error(
'wrong number of arguments')
56 d = os.path.dirname(dest)
57 if len(d)
and not os.path.exists(d):
61 if not os.path.exists(dest):
62 sys.stdout.write(
'[rosbuild] Downloading %s to %s...' % (uri, dest))
64 urllib.request.urlretrieve(uri, dest)
65 sys.stdout.write(
'Done\n')
69 m = hashlib.md5(open(dest,
"rb").read())
72 print(
'[rosbuild] Checking md5sum on %s' % (dest))
76 print(
'[rosbuild] WARNING: md5sum mismatch (%s != %s); re-downloading file %s' % (d, md5sum, dest))
80 urllib.request.urlretrieve(uri, dest)
81 m = hashlib.md5(open(dest).read())
85 print(
'[rosbuild] ERROR: md5sum mismatch (%s != %s) on %s; aborting' % (d, md5sum, dest))
91 if __name__ ==
'__main__':