1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 """Create a virtual Salome installation
21 Based on a script created by Ian Bicking.
25 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
27 install module KERNEL in the current directory
30 import sys, os, optparse, shutil,glob,fnmatch
31 py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
35 # -----------------------------------------------------------------------------
38 """Create a directory and all the intermediate directories if path does not exist"""
39 if not os.path.exists(path):
40 print 'Creating %s' % path
44 print 'Directory %s already exists' % path
48 # -----------------------------------------------------------------------------
50 def symlink(src, dest):
51 """Create a link if it does not exist"""
52 if not os.path.exists(dest):
54 print 'Creating symlink %s' % dest
58 print 'Symlink %s already exists' % dest
62 # -----------------------------------------------------------------------------
65 """Remove (recursive) a directory if it exists"""
66 if os.path.exists(dir):
67 print 'Deleting tree %s' % dir
71 print 'Do not need to delete %s; already gone' % dir
76 # -----------------------------------------------------------------------------
81 if __lib__dir__: return __lib__dir__
83 if platform.architecture()[0] == "64bit":
84 if platform.machine() == "ia64":
87 __lib__dir__ = "lib64"
92 # -----------------------------------------------------------------------------
94 def link_module(options):
96 if not options.module:
97 print "Option module is mandatory"
100 module_dir=os.path.abspath(options.module)
101 if not os.path.exists(module_dir):
102 print "Module %s does not exist" % module_dir
105 home_dir = os.path.expanduser(options.prefix)
107 module_bin_dir=os.path.join(module_dir,'bin','salome')
108 module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
109 module_lib_py_dir=os.path.join(module_dir,get_lib_dir(),py_version,'site-packages','salome')
110 module_lib_py_shared_dir=os.path.join(module_dir,get_lib_dir(),py_version,
111 'site-packages','salome','shared_modules')
112 module_share_dir=os.path.join(module_dir,'share','salome','resources')
113 module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
114 module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
115 module_doc_dir=os.path.join(module_dir,'doc','salome')
116 module_sharedoc_dir=os.path.join(module_dir,'share','doc','salome')
117 module_sharedoc_gui_dir=os.path.join(module_dir,'share','doc','salome','gui')
118 module_sharedoc_tui_dir=os.path.join(module_dir,'share','doc','salome','tui')
120 bin_dir=os.path.join(home_dir,'bin','salome')
121 lib_dir=os.path.join(home_dir,'lib','salome')
122 lib_py_dir=os.path.join(home_dir,'lib',py_version,'site-packages','salome')
123 lib_py_shared_dir=os.path.join(home_dir,'lib',py_version,
124 'site-packages','salome','shared_modules')
125 share_dir=os.path.join(home_dir,'share','salome','resources')
126 doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
127 doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
128 doc_dir=os.path.join(home_dir,'doc','salome')
129 sharedoc_dir=os.path.join(home_dir,'share','doc','salome')
130 sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui')
131 sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui')
133 verbose = options.verbose
144 #directory bin/salome : create it and link content
145 if os.path.exists(module_bin_dir):
147 for fn in os.listdir(module_bin_dir):
148 symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
152 print module_bin_dir, " doesn't exist"
155 #directory lib/salome : create it and link content
156 if os.path.exists(module_lib_dir):
158 for fn in os.listdir(module_lib_dir):
159 symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
163 print module_lib_dir, " doesn't exist"
166 #directory lib/py_version/site-packages/salome : create it and link content
167 if not os.path.exists(module_lib_py_dir):
168 print "Python directory %s does not exist" % module_lib_py_dir
170 mkdir(lib_py_shared_dir)
171 for fn in os.listdir(module_lib_py_dir):
172 if fn == "shared_modules": continue
173 symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
175 if os.path.exists(module_lib_py_shared_dir):
176 for fn in os.listdir(module_lib_py_shared_dir):
177 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
181 print module_lib_py_shared_dir, " doesn't exist"
184 #directory share/doc/salome (KERNEL doc) : create it and link content
185 if os.path.exists(module_sharedoc_dir):
187 for fn in os.listdir(module_sharedoc_dir):
188 if fn == 'gui':continue
189 if fn == 'tui':continue
190 symlink(os.path.join(module_sharedoc_dir, fn), os.path.join(sharedoc_dir, fn))
194 #directory share/doc/salome/gui : create it and link content
195 if os.path.exists(module_sharedoc_gui_dir):
196 mkdir(sharedoc_gui_dir)
197 for fn in os.listdir(module_sharedoc_gui_dir):
198 symlink(os.path.join(module_sharedoc_gui_dir, fn), os.path.join(sharedoc_gui_dir, fn))
202 #directory share/doc/salome/tui : create it and link content
203 if os.path.exists(module_sharedoc_tui_dir):
204 mkdir(sharedoc_tui_dir)
205 for fn in os.listdir(module_sharedoc_tui_dir):
206 symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn))
210 #directory share/salome/resources : create it and link content
211 if os.path.exists(module_share_dir):
213 for fn in os.listdir(module_share_dir):
214 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
218 print "resources directory %s does not exist" % module_share_dir
221 #html files in doc/salome directory
222 if os.path.exists(module_doc_dir):
224 for fn in os.listdir(module_doc_dir):
225 if fn == 'gui':continue
226 if fn == 'tui':continue
227 symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
231 #directory doc/salome/gui : create it and link content
232 if os.path.exists(module_doc_gui_dir):
234 for fn in os.listdir(module_doc_gui_dir):
235 symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
239 #directory doc/salome/tui : create it and link content
240 if os.path.exists(module_doc_tui_dir):
242 for fn in os.listdir(module_doc_tui_dir):
243 symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
247 # -----------------------------------------------------------------------------
250 usage="""usage: %prog [options]
252 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
254 parser = optparse.OptionParser(usage=usage)
256 parser.add_option('-v', '--verbose', action='count', dest='verbose',
257 default=0, help="Increase verbosity")
259 parser.add_option('--prefix', dest="prefix", default='.',
260 help="The base directory to install to (default .)")
262 parser.add_option('--module', dest="module",
263 help="The module directory to install in (mandatory)")
265 parser.add_option('--clear', dest='clear', action='store_true',
266 help="Clear out the install and start from scratch")
268 options, args = parser.parse_args()
272 # -----------------------------------------------------------------------------
274 if __name__ == '__main__':