1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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
24 """Create a virtual Salome installation
26 Based on a script created by Ian Bicking.
30 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
32 install module KERNEL in the current directory
35 import sys, os, optparse, shutil,glob,fnmatch
36 py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
40 # -----------------------------------------------------------------------------
43 """Create a directory and all the intermediate directories if path does not exist"""
44 if not os.path.exists(path):
46 print 'Creating %s' % path
50 print 'Directory %s already exists' % path
54 # -----------------------------------------------------------------------------
56 def symlink(src, dest):
57 """Create a link if it does not exist"""
58 if not os.path.exists(dest):
59 if os.path.lexists(dest):
60 print "Do not create symlink %s. It already exists but it's broken" % dest
63 print 'Creating symlink %s' % dest
68 print 'Symlink %s already exists' % dest
72 # -----------------------------------------------------------------------------
75 """Remove (recursive) a directory if it exists"""
76 if os.path.exists(dir):
77 print 'Deleting tree %s' % dir
81 print 'Do not need to delete %s; already gone' % dir
86 # -----------------------------------------------------------------------------
91 if __lib__dir__: return __lib__dir__
96 # -----------------------------------------------------------------------------
98 def link_module(options):
101 if not options.module_path:
102 print "Option module is mandatory"
105 module_dir=os.path.abspath(options.module_path)
106 if not os.path.exists(module_dir):
107 print "Module %s does not exist" % module_dir
110 verbose = options.verbose
112 home_dir = os.path.expanduser(options.prefix)
113 #try to find python version of salome application and put it in versio
114 pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(home_dir,get_lib_dir(),"python*.*"))]
120 pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(module_dir,get_lib_dir(),"python*.*"))]
121 #check if the module has a python version compatible with application version
123 pyversio=versio or py_version
129 #incompatible python versions
130 print "incompatible python versions : application has version %s and module %s has not" % (versio,module_dir)
133 module_bin_dir=os.path.join(module_dir,'bin','salome')
134 module_test_dir=os.path.join(module_dir,'bin','salome', 'test')
135 module_idl_dir=os.path.join(module_dir,'idl','salome')
136 module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
137 module_pvlib_dir=os.path.join(module_dir,get_lib_dir(),'paraview')
138 module_lib_py_dir=os.path.join(module_dir,get_lib_dir(),pyversio,'site-packages','salome')
139 module_lib_py_shared_dir=os.path.join(module_dir,get_lib_dir(),pyversio,
140 'site-packages','salome')
141 module_share_dir=os.path.join(module_dir,'share','salome')
142 module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
143 module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
144 module_doc_dir=os.path.join(module_dir,'doc','salome')
145 module_sharedoc_dir=os.path.join(module_dir,'share','doc','salome')
146 module_sharedoc_gui_dir=os.path.join(module_dir,'share','doc','salome','gui')
147 module_sharedoc_tui_dir=os.path.join(module_dir,'share','doc','salome','tui')
148 module_sharedoc_examples=os.path.join(module_dir,'share','doc','salome','examples')
150 bin_dir=os.path.join(home_dir,'bin','salome')
151 test_dir=os.path.join(home_dir,'bin','salome', 'test')
152 idl_dir=os.path.join(home_dir,'idl','salome')
153 lib_dir=os.path.join(home_dir,'lib','salome')
154 pvlib_dir=os.path.join(home_dir,'lib','paraview')
155 lib_py_dir=os.path.join(home_dir,'lib',pyversio,'site-packages','salome')
156 lib_py_shared_dir=os.path.join(home_dir,'lib',pyversio,
157 'site-packages','salome')
158 share_dir=os.path.join(home_dir,'share','salome')
159 doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
160 doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
161 doc_dir=os.path.join(home_dir,'doc','salome')
162 sharedoc_dir=os.path.join(home_dir,'share','doc','salome')
163 sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui')
164 sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui')
165 sharedoc_examples_dir=os.path.join(home_dir,'share','doc','salome','examples')
178 #directory bin/salome : create it and link content
179 if os.path.exists(module_bin_dir):
182 for fn in os.listdir(module_bin_dir):
184 symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
189 print module_bin_dir, " doesn't exist"
192 #directory bin/salome/test : create it and link content
193 if os.path.exists(module_test_dir):
194 # link <appli_path>/bin/salome/test/<module> to <module_path>/bin/salome/test
195 print "link %s --> %s"%(os.path.join(test_dir, options.module_name), module_test_dir)
196 symlink(module_test_dir, os.path.join(test_dir, options.module_name))
197 # register module for testing in CTestTestfile.cmake
198 with open(os.path.join(test_dir, "CTestTestfile.cmake"), "ab") as f:
199 f.write("SUBDIRS(%s)\n"%options.module_name)
202 print module_test_dir, " doesn't exist"
205 #directory idl/salome : create it and link content
206 if os.path.exists(module_idl_dir):
208 for fn in os.listdir(module_idl_dir):
209 symlink(os.path.join(module_idl_dir, fn), os.path.join(idl_dir, fn))
212 print module_idl_dir, " doesn't exist"
214 #directory lib/salome : create it and link content
215 if os.path.exists(module_lib_dir):
217 for fn in os.listdir(module_lib_dir):
218 symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
223 print module_lib_dir, " doesn't exist"
226 #directory lib/paraview : create it and link content
227 if os.path.exists(module_pvlib_dir):
229 for fn in os.listdir(module_pvlib_dir):
230 symlink(os.path.join(module_pvlib_dir, fn), os.path.join(pvlib_dir, fn))
235 print module_pvlib_dir, " doesn't exist"
238 #directory lib/pyversio/site-packages/salome : create it and link content
239 if not os.path.exists(module_lib_py_dir):
240 print "Python directory %s does not exist" % module_lib_py_dir
242 # Specific action for the package salome
243 module_lib_pypkg_dir=os.path.join(module_lib_py_dir,"salome")
244 lib_pypkg_dir=os.path.join(lib_py_dir,"salome")
246 mkdir(lib_py_shared_dir)
247 for fn in os.listdir(module_lib_py_dir):
248 if fn == "salome": continue
249 symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
251 if os.path.exists(module_lib_py_shared_dir):
252 for fn in os.listdir(module_lib_py_shared_dir):
253 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
256 if os.path.exists(module_lib_pypkg_dir):
257 for fn in os.listdir(module_lib_pypkg_dir):
258 symlink(os.path.join(module_lib_pypkg_dir, fn), os.path.join(lib_pypkg_dir, fn))
263 print module_lib_py_shared_dir, " doesn't exist"
266 #directory share/doc/salome (KERNEL doc) : create it and link content
267 if os.path.exists(module_sharedoc_dir):
269 for fn in os.listdir(module_sharedoc_dir):
270 if fn == 'gui':continue
271 if fn == 'tui':continue
272 if fn == 'examples':continue
273 symlink(os.path.join(module_sharedoc_dir, fn), os.path.join(sharedoc_dir, fn))
277 #directory share/doc/salome/gui : create it and link content
278 if os.path.exists(module_sharedoc_gui_dir):
279 mkdir(sharedoc_gui_dir)
280 for fn in os.listdir(module_sharedoc_gui_dir):
281 symlink(os.path.join(module_sharedoc_gui_dir, fn), os.path.join(sharedoc_gui_dir, fn))
285 #directory share/doc/salome/tui : create it and link content
286 if os.path.exists(module_sharedoc_tui_dir):
287 mkdir(sharedoc_tui_dir)
288 for fn in os.listdir(module_sharedoc_tui_dir):
289 symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn))
293 #directory share/doc/salome/examples : create it and link content
294 if os.path.exists(module_sharedoc_examples):
295 mkdir(sharedoc_examples_dir)
296 for fn in os.listdir(module_sharedoc_examples):
297 symlink(os.path.join(module_sharedoc_examples, fn), os.path.join(sharedoc_examples_dir, fn))
301 #directory share/salome : create it and link content
302 if os.path.exists(module_share_dir):
304 for fn in os.listdir(module_share_dir):
305 if fn in ["resources","plugins"] :
306 # Create the directory and then link the content
307 mkdir(os.path.join(share_dir,fn))
308 for ffn in os.listdir(os.path.join(module_share_dir,fn)):
309 symlink(os.path.join(module_share_dir, fn, ffn), os.path.join(share_dir,fn, ffn))
311 #other directories (not resources)
312 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
314 print "share/salome directory %s does not exist" % module_share_dir
317 #html files in doc/salome directory
318 if os.path.exists(module_doc_dir):
320 for fn in os.listdir(module_doc_dir):
321 if fn == 'gui':continue
322 if fn == 'tui':continue
323 symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
327 #directory doc/salome/gui : create it and link content
328 if os.path.exists(module_doc_gui_dir):
330 for fn in os.listdir(module_doc_gui_dir):
331 symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
335 #directory doc/salome/tui : create it and link content
336 if os.path.exists(module_doc_tui_dir):
338 for fn in os.listdir(module_doc_tui_dir):
339 symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
343 def link_extra_test(options):
346 if not options.extra_test_path:
347 print "Option extra_test is mandatory"
350 extra_test_dir=os.path.abspath(options.extra_test_path)
351 if not os.path.exists(extra_test_dir):
352 print "Test %s does not exist" % extra_test_dir
355 verbose = options.verbose
357 home_dir = os.path.expanduser(options.prefix)
358 test_dir = os.path.join(home_dir,'bin','salome', 'test')
364 #directory bin/salome/test : create it and link content
365 if os.path.exists(extra_test_dir):
366 # link <appli_path>/bin/salome/test/<extra_test> to <extra_test_path>/bin/salome/test
367 print "link %s --> %s"%(os.path.join(test_dir, options.extra_test_name), extra_test_dir)
368 symlink(extra_test_dir, os.path.join(test_dir, options.extra_test_name))
369 # register extra_test for testing in CTestTestfile.cmake
370 with open(os.path.join(test_dir, "CTestTestfile.cmake"), "ab") as f:
371 f.write("SUBDIRS(%s)\n"%options.extra_test_name)
374 print extra_test_dir, " doesn't exist"
377 # -----------------------------------------------------------------------------
380 usage="""usage: %prog [options]
382 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
384 parser = optparse.OptionParser(usage=usage)
386 parser.add_option('-v', '--verbose', action='count', dest='verbose',
387 default=0, help="Increase verbosity")
389 parser.add_option('--prefix', dest="prefix", default='.',
390 help="The base directory to install to (default .)")
392 parser.add_option('--module', dest="module",
393 help="The module directory to install in (mandatory)")
395 parser.add_option('--clear', dest='clear', action='store_true',
396 help="Clear out the install and start from scratch")
398 options, args = parser.parse_args()
402 # -----------------------------------------------------------------------------
404 if __name__ == '__main__':