# HG changeset patch # User Bernhard Urban # Date 1401185694 -7200 # Node ID 2022366b513c5961fe8714663f01a34e13bfc746 # Parent 6d8c901814ebafd312eaac04c4945fefa6b40e61 mx: add verbose mode to download helper diff -r 6d8c901814eb -r 2022366b513c mxtool/URLConnectionDownload.java --- 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(); diff -r 6d8c901814eb -r 2022366b513c mxtool/mx.py --- 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):