# HG changeset patch # User Doug Simon # Date 1325602162 -3600 # Node ID 148fa38782e87f2e2e1b4414e34a48f7bbbd0fc7 # Parent ac5c2bdfcca2878ebd165021e4152e2b4059919b Downloads are attempted via Java first since it shows a progress counter. diff -r ac5c2bdfcca2 -r 148fa38782e8 mxtool/URLConnectionDownload.java --- a/mxtool/URLConnectionDownload.java Tue Jan 03 13:54:11 2012 +0100 +++ b/mxtool/URLConnectionDownload.java Tue Jan 03 15:49:22 2012 +0100 @@ -75,7 +75,7 @@ for (String s : urls) { try { - System.err.println("Downloading " + s + " to " + path + proxyMsg); + System.err.println("Downloading " + s + " to " + path + proxyMsg); URL url = new URL(s); URLConnection conn = url.openConnection(); // 10 second timeout to establish connection @@ -88,7 +88,8 @@ int n = 0; while ((read = in.read(buf)) != -1) { n += read; - System.err.print("\r " + n + " bytes " + (size == -1 ? "" : " ( " + (n * 100 / size) + "%)")); + long percent = ((long) n * 100 / size); + System.err.print("\r " + n + " bytes " + (size == -1 ? "" : " (" + percent + "%)")); out.write(buf, 0, read); } System.err.println(); diff -r ac5c2bdfcca2 -r 148fa38782e8 mxtool/mx.py --- a/mxtool/mx.py Tue Jan 03 13:54:11 2012 +0100 +++ b/mxtool/mx.py Tue Jan 03 15:49:22 2012 +0100 @@ -710,6 +710,16 @@ if d != '' and not exists(d): os.makedirs(d) + # Try it with the Java tool first since it can show a progress counter + myDir = dirname(__file__) + + javaSource = join(myDir, 'URLConnectionDownload.java') + javaClass = join(myDir, 'URLConnectionDownload.class') + if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): + subprocess.check_call([java().javac, '-d', myDir, javaSource]) + if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + urls) == 0: + return + def url_open(url): userAgent = 'Mozilla/5.0 (compatible)' headers = { 'User-Agent' : userAgent } @@ -744,17 +754,9 @@ except zipfile.BadZipfile as e: log('Error in zip file downloaded from ' + url + ': ' + str(e)) - # now try it with Java - urllib2 does not handle meta refreshes which are used by Sourceforge - myDir = dirname(__file__) - - javaSource = join(myDir, 'URLConnectionDownload.java') - javaClass = join(myDir, 'URLConnectionDownload.class') - if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): - subprocess.check_call([java().javac, '-d', myDir, javaSource]) - if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + urls) != 0: - abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + - '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') - + abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + + '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') + def update_file(path, content): """ Updates a file with some given content if the content differs from what's in