[GRASS-SVN] r74116 - grass/trunk/scripts/g.extension

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 20 15:23:25 PST 2019


Author: neteler
Date: 2019-02-20 15:23:25 -0800 (Wed, 20 Feb 2019)
New Revision: 74116

Modified:
   grass/trunk/scripts/g.extension/g.extension.html
   grass/trunk/scripts/g.extension/g.extension.py
Log:
g.extension: fix proxy support for downloading zip from url (contributed by Anika Bettge)

Modified: grass/trunk/scripts/g.extension/g.extension.html
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.html	2019-02-20 20:43:01 UTC (rev 74115)
+++ grass/trunk/scripts/g.extension/g.extension.html	2019-02-20 23:23:25 UTC (rev 74116)
@@ -149,7 +149,7 @@
 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>
@@ -156,7 +156,7 @@
 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>

Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py	2019-02-20 20:43:01 UTC (rev 74115)
+++ grass/trunk/scripts/g.extension/g.extension.py	2019-02-20 23:23:25 UTC (rev 74116)
@@ -138,6 +138,7 @@
 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 @@
     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 \



More information about the grass-commit mailing list