Back to index

salome-kernel  6.5.0
Functions | Variables
virtual_salome Namespace Reference

Functions

def mkdir
def symlink
def rmtree
def get_lib_dir
def link_module
def main

Variables

string py_version = 'python%s.%s'
int verbose = 0
 __lib__dir__ = None

Function Documentation

Definition at line 89 of file virtual_salome.py.

00089 
00090 def get_lib_dir():
00091     global __lib__dir__
00092     if __lib__dir__: return __lib__dir__
00093     import platform
00094     __lib__dir__ = "lib"
00095     return __lib__dir__
00096 
00097 # -----------------------------------------------------------------------------

Here is the caller graph for this function:

def virtual_salome.link_module (   options)

Definition at line 98 of file virtual_salome.py.

00098 
00099 def link_module(options):
00100     global verbose
00101 
00102     if not options.module:
00103         print "Option module is mandatory"
00104         return
00105 
00106     module_dir=os.path.abspath(options.module)
00107     if not os.path.exists(module_dir):
00108         print "Module %s does not exist" % module_dir
00109         return
00110 
00111     verbose = options.verbose
00112 
00113     home_dir = os.path.expanduser(options.prefix)
00114     #try to find python version of salome application and put it in versio
00115     pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(home_dir,get_lib_dir(),"python*.*"))]
00116     if not pys :
00117       versio=None
00118     else:
00119       versio=pys[0]
00120 
00121     pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(module_dir,get_lib_dir(),"python*.*"))]
00122     #check if the module has a python version compatible with application version
00123     if not pys :
00124       pyversio=versio or py_version
00125     elif versio is None:
00126       pyversio=pys[0]
00127     elif versio in pys:
00128       pyversio=versio
00129     else:
00130       #incompatible python versions
00131       print "incompatible python versions : application has version %s and module %s has not" % (versio,module_dir)
00132       return
00133 
00134     module_bin_dir=os.path.join(module_dir,'bin','salome')
00135     module_idl_dir=os.path.join(module_dir,'idl','salome')
00136     module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
00137     module_lib_py_dir=os.path.join(module_dir,get_lib_dir(),pyversio,'site-packages','salome')
00138     module_lib_py_shared_dir=os.path.join(module_dir,get_lib_dir(),pyversio,
00139                                           'site-packages','salome','shared_modules')
00140     module_share_dir=os.path.join(module_dir,'share','salome')
00141     module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
00142     module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
00143     module_doc_dir=os.path.join(module_dir,'doc','salome')
00144     module_sharedoc_dir=os.path.join(module_dir,'share','doc','salome')
00145     module_sharedoc_gui_dir=os.path.join(module_dir,'share','doc','salome','gui')
00146     module_sharedoc_tui_dir=os.path.join(module_dir,'share','doc','salome','tui')
00147 
00148     bin_dir=os.path.join(home_dir,'bin','salome')
00149     idl_dir=os.path.join(home_dir,'idl','salome')
00150     lib_dir=os.path.join(home_dir,'lib','salome')
00151     lib_py_dir=os.path.join(home_dir,'lib',pyversio,'site-packages','salome')
00152     lib_py_shared_dir=os.path.join(home_dir,'lib',pyversio,
00153                                    'site-packages','salome','shared_modules')
00154     share_dir=os.path.join(home_dir,'share','salome')
00155     doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
00156     doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
00157     doc_dir=os.path.join(home_dir,'doc','salome')
00158     sharedoc_dir=os.path.join(home_dir,'share','doc','salome')
00159     sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui')
00160     sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui')
00161 
00162     if options.clear:
00163         rmtree(bin_dir)
00164         rmtree(idl_dir)
00165         rmtree(lib_dir)
00166         rmtree(lib_py_dir)
00167         rmtree(share_dir)
00168         rmtree(doc_dir)
00169         rmtree(sharedoc_dir)
00170         pass
00171 
00172     #directory bin/salome : create it and link content
00173     if os.path.exists(module_bin_dir):
00174         mkdir(bin_dir)
00175         for fn in os.listdir(module_bin_dir):
00176             symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
00177             pass
00178         pass
00179     else:
00180         if verbose:
00181             print module_bin_dir, " doesn't exist"
00182         pass
00183 
00184     #directory idl/salome : create it and link content
00185     if os.path.exists(module_idl_dir):
00186         mkdir(idl_dir)
00187         for fn in os.listdir(module_idl_dir):
00188             symlink(os.path.join(module_idl_dir, fn), os.path.join(idl_dir, fn))
00189     else:
00190         if verbose:
00191             print module_idl_dir, " doesn't exist"
00192 
00193     #directory lib/salome : create it and link content
00194     if os.path.exists(module_lib_dir):
00195         mkdir(lib_dir)
00196         for fn in os.listdir(module_lib_dir):
00197             symlink(os.path.join(module_lib_dir, fn), os.path.join(lib_dir, fn))
00198             pass
00199         pass
00200     else:
00201         if verbose:
00202             print module_lib_dir, " doesn't exist"
00203         pass
00204 
00205     #directory lib/pyversio/site-packages/salome : create it and link content
00206     if not os.path.exists(module_lib_py_dir):
00207         print "Python directory %s does not exist" % module_lib_py_dir
00208     else:
00209         # Specific action for the package salome
00210         module_lib_pypkg_dir=os.path.join(module_lib_py_dir,"salome")
00211         lib_pypkg_dir=os.path.join(lib_py_dir,"salome")
00212         mkdir(lib_pypkg_dir)
00213         mkdir(lib_py_shared_dir)
00214         for fn in os.listdir(module_lib_py_dir):
00215             if fn == "shared_modules": continue
00216             if fn == "salome": continue
00217             symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
00218             pass
00219         if os.path.exists(module_lib_py_shared_dir):
00220             for fn in os.listdir(module_lib_py_shared_dir):
00221                 symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn))
00222                 pass
00223             pass
00224         if os.path.exists(module_lib_pypkg_dir):
00225             for fn in os.listdir(module_lib_pypkg_dir):
00226                 symlink(os.path.join(module_lib_pypkg_dir, fn), os.path.join(lib_pypkg_dir, fn))
00227                 pass
00228             pass
00229         else:
00230             if verbose:
00231                 print module_lib_py_shared_dir, " doesn't exist"
00232             pass
00233 
00234     #directory share/doc/salome (KERNEL doc) : create it and link content
00235     if os.path.exists(module_sharedoc_dir):
00236         mkdir(sharedoc_dir)
00237         for fn in os.listdir(module_sharedoc_dir):
00238             if fn == 'gui':continue
00239             if fn == 'tui':continue
00240             symlink(os.path.join(module_sharedoc_dir, fn), os.path.join(sharedoc_dir, fn))
00241             pass
00242         pass
00243 
00244     #directory share/doc/salome/gui : create it and link content
00245     if os.path.exists(module_sharedoc_gui_dir):
00246         mkdir(sharedoc_gui_dir)
00247         for fn in os.listdir(module_sharedoc_gui_dir):
00248             symlink(os.path.join(module_sharedoc_gui_dir, fn), os.path.join(sharedoc_gui_dir, fn))
00249             pass
00250         pass
00251 
00252     #directory share/doc/salome/tui : create it and link content
00253     if os.path.exists(module_sharedoc_tui_dir):
00254         mkdir(sharedoc_tui_dir)
00255         for fn in os.listdir(module_sharedoc_tui_dir):
00256             symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn))
00257             pass
00258         pass
00259 
00260     #directory share/salome : create it and link content
00261     if os.path.exists(module_share_dir):
00262         mkdir(share_dir)
00263         for fn in os.listdir(module_share_dir):
00264             if fn in ["resources","plugins"] :
00265                 # Create the directory and then link the content
00266                 mkdir(os.path.join(share_dir,fn))
00267                 for ffn in os.listdir(os.path.join(module_share_dir,fn)):
00268                     symlink(os.path.join(module_share_dir, fn, ffn), os.path.join(share_dir,fn, ffn))
00269             else:
00270                 #other directories (not resources)
00271                 symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn))
00272     else:
00273         print "share/salome directory %s does not exist" % module_share_dir
00274         pass
00275 
00276     #html files in doc/salome directory
00277     if os.path.exists(module_doc_dir):
00278         mkdir(doc_dir)
00279         for fn in os.listdir(module_doc_dir):
00280             if fn == 'gui':continue
00281             if fn == 'tui':continue
00282             symlink(os.path.join(module_doc_dir, fn), os.path.join(doc_dir, fn))
00283             pass
00284         pass
00285 
00286     #directory doc/salome/gui : create it and link content
00287     if os.path.exists(module_doc_gui_dir):
00288         mkdir(doc_gui_dir)
00289         for fn in os.listdir(module_doc_gui_dir):
00290             symlink(os.path.join(module_doc_gui_dir, fn), os.path.join(doc_gui_dir, fn))
00291             pass
00292         pass
00293 
00294     #directory doc/salome/tui : create it and link content
00295     if os.path.exists(module_doc_tui_dir):
00296         mkdir(doc_tui_dir)
00297         for fn in os.listdir(module_doc_tui_dir):
00298             symlink(os.path.join(module_doc_tui_dir, fn), os.path.join(doc_tui_dir, fn))
00299             pass
00300         pass
00301 
00302 # -----------------------------------------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file virtual_salome.py.

