Browse Source

g.extension: fix proxy support for downloading zip from url (contributed by Anika Bettge)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74116 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 6 years ago
parent
commit
6084e85af4
2 changed files with 11 additions and 5 deletions
  1. 2 2
      scripts/g.extension/g.extension.html
  2. 9 3
      scripts/g.extension/g.extension.py

+ 2 - 2
scripts/g.extension/g.extension.html

@@ -149,14 +149,14 @@ g.extension r.stream.distance
 Example for an open http proxy:
 <div class="code"><pre>
 # syntax: http://proxyurl:proxyport
-g.extension extension=r.stream.distance proxy="http://proxy.example.com:8080"
+g.extension extension=r.stream.distance proxy="http=http://proxy.example.com:8080"
 </pre></div>
 
 <p>
 Example for a proxy with proxy authentication:
 <div class="code"><pre>
 # syntax: http://username:password@proxyurl:proxyport
-g.extension extension=r.stream.distance proxy="http://username:password@proxy.example.com:8080"
+g.extension extension=r.stream.distance proxy="http=http://username:password@proxy.example.com:8080"
 </pre></div>
 
 <h3>Managing the extensions</h3>

+ 9 - 3
scripts/g.extension/g.extension.py

@@ -138,6 +138,7 @@ import tempfile
 from distutils.dir_util import copy_tree
 
 try:
+    import requests, zipfile
     from urllib2 import HTTPError, URLError, ProxyHandler, build_opener
     from urllib import urlopen, urlretrieve
 except ImportError:
@@ -1113,10 +1114,15 @@ def download_source_code(source, url, name, outdev,
     elif source in ['remote_zip', 'official']:
         # we expect that the module.zip file is not by chance in the archive
         zip_name = os.path.join(tmpdir, 'extension.zip')
-        f, h = urlretrieve(url, zip_name)
-        if h.get('content-type', '') != 'application/zip':
+        ses = requests.Session()
+        if 'PROXIES' in globals():
+            ses.proxies = PROXIES
+        res = ses.get(url, stream=True)
+        if str(res.status_code) != '200':
             grass.fatal(_("Extension <%s> not found") % name)
-
+        zipcontent = res.content
+        with open(zip_name, "wb") as f:
+            f.write(zipcontent)
         extract_zip(name=zip_name, directory=directory, tmpdir=tmpdir)
         fix_newlines(directory)
     elif source.startswith('remote_') and \