Пример #1
0
    def validate(self):
        if not self.repository or not self.package:
            raise ExtractorInvalidUsage.missing_field()

        if not self._check_remote_repository():
            raise ExtractorInvalidUsage.repository_not_found(
                payload=self.repository)
Пример #2
0
def download_file():
    file_paths = []

    # Should be called with a list of the request ids
    # e.g. http://localhost:8000/download?id=cjznzv95f000a2460o09eytuo&id=cjznzv42f000a2460o09eytue
    if not request.args or not request.args.getlist('id'):
        raise ExtractorInvalidUsage.no_files_specified()

    for value in request.args.getlist('id'):
        try:
            full_path = os.path.join(os.path.join(os.getcwd(), 'models'),
                                     value)
            ros_files = [
                os.path.join(full_path, x) for x in os.listdir(full_path)
                if x.endswith('.ros') or x.endswith('.rossystem')
            ]
            file_paths += ros_files
        except OSError:
            raise ExtractorInvalidUsage.file_not_found()

    # Send a zip file if more than one file exists, otherwise send only the text file
    if len(file_paths) > 1:
        memory_file = BytesIO()
        with zipfile.ZipFile(memory_file, 'w') as zf:
            for ros_file in file_paths:
                zf.write(ros_file, os.path.basename(ros_file))
        memory_file.seek(0)
        return send_file(memory_file,
                         as_attachment=True,
                         attachment_filename='ros-models.zip')
    else:
        return send_file(file_paths[0],
                         as_attachment=True,
                         attachment_filename=os.path.basename(file_paths[0]))
Пример #3
0
    def validate(self):
        super(LaunchExtractorRunner, self).validate()

        if not self.launch:
            raise ExtractorInvalidUsage.missing_field("Launch file name")
        if not self._check_ros_version():
            raise ExtractorInvalidUsage.wrong_ros_version(
                payload=self.ros_version)
Пример #4
0
    def validate(self):
        super(NodeExtractorRunner, self).validate()

        if not self.node:
            raise ExtractorInvalidUsage.missing_field("Node name")
        if not self._check_ros_version():
            raise ExtractorInvalidUsage.wrong_ros_version(
                payload=self.ros_version)
Пример #5
0
 def validate(self):
     if not self.repository:
         raise ExtractorInvalidUsage.missing_field("Repository")
     if not self.package:
         raise ExtractorInvalidUsage.missing_field("Package")
     if not self._check_remote_repository():
         raise ExtractorInvalidUsage.repository_not_found(
             payload=self.repository)
     if not self._check_ros_version():
         raise ExtractorInvalidUsage.wrong_ros_version(
             payload=self.ros_version)
Пример #6
0
 def validate(self):
     if not self.package:
         raise ExtractorInvalidUsage.missing_field("Package")
     # Path where the model files are stored
     if self.repository != "" and not super(
             MsgsExtractorRunner, self)._check_remote_repository():
         raise ExtractorInvalidUsage.repository_not_found(
             payload=self.repository)
     if not self._check_ros_version():
         raise ExtractorInvalidUsage.wrong_ros_version(
             payload=self.ros_version)
     if self.ros_version == "foxy":
         raise ExtractorInvalidUsage.ros_version_not_supported(
             payload=self.ros_version)
Пример #7
0
    def run_analysis(self):
        for message in super(NodeExtractorRunner, self).run_analysis():
            yield message

        # Start the Haros runner
        shell_command = [
            '/bin/bash', self.haros_runner_path, self.package, self.node,
            'node', self.model_path, self.ws_path
        ]
        extractor_process = subprocess.Popen(shell_command,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.STDOUT,
                                             bufsize=1)
        # Send the logs
        for line in iter(extractor_process.stdout.readline, ''):
            yield self._log_event(line)
            print line

        extractor_process.wait()

        # Read the file with the model
        try:
            model_file = open(
                os.path.join(self.model_path, self.node + '.ros'), 'r+')
            model = model_file.read().strip()
            model_file.close()
            yield self._model_event(model, self.node + '.ros')
            self.clean_up()
        except (OSError, IOError):
            raise ExtractorInvalidUsage.no_model_generated()
