コード例 #1
0
    def run_tool(self, sys_argv):
        class_name = self.__class__.__name__
        class_name_lc = class_name.lower()

        args = get_args(sys_argv)

        out_file = args.out_file.format(class_name_lc)

        if args.test:
            in_file = '__test__{}_input.xml'.format(class_name_lc)
            with open(in_file, 'wb') as f:
                f.write(self.generate_input_xml())
            self.execute(in_file, out_file)
            sys.stdout.write(
                'Executed test run of {}.py with input file "{}" and output file '
                '"{}".\n'.format(class_name, in_file, out_file))
        else:
            in_file = args.in_file
            if not os.path.isfile(in_file):
                raise AssertionError(
                    'could not find the input file "{}" in the folder.'.format(
                        in_file))
            self.execute(in_file, out_file)
            sys.stdout.write(
                'Executed run of {}.py with input file "{}" and output file "{}".\n'
                .format(class_name, in_file, out_file))
        if args.merge_files:
            xml_merge(in_file, out_file, out_file)
コード例 #2
0
def deploy():
    _copy = True
    for discipline in list_disciplines():
        discipline.deploy()
        if _copy:
            _copy = False
            copyfile(discipline.in_file, base_file_path)
        else:
            xml_merge(base_file_path, discipline.in_file)

        xml_merge(base_file_path, discipline.out_file)
コード例 #3
0
ファイル: xml_component.py プロジェクト: jbussemaker/OpenLEGO
    def compute(self,
                inputs,
                outputs,
                discrete_inputs=None,
                discrete_outputs=None):
        # type: (Vector, Vector, Optional[dict], Optional[dict]) -> None
        """Write the input XML file, call `execute()`, and read the output XML file to obtain the results.

        Parameters
        ----------
            inputs : `Vector`
                Input parameters.

            outputs : `Vector`
                Output parameters.

            discrete_inputs : `dict`
                Discrete (i.e. not treated as floats) input parameters.

            discrete_outputs : `dict`
                Discrete (i.e. not treated as floats) output parameters.
        """

        input_xml, output_xml, _ = self.generate_file_names()

        if self.inputs_from_xml:
            self.write_input_file(input_xml, inputs, discrete_inputs)
            if self.base_file is not None:
                xml_merge(self.base_file, input_xml)

        # Call execute
        if self.base_file is not None:
            self.execute(self.base_file, output_xml)
            xml_merge(self.base_file, output_xml)
        else:
            self.execute(input_xml, output_xml)

        # If files should not be kept, delete the input XML file
        if not self.keep_files:
            try:
                os.remove(input_xml)
            except OSError:
                pass

        if self.outputs_from_xml:
            self.read_outputs_file(output_xml, outputs, discrete_outputs)

            # If files should not be kept, delete the output XML file
            if not self.keep_files:
                try:
                    os.remove(output_xml)
                except OSError:
                    pass