comparison mxtool/mx.py @ 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 a9781031ecf1
children 674d4065e9fb
comparison
equal deleted inserted replaced
15921:6d8c901814eb 15922:2022366b513c
1885 d = dirname(path) 1885 d = dirname(path)
1886 if d != '' and not exists(d): 1886 if d != '' and not exists(d):
1887 os.makedirs(d) 1887 os.makedirs(d)
1888 1888
1889 1889
1890 if sys.stderr.isatty() and not path.endswith(os.sep): 1890 if not path.endswith(os.sep):
1891 # Try it with the Java tool first since it can show a progress counter 1891 # Try it with the Java tool first since it can show a progress counter
1892 myDir = dirname(__file__) 1892 myDir = dirname(__file__)
1893 javaSource = join(myDir, 'URLConnectionDownload.java') 1893 javaSource = join(myDir, 'URLConnectionDownload.java')
1894 javaClass = join(myDir, 'URLConnectionDownload.class') 1894 javaClass = join(myDir, 'URLConnectionDownload.class')
1895 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): 1895 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
1896 subprocess.check_call([java().javac, '-d', myDir, javaSource]) 1896 subprocess.check_call([java().javac, '-d', myDir, javaSource])
1897 if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + urls, nonZeroIsFatal=False) == 0: 1897 verbose = []
1898 if sys.stderr.isatty():
1899 verbose.append("-v")
1900 if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + verbose + urls, nonZeroIsFatal=False) == 0:
1898 return 1901 return
1899 1902
1900 def url_open(url): 1903 def url_open(url):
1901 userAgent = 'Mozilla/5.0 (compatible)' 1904 userAgent = 'Mozilla/5.0 (compatible)'
1902 headers = {'User-Agent' : userAgent} 1905 headers = {'User-Agent' : userAgent}