瀏覽代碼

If is not able to get the xml of a module suggest to the user to check if the module exist

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54087 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 年之前
父節點
當前提交
f3c48dba70
共有 1 個文件被更改,包括 8 次插入3 次删除
  1. 8 3
      lib/python/pygrass/modules/__init__.py

+ 8 - 3
lib/python/pygrass/modules/__init__.py

@@ -20,6 +20,7 @@ from xml.etree.ElementTree import fromstring
 
 import grass
 
+from pygrass.errors import GrassError
 
 #
 # this dictionary is used to extract the value of interest from the xml
@@ -384,9 +385,13 @@ class Module(object):
     """
     def __init__(self, cmd, *args, **kargs):
         self.name = cmd
-        # call the command with --interface-description
-        get_cmd_xml = subprocess.Popen([cmd, "--interface-description"],
-                                       stdout=subprocess.PIPE)
+        try:
+            # call the command with --interface-description
+            get_cmd_xml = subprocess.Popen([cmd, "--interface-description"],
+                                           stdout=subprocess.PIPE)
+        except OSError:
+            str_err = "Module %r not found, please check that the module exist"
+            raise GrassError(str_err % self.name)
         # get the xml of the module
         self.xml = get_cmd_xml.communicate()[0]
         # transform and parse the xml into an Element class: