Ejemplo n.º 1
0
    def _run_hyst(self, hypy_out, hyst_out):
        '''
        runs hyst on the model,

        hypy_out is an OutputHandler which gets hypy uses to produce output
        hyst_out is an OutputHandler capturing hyst's output

        returns a code in Engine.Error_*
        '''
        rv = Engine.SUCCESS

        hypy_out.add_line("Using Hyst to convert {} for {}.".format(
            "generated model" if self.input_[0] is None else 
            "model '" + self.input_[0] + "'", self.printer[0]))

        hyst_path = get_tool_path('Hyst.jar')

        if hyst_path is None:
            raise RuntimeError('Hyst not found. Did you add the directory with Hyst.jar to HYPYPATH?')

        params = ['java', '-jar', hyst_path]

        if self.debug:
            params.append('-debug')

        if self.verbose:
            params.append('-verbose')

        if self.input_[0] is not None and self.gen[0] is not None:
            raise RuntimeError("Input file provided and model generation selected. These options are incompatible.")

        if self.input_[0] is not None:
            params += ['-i', self.input_[0]]

            if self.input_[1] is not None:
                params.append(self.input_[1]) # cfg file
        elif self.gen[0] is not None:
            params += ['-gen', self.gen[0], self.gen[1]]
        else:
            raise RuntimeError("No input file provided and no model generation params given.")

        if len(self.passes) > 0:
            params.append("-passes")

            for (pass_name, param) in self.passes:
                params += [pass_name, param]
        
        params += ['-o', self.output]
        params += ['-tool', self.printer[0], self.printer[1]]

        params += self.additional_hyst_params

        quoted_params = ["'" + param + "'" if (' ' in param or len(param) == 0) else param for param in params]
        hypy_out.add_line("Hyst command: {}".format(" ".join(quoted_params)))

        try:
            proc = subprocess.Popen(params, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            hyst_out.stdout_handler(proc.stdout)
            code = proc.wait()

            if code == 2: # Hyst exit code 2 = preconditions not met for printer
                rv = Engine.ERROR_UNSUPPORTED
            elif code != 0:
                rv = Engine.ERROR_CONVERSION
                hypy_out.add_line('Error: Hyst returned nonzero exit code: {}.\n'.format(code))
        except OSError as e:
            hypy_out.add_line('Error while running Hyst: {}\n'.format(e))
            rv = Engine.ERROR_CONVERSION

        return rv
Ejemplo n.º 2
0
    def _run_hyst(self, hypy_out, hyst_out):
        '''
        runs hyst on the model,

        hypy_out is an OutputHandler which gets hypy uses to produce output
        hyst_out is an OutputHandler capturing hyst's output

        returns a code in Engine.Error_*
        '''
        rv = Engine.SUCCESS

        hypy_out.add_line("Using Hyst to convert {} for {}.".format(
            "generated model" if self.input_[0] is None else 
            "model '" + self.input_[0] + "'", self.printer[0]))

        hyst_path = get_tool_path('Hyst.jar')

        if hyst_path is None:
            raise RuntimeError('Hyst not found. Did you add the directory with Hyst.jar to HYPY_PATH?')

        params = ['java', '-jar', hyst_path]

        if self.debug:
            params.append('-debug')

        if self.verbose:
            params.append('-verbose')

        if self.input_[0] is not None and self.gen[0] is not None:
            raise RuntimeError("Input file provided and model generation selected. These options are incompatible.")

        if self.input_[0] is not None:
            params += ['-i', self.input_[0]]

            if self.input_[1] is not None:
                params.append(self.input_[1]) # cfg file
        elif self.gen[0] is not None:
            params += ['-gen', self.gen[0], self.gen[1]]
        else:
            raise RuntimeError("No input file provided and no model generation params given.")

        if len(self.passes) > 0:
            params.append("-passes")

            for (pass_name, param) in self.passes:
                params += [pass_name, param]
        
        params += ['-o', self.output]
        params += ['-tool', self.printer[0], self.printer[1]]

        params += self.additional_hyst_params

        quoted_params = ["'" + param + "'" if (' ' in param or len(param) == 0) else param for param in params]
        hypy_out.add_line("Hyst command: {}".format(" ".join(quoted_params)))

        try:
            proc = subprocess.Popen(params, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            hyst_out.stdout_handler(proc.stdout)
            code = proc.wait()

            if code == 2: # Hyst exit code 2 = preconditions not met for printer
                rv = Engine.ERROR_UNSUPPORTED
            elif code != 0:
                rv = Engine.ERROR_CONVERSION
                hypy_out.add_line('Error: Hyst returned nonzero exit code: {}.\n'.format(code))
        except OSError as e:
            hypy_out.add_line('Error while running Hyst: {}\n'.format(e))
            rv = Engine.ERROR_CONVERSION

        return rv