00303 
00304 def main():
00305     usage="""usage: %prog [options]
00306 Typical use is:
00307   python virtual_salome.py -v --prefix="." --module=/local/chris/SALOME2/RELEASES/Install/KERNEL_V3_1_0b1
00308 """
00309     parser = optparse.OptionParser(usage=usage)
00310 
00311     parser.add_option('-v', '--verbose', action='count', dest='verbose',
00312                       default=0, help="Increase verbosity")
00313 
00314     parser.add_option('--prefix', dest="prefix", default='.',
00315                       help="The base directory to install to (default .)")
00316 
00317     parser.add_option('--module', dest="module",
00318                       help="The module directory to install in (mandatory)")
00319 
00320     parser.add_option('--clear', dest='clear', action='store_true',
00321         help="Clear out the install and start from scratch")
00322 
00323     options, args = parser.parse_args()
00324     link_module(options)
00325     pass
00326 
00327 # -----------------------------------------------------------------------------

Here is the call graph for this function:

def virtual_salome.mkdir (   path)
Create a directory and all the intermediate directories if path does not exist

Definition at line 42 of file virtual_salome.py.

00042 
00043 def mkdir(path):
00044     """Create a directory and all the intermediate directories if path does not exist"""
00045     if not os.path.exists(path):
00046         if verbose:
00047             print 'Creating %s' % path
00048         os.makedirs(path)
00049     else:
00050         if verbose:
00051             print 'Directory %s already exists' % path
00052             pass
00053         pass
00054 
00055 # -----------------------------------------------------------------------------

