Salome HOME
sat package : make the script create_appli.py executable and improve the improve...
[tools/sat.git] / src / internal_config / create_appli.py.for_bin_packages.template
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import subprocess
21 import shutil
22
23 ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
24 dir_bin_name = TO BE FILLED 1
25
26 appli_config_name = "appli_config.xml"
27 appli_config_contain = '''<application>
28 <prerequisites path="env_launch.sh"/>
29 <resources path="CatalogResources.xml"/>
30 <modules>
31 TO BE FILLED 2</modules>
32 </application>
33 '''
34 # Write the appli_config.xml file
35 appli_config_stream = open(os.path.join(ROOT_DIR, appli_config_name), "w")
36 appli_config_stream.write(appli_config_contain)
37 appli_config_stream.close()
38
39 # Put the absolute path of the application in the env_launch file
40 env_file_name = "env_launch.sh"
41 env_file_save_name = "env_launch.sh_save"
42 shutil.move(os.path.join(ROOT_DIR, env_file_name), os.path.join(ROOT_DIR, env_file_save_name))
43 env_file_save_stream = open(os.path.join(ROOT_DIR, env_file_save_name), "r")
44 env_file_stream = open(os.path.join(ROOT_DIR, env_file_name), "w")
45 for line in env_file_save_stream.readlines():
46         if 'export out_dir_Path=' in line:
47                 line_to_write = 'export out_dir_Path="' + ROOT_DIR + '"\n'
48         else:
49                 line_to_write = line
50         env_file_stream.write(line_to_write)
51
52 for stream in [env_file_save_stream, env_file_stream]:
53         stream.close()
54
55 os.chmod(os.path.join(ROOT_DIR, env_file_name),
56          stat.S_IRUSR |
57          stat.S_IRGRP |
58          stat.S_IROTH |
59          stat.S_IWUSR |
60          stat.S_IXUSR |
61          stat.S_IXGRP |
62          stat.S_IXOTH)
63
64 command = "python " + os.path.join(ROOT_DIR, dir_bin_name, "KERNEL", "bin", "salome", "appli_gen.py") + " --prefix=APPLI --config=" + appli_config_name
65 subprocess.call(command, shell=True)