#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Define external program paths according to local configuration # # under linux, call config_ld_library_path(key) to extend LD_LIBRARY_PATH to be able to find .so # from prmClasses import * import os, os.path, shutil #, distutils.spawn class ExtProgs(PRMSet): def __init__(self, verb=False): fname = 'metaforExtProgs.cfg' PRMSet.__init__(self, fname, verb) def __getitem__(self, key): return self.pars[key].val def loadPaths(self): home = os.path.expanduser("~") #print("sys.path[0] = ", sys.path[0]) #loc = os.path.abspath('.') non, '.' n'est pas le programDir (et pas �vident de le trouver entre version Dev & installed) # et sys.path[0] est le baseDir (pas le programDir !!!) #print("home Path = ", home) #print("local Path = ", loc) #return [home, loc] return [home] def savePath(self): home = os.path.expanduser("~") return home def setDefaultPars(self): if len(self.pars)!=0: return if isUnix(): # Mesh generation TextPRM(self.pars, 'SAMCEF', 'Samcef', 'samcef') TextPRM(self.pars, 'GMSH', 'Gmsh', 'gmsh') TextPRM(self.pars, 'TRIANGLE', 'Triangle', 'triangle') TextPRM(self.pars, 'TETGEN', 'Tetgen', 'tetgen') TextPRM(self.pars, 'ISOSURF', 'Isosurf', 'isosurf') # Post pro (curve plot,...) TextPRM(self.pars, 'MATLAB', 'Matlab', 'matlab') TextPRM(self.pars, 'SCILAB', 'Scilab', 'scilab') TextPRM(self.pars, 'GNUPLOT', 'GnuPlot', 'gnuplot') # other post TextPRM(self.pars, 'LATEX', 'Latex', 'latex') TextPRM(self.pars, 'GHOSTSCRIPT', 'GhostScript', 'gs') TextPRM(self.pars, 'IMAGEMAGICK', 'Image Magick', 'convert') # Arcelor TextPRM(self.pars, 'LAM3', 'Lam3', 'lam3') TextPRM(self.pars, 'TEC3', 'Tec3', 'tec3') TextPRM(self.pars, 'XDONNEE', 'X-Donnee', 'xd') else: # windows # Mesh generation TextPRM(self.pars, 'SAMCEF', 'Samcef', 'samcef.cmd') TextPRM(self.pars, 'GMSH', 'Gmsh', 'gmsh.exe') TextPRM(self.pars, 'TRIANGLE', 'Triangle', 'triangle.exe') TextPRM(self.pars, 'TETGEN', 'Tetgen', 'tetgen.exe') TextPRM(self.pars, 'ISOSURF', 'Isosurf', 'isosurf.exe') # Post pro (curve plot,...) TextPRM(self.pars, 'MATLAB', 'Matlab', 'matlab.exe') TextPRM(self.pars, 'SCILAB', 'Scilab', 'scilab.bat') TextPRM(self.pars, 'GNUPLOT', 'GnuPlot', 'gnuplot.exe') # other post TextPRM(self.pars, 'LATEX', 'Latex', 'latex.exe') TextPRM(self.pars, 'GHOSTSCRIPT', 'GhostScript', 'gswin32c.exe') TextPRM(self.pars, 'IMAGEMAGICK', 'Image Magick', 'convert.exe') # Arcelor TextPRM(self.pars, 'LAM3', 'Lam3', 'lam3.exe') TextPRM(self.pars, 'TEC3', 'Tec3', 'tec3.exe') TextPRM(self.pars, 'XDONNEE', 'X-Donnee', 'xd.exe') def checkValidity(self, key): if key not in self.pars : print("%s is not a valid external program key from externalProgramPath... "%key) print("Solutions : ") print("\t 1. Check the key validity (must be in capital letter).") print("\t 2. Update the 'externalProgramPath' Script and rerun the configuration.") print("\t 3. If %s not in the Script last version, add it program in the Script..."%key) return False #if distutils.spawn.find_executable(os.path.splitext(self.pars[key].val)[0]) : # sous windows ne trouve que les .exe => ne marche pas avec .bat & .cmd if shutil.which(self.pars[key].val): return True else: print("%s is not found in %s ..."%(key, self.pars[key].val)) print("\t Check installation and accessibility...") print("\t Use 'externalProgramPathGui' to define the full program path (recommanded)") print("\t or add %s in your user path (not recommanded)"%key) return False def configAction(self): PRMAction(self.actions, 'a', self.pars['SAMCEF']) PRMAction(self.actions, 'b', self.pars['GMSH']) PRMAction(self.actions, 'c', self.pars['TRIANGLE']) PRMAction(self.actions, 'd', self.pars['TETGEN']) PRMAction(self.actions, 'e', self.pars['ISOSURF']) NoAction(self.actions) PRMAction(self.actions, 'f', self.pars['MATLAB']) PRMAction(self.actions, 'g', self.pars['SCILAB']) NoAction(self.actions) PRMAction(self.actions, 'h', self.pars['LATEX']) PRMAction(self.actions, 'i', self.pars['GHOSTSCRIPT']) PRMAction(self.actions, 'j', self.pars['IMAGEMAGICK']) NoAction(self.actions) PRMAction(self.actions, 'k', self.pars['LAM3']) PRMAction(self.actions, 'l', self.pars['TEC3']) PRMAction(self.actions, 'm', self.pars['XDONNEE']) NoAction(self.actions) SaveAction(self.actions , 'S') QuitAction(self.actions , 'Q') def config_ld_library_path(self, key): # add progPath/bin/../lib to LD_LIBRARY_PATH (else may not found .so) progLibPath = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(self.pars[key].val)),'..','lib')) if os.path.exists(progLibPath): for p in os.environ['LD_LIBRARY_PATH'].split(':'): if os.path.exists(p) and os.path.samefile(progLibPath, p): # deja dans le LD_LIBRARY_PATH => on skippe l'ajout break else : # pas trouvé dans le LD_LIBRARY_PATH => on ajoute dans le LD_LIBRARY_PATH os.environ['LD_LIBRARY_PATH'] = progLibPath + ':' + os.environ['LD_LIBRARY_PATH'] #================================================================================= def main(): progsConf = ExtProgs() #verb=True) progsConf.configAction() progsConf.menu() if __name__ == "__main__": try: import signal signal.signal(signal.SIGBREAK, sigbreak); except: pass main()