changeset 4188:148fa38782e8

Downloads are attempted via Java first since it shows a progress counter.
author Doug Simon <doug.simon@oracle.com>
date Tue, 03 Jan 2012 15:49:22 +0100
parents ac5c2bdfcca2
children de9f8d8e4172
files mxtool/URLConnectionDownload.java mxtool/mx.py
diffstat 2 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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