4 from errbot import BotPlugin, botcmd, re_botcmd
5 from errbot.utils import ValidationException
9 Execute a command when the bot is talked to
18 Load configuration from config.by
20 super(Exec, self).activate()
21 if (self.config == None and self.bot_config.EXEC):
22 self.check_configuration(self.bot_config.EXEC)
23 self.configure(self.bot_config.EXEC)
25 def executable_exists(self, name):
27 Check if an executable exists
30 raise ValidationException('Command is empty')
33 for path in os.environ['PATH'].split(os.pathsep):
34 fullpath = path + os.sep + name
35 if os.path.exists(fullpath):
39 raise ValidationException('Command not in PATH')
41 def get_configuration_template(self):
43 Defines the configuration structure this plugin supports
45 return self.config_template
47 def check_configuration(self, configuration):
49 Triggers when the configuration is checked, shortly before activation
51 super(Exec, self).check_configuration(configuration)
52 self.executable_exists(configuration['command'])
54 @re_botcmd(pattern=r".*", prefixed=False)
55 def runexec(self, msg, match):
62 output = subprocess.check_output(
63 [self.config['command'], str(msg), str(msg.frm)],
64 stderr=subprocess.STDOUT
70 except subprocess.CalledProcessError as err: