2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # 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):
60 print 'Creating symlink %s' % dest
65 print 'Symlink %s already exists' % dest
69 # -----------------------------------------------------------------------------
72 """Remove (recursive) a directory if it exists"""
73 if os.path.exists(dir):
74 print 'Deleting tree %s' % dir
78 print 'Do not need to delete %s; already gone' % dir
83 # -----------------------------------------------------------------------------
88 if __lib__dir__: return __lib__dir__
93 # -----------------------------------------------------------------------------
95 def link_module(options):
98 if not options.module:
99 print "Option module is mandatory"
102 module_dir=os.path.abspath(options.module)
103 if not os.path.exists(module_dir):
104 print "Module %s does not exist" % module_dir
107 verbose = options.verbose
109 home_dir = os.path.expanduser(options.prefix)
110 #try to find python version of salome application and put it in versio
111 pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(home_dir,get_lib_dir(),"python*.*"))]
117 pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(module_dir,get_lib_dir(),"python*.*"))]
118 #check if the module has a python version compatible with application version
120 pyversio=versio or py_version
126 #incompatible python versions
127 print "incompatible python versions : application has version %s and module %s has not" % (versio,module_dir)
130 module_bin_dir=os.path.join(module_dir,'bin','salome')
131 module_idl_dir=os.path.join(module_dir,'idl','salome')
132 module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
133 module_lib_py_dir=os.path.join(module_dir,get_lib_dir(),pyversio,'site-packages','salome')
134 module_lib_py_shared_dir=os.path.join(module_dir,get_lib_dir(),pyversio,
135 'site-packages','salome','shared_modules')
136 module_share_dir=os.path.join(module_dir,'share','salome','resources')
137 module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
138 module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
139 module_doc_dir=os.path.join(module_dir,'doc','salome')
140 module_sharedoc_dir=os.path.join(module_dir,'share','doc','salome')
141 module_sharedoc_gui_dir=os.path.join(module_dir,'share','doc','salome','gui')
142 module_sharedoc_tui_dir=os.path.join(module_dir,'share','doc','salome','tui')
144 bin_dir=os.path.join(home_dir,'bin','salome')
145 idl_dir=os.path.join(home_dir,'idl','salome')
146 lib_dir=os.path.join(home_dir,'lib','salome')
147 lib_py_dir=os.path.join(home_dir,'lib',pyversio,'site-packages','salome')
148 lib_py_shared_dir=os.path.join(home_dir,'lib',pyversio,
149 'site-packages','salome','shared_modules')
150 share_dir=os.path.join(home_dir,'share','salome','resources')
151 doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
152 doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
153 doc_dir=os.path.join(home_dir,'doc','salome')
154 sharedoc_dir=os.path.join(home_dir,'share','doc','salome')
155 sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui')
156 sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui')
168 #directory bin/salome : create it and link content
169 if os.path.exists(module_bin_dir):
171 for fn in os.listdir(module_bin_dir):
172 symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
177 print module_bin_dir, " doesn't exist"
180 #directory idl/salome : create it and link content
181 if os.path.exists(module_idl_dir):
183 for fn in os.listdir(module_idl_dir):
184 symlink(os.path.join(module_idl_dir, fn), os.path.join(idl_dir, fn))
187 print module_idl_dir, " doesn't exist"
189 #directory lib/salome : create it and link content
190 if os.path.exists(module_lib_dir):
192 for fn in os.listdir(module_lib_dir):
193 symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
198 print module_lib_dir, " doesn't exist"
201 #directory lib/pyversio/site-packages/salome : create it and link content
202 if not os.path.exists(module_lib_py_dir):
203 print "Python directory %s does not exist" % module_lib_py_dir
205 mkdir(lib_py_shared_dir)
206 for fn in os.listdir(module_lib_py_dir):
207 if fn == "shared_modules": continue
208 symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
210 if os.path.exists(module_lib_py_shared_dir):
211 for fn in os.listdir(module_lib_py_shared_dir):
212 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
217 print module_lib_py_shared_dir, " doesn't exist"
220 #directory share/doc/salome (KERNEL doc) : create it and link content
221 if os.path.exists(module_sharedoc_dir):
223 for fn in os.listdir(module_sharedoc_dir):
224 if fn == 'gui':continue
225 if fn == 'tui':continue
226 symlink(os.path.join(module_sharedoc_dir, fn), os.path.join(sharedoc_dir, fn))
230 #directory share/doc/salome/gui : create it and link content
231 if os.path.exists(module_sharedoc_gui_dir):
232 mkdir(sharedoc_gui_dir)
233 for fn in os.listdir(module_sharedoc_gui_dir):
234 symlink(os.path.join(module_sharedoc_gui_dir, fn), os.path.join(sharedoc_gui_dir, fn))
238 #directory share/doc/salome/tui : create it and link content
239 if os.path.exists(module_sharedoc_tui_dir):
240 mkdir(sharedoc_tui_dir)
241 for fn in os.listdir(module_sharedoc_tui_dir):
242 symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn))
246 #directory share/salome/resources : create it and link content
247 if os.path.exists(module_share_dir):
249 for fn in os.listdir(module_share_dir):
250 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
254 print "resources directory %s does not exist" % module_share_dir
257 #html files in doc/salome directory
258 if os.path.exists(module_doc_dir):
260 for fn in os.listdir(module_doc_dir):
261 if fn == 'gui':continue
262 if fn == 'tui':continue
263 symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
267 #directory doc/salome/gui : create it and link content
268 if os.path.exists(module_doc_gui_dir):
270 for fn in os.listdir(module_doc_gui_dir):
271 symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
275 #directory doc/salome/tui : create it and link content
276 if os.path.exists(module_doc_tui_dir):
278 for fn in os.listdir(module_doc_tui_dir):
279 symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
283 # -----------------------------------------------------------------------------
286 usage="""usage: %prog [options]
288 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
290 parser = optparse.OptionParser(usage=usage)
292 parser.add_option('-v', '--verbose', action='count', dest='verbose',
293 default=0, help="Increase verbosity")
295 parser.add_option('--prefix', dest="prefix", default='.',
296 help="The base directory to install to (default .)")
298 parser.add_option('--module', dest="module",
299 help="The module directory to install in (mandatory)")
301 parser.add_option('--clear', dest='clear', action='store_true',
302 help="Clear out the install and start from scratch")
304 options, args = parser.parse_args()
308 # -----------------------------------------------------------------------------
310 if __name__ == '__main__':