Пример #8
0
    def run_analysis(self):
        msgs_models_path = os.path.join(self.results_path, 'msgs')

        model_full_path = os.path.join(msgs_models_path, self.package + '.ros')

        shell_command = '/bin/bash ' + self.messages_extractor_script + ' ' + self.package + ' ' + msgs_models_path + ' ' + self.workspace_path + ' "' + self.repository + '"'
        if self.branch_optional != "":
            shell_command = shell_command[:-1]
            shell_command += ' -b ' + self.branch_optional + '"'

        yield self._log_event("... Processing the command: ")
        yield self._log_event(shell_command)

        self._create_ssh_client()
        stdin, stdout, stderr = self.client.exec_command(shell_command)

        stdoutLines = stdout.readlines()
        for line in stdoutLines:
            yield self._log_event(line)
            print(line)

        self.client.close()

        # Read the file with the model
        try:
            model_file = open(model_full_path, 'r+')
            model = model_file.read().strip()
            model_file.close()
            yield self._model_event(model, self.package + '.ros')
        except (OSError, IOError):
            raise ExtractorInvalidUsage.no_model_generated()
Пример #9
0
    def run_analysis(self):
        for message in super(LaunchExtractorRunner, self).run_analysis():
            yield message

        if not self._launch_file_exists():
            raise ExtractorInvalidUsage.launch_file_not_found(
                payload=self.launch)

        shell_command = [
            '/bin/bash', self.haros_runner_path, self.package, self.launch,
            'launch', self.model_path, self.ws_path
        ]
        extractor_process = subprocess.Popen(shell_command,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.STDOUT,
                                             bufsize=1)

        failed_packages_regex = r"Failed to process package '(.+?)'"
        failed_packages = []

        for line in iter(extractor_process.stdout.readline, ''):
            failed_package = re.search(failed_packages_regex, line)
            if failed_package:
                failed_packages.append(failed_package.group(1))
            yield self._log_event(line)
            print line

        extractor_process.wait()

        for file_ in os.listdir(self.model_path):
            if file_.endswith(".ros") or file_.endswith(".rossystem"):
                model_file = open(os.path.join(self.model_path, file_), 'r+')
                model = model_file.read().strip()
                model_file.close()
                yield self._model_event(model, file_)

        if failed_packages:
            raise ExtractorInvalidUsage.failed_packages(
                payload=failed_packages)
Пример #10
0
    def run_analysis(self):
        if (self.ros_version == 'melodic'):
            python_version = 2
        else:
            python_version = 3
        nodes_models_path = os.path.join(self.results_path, 'nodes')

        model_full_path = os.path.join(nodes_models_path, self.node + '.ros')

        shell_command = 'export PYTHON_VERSION=' + str(
            python_version
        ) + ' && /haros_runner.sh ' + self.package + ' ' + self.node + ' node ' + nodes_models_path + ' ' + self.workspace_path + ' "' + self.repository + '"'

        if self.branch_optional != "":
            shell_command = shell_command[:-1]
            shell_command += ' -b ' + self.branch_optional + '"'

        yield self._log_event("... Processing the command: ")
        yield self._log_event(shell_command)

        self._create_ssh_client()
        stdin, stdout, stderr = self.client.exec_command(shell_command)

        stdoutLines = stdout.readlines()
        for line in stdoutLines:
            yield self._log_event(line)
            print(line)

        self.client.close()

        # Read the file with the model
        try:
            model_file = open(model_full_path, 'r+')
            model = model_file.read().strip()
            model_file.close()
            yield self._model_event(model, self.node + '.ros')
        except (OSError, IOError):
            raise ExtractorInvalidUsage.no_model_generated()
Пример #11
0
    def validate(self):
        super(LaunchExtractorRunner, self).validate()

        if not self.launch:
            raise ExtractorInvalidUsage.missing_field()
Пример #12
0
    def validate(self):
        super(NodeExtractorRunner, self).validate()

        if not self.node:
            raise ExtractorInvalidUsage.missing_field()