Exemple #1
0
    def processCommandInput(self, pid, cmd, pwd):
        """
        This method tries to find a plugin to parse the command sent
        by the terminal (identiefied by the process id).
        """
        if pid not in self.plugin_sets:
            self.createPluginSet(pid)

        plugin = self._get_plugins_by_input(cmd, self.plugin_sets[pid])

        if plugin:
            modified_cmd_string = plugin.processCommandString("", pwd, cmd)
            if not self._is_command_malformed(cmd, modified_cmd_string):

                cmd_info = CommandRunInformation(
                    **{'workspace': model.api.getActiveWorkspace().name,
                        'itime': time.time(),
                        'import_source': 'shell',
                        'command': cmd.split()[0],
                        'params': ' '.join(cmd.split()[1:])})
                cmd_info.setID(self._mapper_manager.save(cmd_info))

                self._active_plugins[pid] = plugin, cmd_info

                return plugin.id, modified_cmd_string

        return None, None
Exemple #2
0
    def processReport(self, plugin, filepath, ws_name=None):

        if not ws_name:
            ws_name = model.api.getActiveWorkspace().name

        cmd_info = CommandRunInformation(
            **{'workspace': ws_name,
               'itime': time.time(),
               'import_source': 'report',
               'command': plugin,
               'params': filepath,
            })

        self._mapper_manager.createMappers(ws_name)
        command_id = self._mapper_manager.save(cmd_info)
        cmd_info.setID(command_id)

        if plugin in self._plugins:
            logger.info('Processing report with plugin {0}'.format(plugin))
            self._plugins[plugin].workspace = ws_name
            with open(filepath, 'rb') as output:
                self.processOutput(self._plugins[plugin], output.read(), cmd_info, True)
            return command_id

        # Plugin to process this report not found, update duration of plugin process
        cmd_info.duration = time.time() - cmd_info.itime
        self._mapper_manager.update(cmd_info)
        return False