changeset 15922:2022366b513c

mx: add verbose mode to download helper
author Bernhard Urban <bernhard.urban@jku.at>
date Tue, 27 May 2014 12:14:54 +0200
parents 6d8c901814eb
children d0c7bd38e700
files mxtool/URLConnectionDownload.java mxtool/mx.py
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mxtool/URLConnectionDownload.java	Tue May 27 12:08:11 2014 +0200
+++ b/mxtool/URLConnectionDownload.java	Tue May 27 12:14:54 2014 +0200
@@ -42,9 +42,11 @@
 	 *            successful one
 	 */
     public static void main(String[] args) {
-    	File path = new File(args[0]);
-    	String[] urls = new String[args.length - 1];
-    	System.arraycopy(args, 1, urls, 0, urls.length);
+        File path = new File(args[0]);
+        boolean verbose = args[1].equals("-v");
+        int offset = verbose ? 2 : 1;
+        String[] urls = new String[args.length - offset];
+        System.arraycopy(args, offset, urls, 0, urls.length);
 
         File parent = path.getParentFile();
         makeDirectory(parent);
@@ -92,8 +94,10 @@
                 int n = 0;
                 while ((read = in.read(buf)) != -1) {
                     n += read;
-                    long percent = ((long) n * 100 / size);
-                    System.err.print("\r " + n + " bytes " + (size == -1 ? "" : " (" + percent + "%)"));
+                    if (verbose) {
+                        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 May 27 12:08:11 2014 +0200
+++ b/mxtool/mx.py	Tue May 27 12:14:54 2014 +0200
@@ -1887,14 +1887,17 @@
         os.makedirs(d)
 
 
-    if sys.stderr.isatty() and not path.endswith(os.sep):
+    if not path.endswith(os.sep):
         # 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, nonZeroIsFatal=False) == 0:
+        verbose = []
+        if sys.stderr.isatty():
+            verbose.append("-v")
+        if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + verbose + urls, nonZeroIsFatal=False) == 0:
             return
 
     def url_open(url):