]> SALOME platform Git repositories - modules/kernel.git/blob - bin/virtual_salome.py
Salome HOME
03bc4c258ab849106d343d6d19ecceaa44353096
[modules/kernel.git] / bin / virtual_salome.py
1 """Create a virtual Salome installation 
2
3 Based on a script created by Ian Bicking.
4
5 Typical use::
6
7   python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
8
9 install module KERNEL in the current directory
10 """
11
12 import sys, os, optparse, shutil,glob,fnmatch
13 py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
14
15 def mkdir(path):
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
19         os.makedirs(path)
20     else:
21         if verbose:
22             print 'Directory %s already exists' % path
23             pass
24         pass
25
26 def symlink(src, dest):
27     """Create a link if it does not exist"""
28     if not os.path.exists(dest):
29         if verbose:
30             print 'Creating symlink %s' % dest
31             pass
32         os.symlink(src, dest)
33     else:
34         print 'Symlink %s already exists' % dest
35         pass
36     pass
37
38 def rmtree(dir):
39     """Remove (recursive) a directory if it exists"""
40     if os.path.exists(dir):
41         print 'Deleting tree %s' % dir
42         shutil.rmtree(dir)
43     else:
44         if verbose:
45             print 'Do not need to delete %s; already gone' % dir
46             pass
47         pass
48     pass
49
50 def main():
51     usage="""usage: %prog [options]
52 Typical use is:
53   python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
54 """
55     parser = optparse.OptionParser(usage=usage)
56
57     parser.add_option('-v', '--verbose', action='count', dest='verbose',
58                       default=0, help="Increase verbosity")
59
60     parser.add_option('--prefix', dest="prefix", default='.',
61                       help="The base directory to install to (default .)")
62
63     parser.add_option('--module', dest="module", 
64                       help="The module directory to install in (mandatory)")
65
66     parser.add_option('--clear', dest='clear', action='store_true',
67         help="Clear out the install and start from scratch")
68
69     options, args = parser.parse_args()
70     global verbose
71
72     if not options.module:
73         print "Option module is mandatory"
74         return 
75    
76     module_dir=options.module
77     if not os.path.exists(module_dir):
78         print "Module %s does not exist" % module_dir
79         return
80
81     home_dir = os.path.expanduser(options.prefix)
82
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')
93
94     if not os.path.exists(module_lib_py_dir):
95         print "Python directory %s does not exist" % module_lib_py_dir
96         return
97
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')
107
108     verbose = options.verbose
109
110     if options.clear:
111         rmtree(bin_dir)
112         rmtree(lib_dir)
113         rmtree(share_dir)
114         rmtree(doc_dir)
115         pass
116     
117     #directory bin/salome : create it and link content
118     mkdir(bin_dir)
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))
122         pass
123     
124     #directory lib/salome : create it and link content
125     mkdir(lib_dir)
126     for fn in os.listdir(module_lib_dir):
127         symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
128
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))
135             pass
136         pass
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))
141             pass
142         pass
143     else:
144         print module_lib_py_shared_dir, " doesn't exist"
145         pass    
146
147
148     #directory share/salome/resources : create it and link content
149     mkdir(share_dir)
150     for fn in os.listdir(module_share_dir):
151         symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
152
153     #html files in doc/salome directory
154     if os.path.exists(module_doc_dir):
155         mkdir(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))
160             pass
161         pass
162     
163     #directory doc/salome/gui : create it and link content
164     if os.path.exists(module_doc_gui_dir):
165         mkdir(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))
168             pass
169         pass
170     
171     #directory doc/salome/tui : create it and link content
172     if os.path.exists(module_doc_tui_dir):
173         mkdir(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))
176             pass
177         pass
178     
179 if __name__ == '__main__':
180     main()
181     pass