Here is the caller graph for this function:

def virtual_salome.rmtree (   dir)
Remove (recursive) a directory if it exists

Definition at line 74 of file virtual_salome.py.

00074 
00075 def rmtree(dir):
00076     """Remove (recursive) a directory if it exists"""
00077     if os.path.exists(dir):
00078         print 'Deleting tree %s' % dir
00079         shutil.rmtree(dir)
00080     else:
00081         if verbose:
00082             print 'Do not need to delete %s; already gone' % dir
00083             pass
00084         pass
00085     pass
00086 
00087 # -----------------------------------------------------------------------------

Here is the caller graph for this function:

def virtual_salome.symlink (   src,
  dest 
)
Create a link if it does not exist

Definition at line 56 of file virtual_salome.py.

00056 
00057 def symlink(src, dest):
00058     """Create a link if it does not exist"""
00059     if not os.path.exists(dest):
00060         if os.path.lexists(dest):
00061             print "Do not create symlink %s. It already exists but it's broken" % dest
00062             return
00063         if verbose:
00064             print 'Creating symlink %s' % dest
00065             pass
00066         os.symlink(src, dest)
00067     else:
00068         if verbose:
00069             print 'Symlink %s already exists' % dest
00070         pass
00071     pass
00072 
00073 # -----------------------------------------------------------------------------

Here is the caller graph for this function:


Variable Documentation

Definition at line 88 of file virtual_salome.py.

string virtual_salome.py_version = 'python%s.%s'

Definition at line 36 of file virtual_salome.py.

Definition at line 38 of file virtual_salome.py.