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])
34 """Create a directory and all the intermediate directories if path does not exist"""
35 if not os.path.exists(path):
36 print 'Creating %s' % path
40 print 'Directory %s already exists' % path
44 def symlink(src, dest):
45 """Create a link if it does not exist"""
46 if not os.path.exists(dest):
48 print 'Creating symlink %s' % dest
52 print 'Symlink %s already exists' % dest
57 """Remove (recursive) a directory if it exists"""
58 if os.path.exists(dir):
59 print 'Deleting tree %s' % dir
63 print 'Do not need to delete %s; already gone' % dir
69 usage="""usage: %prog [options]
71 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
73 parser = optparse.OptionParser(usage=usage)
75 parser.add_option('-v', '--verbose', action='count', dest='verbose',
76 default=0, help="Increase verbosity")
78 parser.add_option('--prefix', dest="prefix", default='.',
79 help="The base directory to install to (default .)")
81 parser.add_option('--module', dest="module",
82 help="The module directory to install in (mandatory)")
84 parser.add_option('--clear', dest='clear', action='store_true',
85 help="Clear out the install and start from scratch")
87 options, args = parser.parse_args()
90 if not options.module:
91 print "Option module is mandatory"
94 module_dir=options.module
95 if not os.path.exists(module_dir):
96 print "Module %s does not exist" % module_dir
99 home_dir = os.path.expanduser(options.prefix)
101 #module_dir="/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1"
102 module_bin_dir=os.path.join(module_dir,'bin','salome')
103 module_lib_dir=os.path.join(module_dir,'lib','salome')
104 module_lib_py_dir=os.path.join(module_dir,'lib',py_version,'site-packages','salome')
105 module_lib_py_shared_dir=os.path.join(module_dir,'lib',py_version,
106 'site-packages','salome','shared_modules')
107 module_share_dir=os.path.join(module_dir,'share','salome','resources')
108 module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
109 module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
110 module_doc_dir=os.path.join(module_dir,'doc','salome')
112 if not os.path.exists(module_lib_py_dir):
113 print "Python directory %s does not exist" % module_lib_py_dir
116 bin_dir=os.path.join(home_dir,'bin','salome')
117 lib_dir=os.path.join(home_dir,'lib','salome')
118 lib_py_dir=os.path.join(home_dir,'lib',py_version,'site-packages','salome')
119 lib_py_shared_dir=os.path.join(home_dir,'lib',py_version,
120 'site-packages','salome','shared_modules')
121 share_dir=os.path.join(home_dir,'share','salome','resources')
122 doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
123 doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
124 doc_dir=os.path.join(home_dir,'doc','salome')
126 verbose = options.verbose
135 #directory bin/salome : create it and link content
137 for fn in os.listdir(module_bin_dir):
138 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
139 symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
142 #directory lib/salome : create it and link content
144 for fn in os.listdir(module_lib_dir):
145 symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
147 #directory lib/py_version/site-packages/salome : create it and link content
148 mkdir(lib_py_shared_dir)
149 for fn in os.listdir(module_lib_py_dir):
150 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
151 if os.path.split(fn)[1] != "shared_modules":
152 symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
155 if os.path.exists(module_lib_py_shared_dir):
156 for fn in os.listdir(module_lib_py_shared_dir):
157 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
158 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
162 print module_lib_py_shared_dir, " doesn't exist"
166 #directory share/salome/resources : create it and link content
168 for fn in os.listdir(module_share_dir):
169 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
171 #html files in doc/salome directory
172 if os.path.exists(module_doc_dir):
174 for fn in os.listdir(module_doc_dir):
175 if fn == 'gui':continue
176 if fn == 'tui':continue
177 symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
181 #directory doc/salome/gui : create it and link content
182 if os.path.exists(module_doc_gui_dir):
184 for fn in os.listdir(module_doc_gui_dir):
185 symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
189 #directory doc/salome/tui : create it and link content
190 if os.path.exists(module_doc_tui_dir):
192 for fn in os.listdir(module_doc_tui_dir):
193 symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
197 if __name__ == '__main__':