Bläddra i källkod

r.in.wms: add proxy for GDAL driver

Anika Bettge 6 år sedan
förälder
incheckning
39164b6220
2 ändrade filer med 29 tillägg och 0 borttagningar
  1. 20 0
      scripts/r.in.wms/r.in.wms.py
  2. 9 0
      scripts/r.in.wms/wms_gdal_drv.py

+ 20 - 0
scripts/r.in.wms/r.in.wms.py

@@ -145,6 +145,20 @@ This program is free software under the GNU General Public License
 #% guisection: Map style
 #%end
 
+#%option
+#% key: proxy
+#% label: HTTP proxy only GDAL driver (GDAL_HTTP_PROXY)
+#% type: string
+#% description: HTTP proxy
+#%end
+
+#%option
+#% key: proxy_user_pw
+#% label: User and password for HTTP proxy only for GDAL driver (GDAL_HTTP_PROXYUSERPWD). Must be in the form of [user name]:[password].
+#% type: string
+#% description: User and password for HTTP proxy
+#%end
+
 #%option G_OPT_F_BIN_INPUT
 #% key: capfile
 #% required: no
@@ -227,6 +241,12 @@ def main():
         wms.GetCapabilities(options)
     else:
         from wms_base import GRASSImporter
+        # set proxy
+        if options['proxy'] and options['proxy_user_pw']:
+            wms.setProxy(options['proxy'], options['proxy_user_pw'])
+        if options['proxy']:
+            wms.setProxy(options['proxy'])
+
         options['region'] = GetRegionParams(options['region'])
         fetched_map = wms.GetMap(options, flags)
 

+ 9 - 0
scripts/r.in.wms/wms_gdal_drv.py

@@ -35,6 +35,10 @@ class NullDevice():
 
 class WMSGdalDrv(WMSBase):
 
+    def setProxy(self, proxy, user_pw=None):
+        self.proxy = proxy
+        sekf.proxy_auth = user_pw
+
     def _createXML(self):
         """!Create XML for GDAL WMS driver
 
@@ -127,6 +131,11 @@ class WMSGdalDrv(WMSBase):
         temp_map = self._tempfile()
 
         xml_file = self._createXML()
+
+        if hasattr(self, 'proxy'):
+            gdal.SetConfigOption('GDAL_HTTP_PROXY', self.proxy)
+        if hasattr(self, 'proxy_auth'):
+            gdal.SetConfigOption('GDAL_HTTP_PROXYUSERPWD', self.proxy_auth)
         wms_dataset = gdal.Open(xml_file, gdal.GA_ReadOnly)
         grass.try_remove(xml_file)
         if wms_dataset is None: