1 """Create a virtual Salome installation
3 Based on a script created by Ian Bicking.
7 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
9 install module KERNEL in the current directory
12 import sys, os, optparse, shutil,glob,fnmatch
13 py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
16 """Create a directory and all the intermediate directories if path does not exist"""
17 if not os.path.exists(path):
18 print 'Creating %s' % path
22 print 'Directory %s already exists' % path
26 def symlink(src, dest):
27 """Create a link if it does not exist"""
28 if not os.path.exists(dest):
30 print 'Creating symlink %s' % dest
34 print 'Symlink %s already exists' % dest
39 """Remove (recursive) a directory if it exists"""
40 if os.path.exists(dir):
41 print 'Deleting tree %s' % dir
45 print 'Do not need to delete %s; already gone' % dir
51 usage="""usage: %prog [options]
53 python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
55 parser = optparse.OptionParser(usage=usage)
57 parser.add_option('-v', '--verbose', action='count', dest='verbose',
58 default=0, help="Increase verbosity")
60 parser.add_option('--prefix', dest="prefix", default='.',
61 help="The base directory to install to (default .)")
63 parser.add_option('--module', dest="module",
64 help="The module directory to install in (mandatory)")
66 parser.add_option('--clear', dest='clear', action='store_true',
67 help="Clear out the install and start from scratch")
69 options, args = parser.parse_args()
72 if not options.module:
73 print "Option module is mandatory"
76 module_dir=options.module
77 if not os.path.exists(module_dir):
78 print "Module %s does not exist" % module_dir
81 home_dir = os.path.expanduser(options.prefix)
83 #module_dir="/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1"
84 module_bin_dir=os.path.join(module_dir,'bin','salome')
85 module_lib_dir=os.path.join(module_dir,'lib','salome')
86 module_lib_py_dir=os.path.join(module_dir,'lib',py_version,'site-packages','salome')
87 module_lib_py_shared_dir=os.path.join(module_dir,'lib',py_version,
88 'site-packages','salome','shared_modules')
89 module_share_dir=os.path.join(module_dir,'share','salome','resources')
90 module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
91 module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
92 module_doc_dir=os.path.join(module_dir,'doc','salome')
94 if not os.path.exists(module_lib_py_dir):
95 print "Python directory %s does not exist" % module_lib_py_dir
98 bin_dir=os.path.join(home_dir,'bin','salome')
99 lib_dir=os.path.join(home_dir,'lib','salome')
100 lib_py_dir=os.path.join(home_dir,'lib',py_version,'site-packages','salome')
101 lib_py_shared_dir=os.path.join(home_dir,'lib',py_version,
102 'site-packages','salome','shared_modules')
103 share_dir=os.path.join(home_dir,'share','salome','resources')
104 doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
105 doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
106 doc_dir=os.path.join(home_dir,'doc','salome')
108 verbose = options.verbose
117 #directory bin/salome : create it and link content
119 for fn in os.listdir(module_bin_dir):
120 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
121 symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
124 #directory lib/salome : create it and link content
126 for fn in os.listdir(module_lib_dir):
127 symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
129 #directory lib/py_version/site-packages/salome : create it and link content
130 mkdir(lib_py_shared_dir)
131 for fn in os.listdir(module_lib_py_dir):
132 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
133 if os.path.split(fn)[1] != "shared_modules":
134 symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
137 if os.path.exists(module_lib_py_shared_dir):
138 for fn in os.listdir(module_lib_py_shared_dir):
139 # if os.path.splitext(fn)[1] not in (".pyc",".pyo"): #Compiled python are excluded
140 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
144 print module_lib_py_shared_dir, " doesn't exist"
148 #directory share/salome/resources : create it and link content
150 for fn in os.listdir(module_share_dir):
151 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
153 #html files in doc/salome directory
154 if os.path.exists(module_doc_dir):
156 for fn in os.listdir(module_doc_dir):
157 if fn == 'gui':continue
158 if fn == 'tui':continue
159 symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
163 #directory doc/salome/gui : create it and link content
164 if os.path.exists(module_doc_gui_dir):
166 for fn in os.listdir(module_doc_gui_dir):
167 symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
171 #directory doc/salome/tui : create it and link content
172 if os.path.exists(module_doc_tui_dir):
174 for fn in os.listdir(module_doc_tui_dir):
175 symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
179 if __name__ == '__main__':