]> SALOME platform Git repositories - tools/ydefx.git/blob - src/pydefx/defaultschemabuilder.py
Salome HOME
Add insitu example as a test.
[tools/ydefx.git] / src / pydefx / defaultschemabuilder.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2019  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 import inspect
21 import pathlib
22 import os
23 import shutil
24
25 class DefaultSchemaBuilder:
26   def __init__(self, prescript=None):
27     """
28     This object builds the YACS schema for the parametric computation.
29     prescript: contains python code that is executed before any evaluation.
30     """
31     self.prescript = prescript
32
33   def buildSchema(self, local_work_dir):
34     """
35     Create the YACS schema and copy it to local_work_dir.
36     local_work_dir : path where the schema will be created.
37     return:
38       path to the created file,
39       list of additional files needed for running.
40     """
41     # use generic schema
42     filename = inspect.getframeinfo(inspect.currentframe()).filename
43     install_directory = pathlib.Path(filename).resolve().parent
44     yacs_schema_path = os.path.join(install_directory, "schemas",
45                                     "idefix_pyschema.xml")
46     plugin_path = os.path.join(install_directory, "schemas", "plugin.py")
47     yacs_schema_path = shutil.copy(yacs_schema_path, local_work_dir)
48     plugin_path = shutil.copy(plugin_path, local_work_dir)
49     files = [plugin_path]
50     if self.prescript:
51       prescript_path = os.path.join(local_work_dir, "idefix_prescript.py")
52       with open(prescript_path, "w") as f:
53         f.write(self.prescript)
54       files.append(prescript_path)
55     return yacs_schema_path, files