Browse Source

r.in.wms: fix cap_file option

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@37064 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 years ago
parent
commit
1d22ca938c
1 changed files with 14 additions and 3 deletions
  1. 14 3
      scripts/r.in.wms/r.in.wms.py

+ 14 - 3
scripts/r.in.wms/r.in.wms.py

@@ -192,14 +192,22 @@ def list_layers():
     
     # download capabilities file
     grass.verbose("List of layers for server <%s>:" % options['mapserver'])
-    cap_file = urllib.urlopen(options['mapserver'] + '?' + qstring)
-    if not cap_file:
+    url = options['mapserver'] + '?' + qstring
+    try:
+        if options['cap_file']:
+            cap_file = urllib.urlretrieve(url, options['cap_file'])
+        else:
+            cap_file = urllib.urlopen(url, options['mapserver'] + '?' + qstring)
+    except IOError:
         grass.fatal("Unable to get capabilities of '%s'" % options['mapserver'])
     
     # parse file with sax
     cap_xml = wms_parse.ProcessCapFile()
     try:
-        xml.sax.parse(cap_file, cap_xml)
+        if options['cap_file']:
+            xml.sax.parse(options['cap_file'], cap_xml)
+        else:
+            xml.sax.parse(cap_file, cap_xml)
     except xml.sax.SAXParseException, err:
         grass.fatal("Reading capabilities failed. "
                     "Unable to parse XML document: %s" % err)
@@ -214,6 +222,9 @@ def main():
     elif not options['output']:
         grass.fatal("No output map specified")
     
+    if options['cap_file'] and not flags['l']:
+        grass.warning("Option <cap_file> ignored. It requires '-l' flag.")
+    
     # set directory for download
     if not options['folder']:
         options['folder'] = os.path.join(grass.gisenv()['GISDBASE'], 'wms_download')