3 # Copyright (C) 2008-2018 EDF R&D
5 # This file is part of SALOME ADAO module
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
30 from daYacsSchemaCreator.methods import *
31 from daYacsSchemaCreator.help_methods import *
33 def create_schema(config_file, config_content, yacs_schema_filename):
35 if config_file is not None and config_content is None:
38 (fd, filename) = tempfile.mkstemp()
39 exec(compile(open(config_file).read(), filename, 'exec'))
40 except Exception as e:
41 if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
43 raise ValueError("\n\nexception in loading %s\n\nThe following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal.\n"%(config_file,str(e),msg))
44 elif config_file is None and config_content is not None:
45 # Import config_content
47 (fd, filename) = tempfile.mkstemp()
48 exec(compile(config_content, filename, 'exec'))
49 except Exception as e:
50 if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
52 raise ValueError("\n\nexception in loading the config content\n\nThe following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal.\n"%(str(e),msg))
54 raise ValueError("Error in schema creation, file or content has to be given")
56 if "study_config" not in locals():
57 raise ValueError("\n\n Cannot find study_config in %s\n"%str(config_file))
59 globals()['study_config'] = locals()['study_config']
61 check_study(study_config)
62 proc = create_yacs_proc(study_config)
63 write_yacs_proc(proc, yacs_schema_filename)
65 def create_schema_from_file(config_file, yacs_schema_filename):
66 create_schema(config_file, None, yacs_schema_filename)
68 def create_schema_from_content(config_content, yacs_schema_filename):
69 create_schema(None, config_content, yacs_schema_filename)