Browse Source

Die properly in case of non-existent plugin

Alois Mahdal 10 years ago
parent
commit
d50d523839
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      include/gmon.py

+ 10
- 4
include/gmon.py View File

73
 
73
 
74
     def _load_plugin(self, pluginpath):
74
     def _load_plugin(self, pluginpath):
75
         modpath = "%s/%s.py" % (pluginpath, self.name)
75
         modpath = "%s/%s.py" % (pluginpath, self.name)
76
-        with open(modpath) as fh:
77
-            module = imp.load_module(self.name, fh, modpath,
78
-                                     (".py", "r", imp.PY_SOURCE))
76
+        try:
77
+            with open(modpath) as fh:
78
+                module = imp.load_module(self.name, fh, modpath,
79
+                                         (".py", "r", imp.PY_SOURCE))
80
+        except IOError:
81
+            raise GmonPluginError(self.name)
79
         self.plugin = module.Plugin(self.plugindata)
82
         self.plugin = module.Plugin(self.plugindata)
80
 
83
 
81
     def _format_output(self, raw):
84
     def _format_output(self, raw):
95
 
98
 
96
     def __init__(self, cmdargs):
99
     def __init__(self, cmdargs):
97
         self._set_pluginpath()
100
         self._set_pluginpath()
98
-        self.subcommand = Subcommand(cmdargs, self.pluginpath)
101
+        try:
102
+            self.subcommand = Subcommand(cmdargs, self.pluginpath)
103
+        except GmonPluginError as e:
104
+            self.die("no such plugin: %s" % e)
99
 
105
 
100
     def _set_pluginpath(self):
106
     def _set_pluginpath(self):
101
         mypath = os.path.dirname(os.path.realpath(sys.argv[0]))
107
         mypath = os.path.dirname(os.path.realpath(sys.argv[0]))