]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsSchemaCreator/run.py
Salome HOME
Simplifying python files installation scheme
[modules/adao.git] / src / daSalome / daYacsSchemaCreator / run.py
1 #-*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2018 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
24
25 import sys
26 import os
27 import traceback
28 import logging
29 import tempfile
30 from daYacsSchemaCreator.methods import *
31 from daYacsSchemaCreator.help_methods import *
32
33 def create_schema(config_file, config_content, yacs_schema_filename):
34
35     if config_file is not None and config_content is None:
36       # Import config_file
37       try:
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)
42         else: msg = ""
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
46       try:
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)
51         else: msg = ""
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))
53     else:
54         raise ValueError("Error in schema creation, file or content has to be given")
55
56     if "study_config" not in locals():
57         raise ValueError("\n\n Cannot find study_config in %s\n"%str(config_file))
58     else:
59         globals()['study_config'] = locals()['study_config']
60
61     check_study(study_config)
62     proc = create_yacs_proc(study_config)
63     write_yacs_proc(proc, yacs_schema_filename)
64
65 def create_schema_from_file(config_file, yacs_schema_filename):
66     create_schema(config_file, None, yacs_schema_filename)
67
68 def create_schema_from_content(config_content, yacs_schema_filename):
69     create_schema(None, config_content, yacs_schema_filename)