Exemple #1
0
def matchSafe(fi,ex,safe,ck):
   # ~~> list all entries
   dp, _, filenames = walk(safe).next()
   if filenames == []: return True
   # ~~> match expression
   exnames = []
   for fo in filenames:
      if fnmatch(fo,ex):
         if ck > 1:  #TODO: try except if file access not granted
            try: remove(path.join(dp,fo))
            except:
               time.sleep(5) # /!\ addition for windows operating system
               try: remove(path.join(dp,fo))
               except Exception as e:
                  raise Exception([filterMessage({'name':'matchSafe::remove','msg':'I could not remove your existing file: '+path.join(dp,fo)},e,True)])
            continue
         exnames.append(path.join(dp,fo))
   if exnames == []: return True
   # ~~> check if newer files
   found = False
   for fo in exnames:
      if isNewer(fi,fo) == 0: found = True
   if not found: return False
   # ~~> remove all if one older
   for fo in exnames: remove(fo)
   return True
def createObjFiles(oname, oprog, odict, ocfg, bypass):
    # ~~ Assumes that the source filenames are in lower case ~~~~~~~~
    Root, Suffix = path.splitext(oname)

    # ~~ Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ObjDir = path.join(cfg['MODULES'][odict['libname']]['path'], ocfg)
    createDirectories(ObjDir)
    chdir(ObjDir)

    # ~~ Removes exisitng objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if odict['type'] == 'M':
        ModFile = path.join(ObjDir, Root + cfg['SYSTEM']['sfx_mod'])
        if path.exists(ModFile): remove(ModFile)
    ObjFile = path.join(ObjDir, Root + cfg['SYSTEM']['sfx_obj'])
    if path.exists(ObjFile): remove(ObjFile)

    # ~~ creation of the module (according to makefile.wnt + systel.ini):
    # ~~ ifort.exe /c /Ot /names:uppercase /convert:big_endian /extend_source:132 /include:..\..\..\postel3d\postel3d_V5P9\1 declarations_postel3d.f
    cmd = cfg['COMPILER']['cmd_obj']
    incs = cfg['MODULES'][odict['libname']]['incs']
    cmd = cmd.replace('<incs>', incs)
    mods = ''
    for mod in HOMERES[oprog]['deps']:
        mods = mods + path.join(
            cfg['MODULES'][odict['libname']]['mods'].replace(
                '<config>', cfg['MODULES'][mod]['path']), ocfg) + ' '
    #mods = mods + path.join(cfg['MODULES'][odict['libname']]['mods'].replace('<config>',cfg['MODULES'][odict['libname']]['path']),ocfg) + ' '
    cmd = cmd.replace('<mods>', mods)
    cmd = cmd.replace('<f95name>', path.join(odict['path'], oname))
    cmd = cmd.replace('<config>', ObjDir).replace('<root>', cfg['root'])

    if debug: print cmd
    mes = MESSAGES(size=10)
    try:
        tail, code = mes.runCmd(cmd, bypass)
    except Exception as e:
        raise Exception([
            filterMessage(
                {
                    'name':
                    'createObjFiles',
                    'msg':
                    'something went wrong, I am not sure why. Please verify your compiler installation or the python script itself.'
                }, e, bypass)
        ])
    if code != 0:
        raise Exception([{
            'name':
            'createObjFiles',
            'msg':
            'could not compile your FORTRAN (runcode=' + str(code) +
            ').\n      ' + tail
        }])
    if odict['type'] == 'M':
        print '   - created ' + ObjFile + ' and ' + ModFile
    else:
        print '   - created ' + ObjFile
    odict['time'] = 1
    #and remove .f from objList
    return
Exemple #3
0
def matchSafe(fi,ex,safe,ck):
   # ~~> list all entries
   dp, _, filenames = walk(safe).next()
   if filenames == []: return True
   # ~~> match expression
   exnames = []
   for fo in filenames:
      if fnmatch(fo,ex):
         if ck > 1:  #TODO: try except if file access not granted
            try: remove(path.join(dp,fo))
            except:
               time.sleep(5) # /!\ addition for windows operating system
               try: remove(path.join(dp,fo))
               except Exception as e:
                  raise Exception([filterMessage({'name':'matchSafe::remove','msg':'I could not remove your existing file: '+path.join(dp,fo)},e,True)])
            continue
         exnames.append(path.join(dp,fo))
   if exnames == []: return True
   # ~~> check if newer files
   found = False
   for fo in exnames:
      if isNewer(fi,fo) == 0: found = True
   if not found: return False
   # ~~> remove all if one older
   for fo in exnames: remove(fo)
   return True
Exemple #4
0
def moveFile2File(fi,fo):
   if fo == fi: return
   if path.exists(fo):
      try: remove(fo)
      except:
         time.sleep(5) # /!\ addition for windows operating system
         try: remove(fo)
         except Exception as e:
            raise Exception([filterMessage({'name':'moveFile2File::remove','msg':'I could not remove your existing file: '+fo},e,True)])
   if path.exists(fi):
      try: shutil.move(fi,fo)
      except:
         time.sleep(5) # /!\ addition for windows operating system
         try: shutil.move(fi,fo)
         except Exception as e:
            raise Exception([filterMessage({'name':'moveFile2File::shutil.move','msg':'I could not move your file: '+fi+'\n   ... maybe the detination exists?'},e,True)])
   return
Exemple #5
0
def moveFile2File(fi,fo):
   if fo == fi: return
   if path.exists(fo):
      try: remove(fo)
      except:
         time.sleep(5) # /!\ addition for windows operating system
         try: remove(fo)
         except Exception as e:
            raise Exception([filterMessage({'name':'moveFile2File::remove','msg':'I could not remove your existing file: '+fo},e,True)])
   if path.exists(fi):
      try: shutil.move(fi,fo)
      except:
         time.sleep(5) # /!\ addition for windows operating system
         try: shutil.move(fi,fo)
         except Exception as e:
            raise Exception([filterMessage({'name':'moveFile2File::shutil.move','msg':'I could not move your file: '+fi+'\n   ... maybe the detination exists?'},e,True)])
   return
Exemple #6
0
 def addAction(self,actions):
    try:
       i = getXMLKeys(actions,self.active)
    except Exception as e:
       raise Exception([filterMessage({'name':'ACTION::addACTION'},e,self.bypass)])  # only one item here
    else:
       self.active = i
    if self.dids.has_key(self.active["xref"]):
       raise Exception([{'name':'ACTION::addACTION','msg':'you are getting me confused, this xref already exists: '+self.active["xref"]}])
    self.dids.update({ self.active["xref"]:{} })
    self.code = self.active["code"]
    return self.active["target"]
Exemple #7
0
def compile_princi_lib(princi_file, cfgname, cfgs, incs_flags, ld_flags):
    """
       Compiling user fortran as a library

       @param user_fortran Name of the user_fortran
       @param cfgname Name of the configuration
       @param cfgs Configuration structure
       @param incs_flags Include flags for compilation
       @param ld_flags Linking flags for compilation
    """
    if not path.exists(princi_file):
        raise Exception([{
            'name':'compile_princi_lib',
            'msg':'could not find your FORTRAN: '+princi_file}])

    user_fortran = []
    # in case of a folder getting list of files
    if path.isdir(princi_file):
        list_files = listdir(princi_file)
        for fle in list_files:
            if re.match("^m[0-9]+.*", fle) and \
               fle.lower().endswith((".f", ".f90")):
                user_fortran.append(path.join(princi_file, fle))
        # Adding the other files
        for fle in list_files:
            if fle not in user_fortran and \
               fle.lower().endswith((".f", ".f90")):
                user_fortran.append(path.join(princi_file, fle))
    else:
        user_fortran = [princi_file]
    # Building linking commands
    command = cfgs[cfgname]['cmd_lib'].replace('<libname>',
                                               "libuser_fortran" + \
                                                cfgs[cfgname]['sfx_lib'])\
                                      .replace('<objs>', ' '.join(user_fortran))
    command += ' ' + incs_flags + ' ' + ld_flags

    mes = MESSAGES(size=10)
    print "command",command
    try:
        tail, code = mes.runCmd(command, False)
    except Exception as execpt:
        raise Exception([filterMessage(\
                {'name':'compile_princi_lib',
                 'msg':'something went wrong for no reason. \
                        Please verify your compiler installation.'
                }, execpt, False)])
    if code != 0:
        raise Exception([{
            'name':'compile_princi_lib',
            'msg':'could not compile your FORTRAN \
                   (runcode='+str(code)+').\n      '+tail}])
Exemple #8
0
 def addLayer(self,layer):
    # ~~> set default from the upper drawer
    layering = { "vars":self.drawing["vars"], "time":self.drawing["time"],
       "extract":self.drawing["extract"], "target":'',
       "title":'', "config":self.drawing["config"] }
    # ~~> reset from layer
    try:
       self.layering = getXMLKeys(layer,layering)
    except Exception as e:
       raise Exception([filterMessage({'name':'PLOT::addLayer'},e,self.bypass)])
    # ~~> filling-in remaining gaps
    self.layering = self.distributeMeta(self.layering)
    return self.layering["target"]
Exemple #9
0
 def addDraw(self,draw):       # plots: plot1d, plot2d, plot3d, plotpv, ...
    drawing = { "type":'', "xref":'', "deco": 'line', "size":'[10;10]',
       "time": '[-1]', "extract": '', "vars": '', "roi": '',
       "title": '', "config": 'distinct', 'outFormat': 'png',
       'layers':[] }     # draw includes an array of layers
    try:
       i = getXMLKeys(draw,drawing)
    except Exception as e:
       raise Exception([filterMessage({'name':'PLOT::addDraw'},e,self.bypass)])
    else:
       self.drawing = i
    self.active['xref'] = self.drawing["xref"]
    self.active['roi'] = self.drawing["roi"]
    if self.dids[self.active['type']].has_key(self.drawing["xref"]):
       raise Exception([{'name':'PLOT::addDRAW','msg':'you are getting me confused, this xref already exists: '+self.drawing["xref"]}])
    self.dids[self.active['type']].update({self.drawing["xref"]:self.drawing})
    return
Exemple #10
0
 def compilePRINCI(self,cfg,rebuild):
    if not "compile" in self.available.split(';'): return
    xref = self.active["xref"]; cfgname = self.active['cfg']
    active = self.dids[xref][cfgname]
    confirmed = False
    # ~~> principal PRINCI file
    value,default = getKeyWord('FICHIER FORTRAN',active['cas'],DICOS[active['dico']]['dico'],DICOS[active['dico']]['frgb'])
    princiFile = ''; princiSafe = ''
    if value != []:       # you do not need to compile the default executable
       princiFile = path.join(active['path'],eval(value[0]))
       if path.exists(princiFile):
          exeFile = path.join(active['safe'],path.splitext(eval(value[0]))[0] + cfg['SYSTEM']['sfx_exe'])
          if not path.exists(exeFile) or cfg['REBUILD'] == 0:
             print '     +> compiling princi file: ' + path.basename(princiFile)
             copyFile(princiFile,active['safe'])
             princiSafe = path.join(active['safe'],path.basename(princiFile))
             confirmed = True
       else:
          raise Exception([{'name':'ACTION::compilePRINCI','msg':'I could not find your PRINCI file: '+princiFile}])
    # ~~> associated PRINCI file
    for mod in active["links"]:
       link = active["links"][mod]
       value,default = getKeyWord('FICHIER FORTRAN',link['cas'],DICOS[link['dico']]['dico'],DICOS[link['dico']]['frgb'])
       princiFilePlage = ''
       if value != []:       # you do not need to compile the default executable
          princiFilePlage = path.join(active['path'],eval(value[0]))
          if path.exists(princiFilePlage):
             if princiSafe != '':
                putFileContent(princiSafe,getFileContent(princiSafe)+['']+getFileContent(princiFilePlage))
             else:
                print '     +> compiling princi file: ' + path.basename(princiFilePlage)
                exeFile = path.join(active['safe'],path.splitext(eval(value[0]))[0] + cfg['SYSTEM']['sfx_exe'])
                princiSafe = path.join(active['safe'],path.basename(princiFilePlage))
                copyFile(princiFilePlage,active['safe'])
             confirmed = True
          else:
             raise Exception([{'name':'ACTION::compilePRINCI','msg':'I could not find your PRINCI file: '+princiFilePlage}])
    if confirmed:
       try:
          compilePRINCI(princiSafe,active["code"],self.active['cfg'],cfg,self.bypass)
       except Exception as e:
          raise Exception([filterMessage({'name':'ACTION::compilePRINCI'},e,self.bypass)])  # only one item here
       #moveFile(exeFile,active['safe'])
       print '       ~> compilation successful ! created: ' + path.basename(exeFile)
Exemple #11
0
   def runCAS(self,options,cfg,rebuild):
      if not "run" in self.available.split(';'): return
      
      # ~~> prepare options as if run from command line
      specs = Values()
      setattr(specs,'configName',options.configName)
      setattr(specs,'configFile', options.configFile)
      setattr(specs,'sortieFile',True)
      setattr(specs,'tmpdirectory',True)
      setattr(specs,'rootDir', options.rootDir)
      setattr(specs,'version', options.version)
      setattr(specs,'wDir', options.wDir)
      setattr(specs,'compileonly', False)
      if options.hosts != '': setattr(specs,'hosts', options.hosts)
      else: setattr(specs,'hosts', gethostname().split('.')[0])
      setattr(specs,'split', options.split)
      setattr(specs,'run', options.run)
      setattr(specs,'merge', options.merge)
      if options.ncsize != '': self.active["ncsize"] = options.ncsize
      setattr(specs,'ncsize', self.active["ncsize"])
      setattr(specs,'nctile', '1')    # default but should not be used for validation
      setattr(specs,'bypass',self.bypass)

      # ~~> check on sorties and run
      casFile = path.join(self.active['path'],self.active["target"])
      sacFile = path.join(self.active['safe'],self.active["target"])
      sortieFiles = getLatestSortieFiles(sacFile)
      outputs = self.dids[self.active["xref"]][self.active['cfg']]['output']
      if matchSafe(casFile,self.active["target"]+'_*??h??min??s*.sortie',self.active['safe'],rebuild):
         print '     +> running cas file: ' + self.active["target"]
         for k in outputs: matchSafe('',path.basename(k[1][0]),self.active['safe'],2)
         try:
            sortieFiles = runCAS(self.active['cfg'],cfg,self.active["code"],sacFile,specs)
         except Exception as e:
            raise Exception([filterMessage({'name':'ACTION::runCAS'},e,self.bypass)])  # only one item here
      if sortieFiles != []: self.updateCFG({ 'sortie': sortieFiles })
Exemple #12
0
def main():
    """
      Main function that runs the mascaret executable in the current folder
   """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print '\n\nLoading Options and Configurations\n' + 72 * '~' + '\n'
    parser = ArgumentParser(\
       formatter_class=RawDescriptionHelpFormatter,
       description=('''\n\
Run the mascaret executable in the current folder, given a CAS file.
      '''))
    parser.add_argument("args", nargs='*')
    # ~~> Environment
    parser.add_argument(\
       "-c", "--configname",dest="configName",default='',
       help="specify configuration name, default is randomly found in the configuration file" )
    parser.add_argument(\
       "-f", "--configfile",dest="configFile",default='',
       help="specify configuration file, default is systel.cfg" )
    parser.add_argument(\
       "-r", "--rootdir",dest="rootDir",default='',
       help="specify the root, default is taken from config file" )
    parser.add_argument(\
       "-s", "--sortiefile",action="store_true",dest="sortieFile",default=False,
       help="specify whether there is a sortie file, default is no" )
    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # path to the root
    PWD = path.dirname(path.dirname(path.dirname(sys.argv[0])))
    if options.rootDir != '': PWD = options.rootDir
    # user configuration name
    USETELCFG = ''
    if 'USETELCFG' in environ: USETELCFG = environ['USETELCFG']
    if options.configName == '': options.configName = USETELCFG
    # user configuration file
    SYSTELCFG = path.join(PWD, 'configs')
    if 'SYSTELCFG' in environ: SYSTELCFG = environ['SYSTELCFG']
    if options.configFile != '': SYSTELCFG = options.configFile
    if path.isdir(SYSTELCFG): SYSTELCFG = path.join(SYSTELCFG, 'systel.cfg')
    options.configFile = SYSTELCFG
    options.bypass = False

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mes = MESSAGES()  # runcode takes its version number from the CAS file
    svnrev = ''
    svnurl = ''
    svnban = 'unknown revision'
    try:
        key_equals = re.compile(r'(?P<key>[^:]*)(?P<after>.*)', re.I)
        tail, code = mes.runCmd('svn info ' + PWD, True)
        for line in tail.split('\n'):
            proc = re.match(key_equals, line)
            if proc:
                if proc.group('key').strip() == 'Revision':
                    svnrev = proc.group('after')[1:].strip()
                if proc.group('key').strip() == 'URL':
                    svnurl = proc.group('after')[1:].strip()
    except:
        pass
    if svnrev + svnurl == '':
        print '\n'.join(banner('unknown revision'))
    else:
        if svnurl != '': print '\n'.join(banner(svnurl.split('/')[-1]))
        if svnrev != '': print '\n'.join(banner('rev. #' + svnrev))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if not path.isfile(options.configFile):
        print '\nNot able to get to the configuration file: ' + options.configFile + '\n'
        dircfg = path.abspath(path.dirname(options.configFile))
        if path.isdir(dircfg):
            print ' ... in directory: ' + dircfg + '\n ... use instead: '
            _, _, filenames = walk(dircfg).next()
            for fle in filenames:
                head, tail = path.splitext(fle)
                if tail == '.cfg':
                    print '    +> ', fle
        sys.exit(1)
    if len(options.args) < 1:
        print '\nThe name of the CAS file is required\n'
        parser.print_help()
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cas = options.args[0]

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cfgs = parseConfigFile(options.configFile, options.configName)
    cfgname = cfgs.iterkeys().next()

    xcpts = MESSAGES()

    # still in lower case
    if not cfgs[cfgname].has_key('root'): cfgs[cfgname]['root'] = PWD
    if options.rootDir != '':
        cfgs[cfgname]['root'] = path.abspath(options.rootDir)
    # parsing for proper naming
    cfg = parseConfig_RunningTELEMAC(cfgs[cfgname])

    try:
        createMascaretFiles(cfg, cas)
    except Exception as e:
        xcpts.addMessages(
            filterMessage({'name': '_____________\nruncode::main:\n'}, e,
                          options.bypass))


    mascaretExe = cfg['root'] + sep + 'builds'+ sep + cfgname + sep + 'bin' + \
                  sep + 'mascaret' + cfgs[cfgname]['sfx_exe'] + ' FichierCas.txt'
    try:
        tail, code = xcpts.runCmd(mascaretExe, options.bypass)
    except Exception as e:
        xcpts.addMessages(
            filterMessage(
                {
                    'name':
                    'processExecutable',
                    'msg':
                    'something went wrong for no reason. \
                                             Please verify your compiler installation.'
                }, e, options.bypass))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.notEmpty() or code != 0:
        print '\n\nHummm ... I could not complete my work.\n'+'~'*72\
        + xcpts.exceptMessages()
        sys.exit(1)


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print '\n\nMy work is done\n\n'
        sys.exit(0)
Exemple #13
0
                    {cfgname: {
                        'cfg': cfg,
                        'options': options
                    }})

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Running the XML commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        for xmlFile in xmls:
            print '\n\nFocused validation on ' + xmlFile + '\n' + '~' * 72 + '\n'
            try:
                report = reports.add(options.report, root, VERSION)
            except Exception as e:
                xcpts.addMessages([
                    filterMessage(
                        {
                            'name':
                            'runXML::main:\n      ' + path.dirname(xmlFile)
                        }, e, options.bypass)
                ])
                break
            r = []
            if xmlFile.replace(root, '') in report:
                r = report[xmlFile.replace(root, '')]['casts']
            # /!\ please do not reset the users environemnt
            #environ['USETELCFG'] = cfgname
            try:
                tic = time.time()
                r = runXML(path.realpath(xmlFile), xmls[xmlFile], r,
                           options.bypass, options.runOnly)
                toc = time.time()
                #if r == []: r = [{ 'fail':False, 'warn':False, 'value':1, 'title':'My work is done' }]
def createExeFiles(ename, ecfg, eprog, bypass):

    # ~~ Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ExeDir = path.join(cfg['MODULES'][eprog.lower()]['path'], ecfg)
    chdir(ExeDir)

    # ~~ Removes existing executables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if 'homere' in ename or 'systeme' in ename:
        ExeFile = path.join(ExeDir,
                            eprog + cfg['version'] + cfg['SYSTEM']['sfx_exe'])
        LibFile = path.join(ExeDir,
                            eprog + cfg['version'] + cfg['SYSTEM']['sfx_lib'])
        ObjCmd = path.join(ExeDir, eprog + cfg['version'] + '.cmdo')
        ExeCmd = path.join(ExeDir, eprog + cfg['version'] + '.cmdx')
    else:
        ExeFile = path.join(ExeDir, ename + cfg['SYSTEM']['sfx_exe'])
        LibFile = path.join(ExeDir, ename + cfg['SYSTEM']['sfx_lib'])
        ObjCmd = path.join(ExeDir, ename + '.cmdo')
        ExeCmd = path.join(ExeDir, ename + '.cmdx')
    #if cfg['COMPILER']['REBUILD'] > 0 and path.exists(ExeFile): remove(ExeFile)

    # ~~ Lists all system libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    LibFiles = ''
    for lib in HOMERES[ename.upper(
    )]['deps'][1:]:  # /!\ [1:] to create the exe from local objs.
        #ModDir = path.join(cfg['MODULES'][eprog.lower()]['path'],ecfg)
        l = path.join(ExeDir,
                      lib.lower() + cfg['version'] + cfg['SYSTEM']['sfx_lib'])
        if not path.exists(l):
            raise Exception([{
                'name': 'createExeFiles',
                'msg': 'Library missing:\n      ' + l
            }])
        LibFiles = LibFiles + l + ' '

    # ~~ Add external libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for lib in cfg['MODULES'][eprog]['libs'].split():
        # FD@EDF : temporary removal of the following action
        # => interesting but we should also support LDFLAGS as -lpthread -lmpich -lmed...
        #if not path.exists(lib): raise Exception([{'name':'createExeFiles','msg':'External library missing:\n      '+lib}])
        LibFiles = LibFiles + lib + ' '

    # ~~ Lists local objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ObjFiles = ''
    for obj, lib in HOMERES[ename.upper()]['add']:
        Root, Suffix = path.splitext(obj)
        if lib == eprog and obj.lower(
        ) + cfg['SYSTEM']['sfx_obj'] not in ObjFiles.split():
            o = Root.lower() + cfg['SYSTEM']['sfx_obj']
            if not path.exists(o):
                raise Exception([{
                    'name': 'createExeFiles',
                    'msg': 'Object missing:\n      ' + o
                }])
            ObjFiles = ObjFiles + o + ' '
    #if ObjFiles.strip() == '' and path.exists(ExeFile): return True
    for obj, lib in HOMERES[ename.upper()]['tag']:
        if lib == eprog and obj.lower(
        ) + cfg['SYSTEM']['sfx_obj'] not in ObjFiles.split():
            o = obj.lower() + cfg['SYSTEM']['sfx_obj']
            if not path.exists(o):
                raise Exception([{
                    'name': 'createExeFiles',
                    'msg': 'Object missing:\n      ' + o
                }])
            ObjFiles = ObjFiles + o + ' '

    # ~~ is executable necessary ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if path.exists(ExeFile):
        if cfg['COMPILER']['REBUILD'] > 0 and cfg['COMPILER']['REBUILD'] < 3:
            remove(ExeFile)
    if path.exists(ExeFile):
        if cfg['COMPILER']['REBUILD'] > 2 or cfg['COMPILER']['REBUILD'] == 0:
            refresh = False
            for o in ObjFiles.split():
                refresh = refresh or (isNewer(o, ExeFile) == 0)
            for l in LibFiles.split():
                refresh = refresh or (isNewer(l, ExeFile) == 0)
            if refresh: remove(ExeFile)
    if path.exists(ExeFile): return

    # ~~ creation of the exe (according to makefile.wnt + systel.ini):
    # ~~ xilink.exe /stack:536870912 /out:postel3dV5P9.exe declarations_postel3d.obj coupeh.obj lecdon_postel3d.obj postel3d.obj coupev.obj lecr3d.obj pre2dh.obj pre2dv.obj ecrdeb.obj nomtra.obj homere_postel3d.obj point_postel3d.obj ..\..\..\bief\bief_V5P9\1\biefV5P9.lib ..\..\..\damocles\damo_V5P9\1\damoV5P9.lib ..\..\..\paravoid\paravoid_V5P9\1\paravoidV5P9.lib ..\..\..\special\special_V5P9\1\specialV5P9.lib
    cmd = cfg['COMPILER']['cmd_exe']
    cmd = cmd.replace('<libs>', LibFiles)
    cmd = cmd.replace('<objs>', ObjFiles)
    cmd = cmd.replace('<exename>',
                      ExeFile).replace('<config>',
                                       ExeDir).replace('<root>', cfg['root'])

    xocmd = cfg['COMPILER']['cmd_obj']
    xocmd = xocmd.replace('<incs>', cfg['MODULES'][eprog]['incs'])
    mods = ''
    for mod in HOMERES[ename.upper()]['deps']:
        mods = mods + path.join(
            cfg['MODULES'][eprog]['mods'].replace(
                '<config>', cfg['MODULES'][mod]['path']), ecfg) + ' '
    xocmd = xocmd.replace('<mods>', mods)
    # <f95name> ... still to be replaced
    xocmd = xocmd.replace('<config>', ExeDir).replace('<root>', cfg['root'])

    xecmd = cfg['COMPILER']['cmd_exe']
    xecmd = xecmd.replace('<libs>', LibFile + ' ' + LibFiles)
    # <exename> and <objs> ... still to be replaced
    xecmd = xecmd.replace('<config>', ExeDir).replace('<root>', cfg['root'])

    if debug: print cmd
    mes = MESSAGES(size=10)
    try:
        tail, code = mes.runCmd(cmd, bypass)
        if tail != '':
            if path.exists(ObjCmd): remove(ObjCmd)
            if path.exists(ExeCmd): remove(ExeCmd)
    except Exception as e:
        if path.exists(ObjCmd): remove(ObjCmd)
        if path.exists(ExeCmd): remove(ExeCmd)
        raise Exception([
            filterMessage(
                {
                    'name':
                    'createExeFiles',
                    'msg':
                    'Could not link your executable. Please verify your external library installation or the python script itself.'
                }, e, bypass)
        ])
    if code != 0:
        if path.exists(ObjCmd): remove(ObjCmd)
        if path.exists(ExeCmd): remove(ExeCmd)
        raise Exception([{
            'name':
            'createExeFiles',
            'msg':
            'something went wrong, I am not sure why (runcode=' + str(code) +
            ').\n      ' + tail
        }])
    print '   - created ' + ExeFile
    putFileContent(ObjCmd, [xocmd])
    putFileContent(ExeCmd, [xecmd])
    return
def createLibFiles(lname, lcfg, lprog, bypass):
    # ~~ Assumes that all objects are in <config> ~~~~~~~~~~~~~~~~~~~
    # ~~ recreates the lib regardless ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    # ~~ Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    LibDir = path.join(cfg['MODULES'][lname]['path'], lcfg)
    chdir(LibDir)

    # LibFile is now created directly within prg[0]'s directory - /!\ hopefuly, the directory exists
    LibFile = path.join(path.join(cfg['MODULES'][lprog]['path'], lcfg),
                        lname + cfg['version'] + cfg['SYSTEM']['sfx_lib'])

    # ~~ Lists all objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ObjFiles = ''
    for obj, lib in HOMERES[item]['add']:
        Root, Suffix = path.splitext(obj)
        if lib == lname:
            ObjFiles = ObjFiles + (Root.lower() + cfg['SYSTEM']['sfx_obj'] +
                                   ' ')
    for obj, lib in HOMERES[item]['tag']:
        if lib == lname:
            ObjFiles = ObjFiles + (obj.lower() + cfg['SYSTEM']['sfx_obj'] +
                                   ' ')

    # ~~ is linkage necessary ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if cfg['COMPILER']['REBUILD'] > 0 and cfg['COMPILER'][
            'REBUILD'] < 3 and path.exists(LibFile):
        remove(LibFile)
    if cfg['COMPILER']['REBUILD'] > 2 and path.exists(LibFile):
        refresh = False
        for o in ObjFiles.split():
            refresh = refresh or (isNewer(o, LibFile)
                                  == 0) or (not path.exists(o))
        if refresh: remove(LibFile)
    if path.exists(LibFile): return True

    # ~~ creation of the librairies (according to makefile.wnt + systel.ini):
    # ~~ xilink.exe -lib /nologo /out:postel3dV5P9.lib declarations_postel3d.obj coupeh.obj lecdon_postel3d.obj postel3d.obj coupev.obj lecr3d.obj pre2dh.obj pre2dv.obj ecrdeb.obj nomtra.obj homere_postel3d.obj point_postel3d.obj
    cmd = cfg['COMPILER']['cmd_lib']
    cmd = cmd.replace('<objs>', ObjFiles)
    cmd = cmd.replace('<libname>', LibFile)

    if debug: print cmd
    mes = MESSAGES(size=10)
    try:
        tail, code = mes.runCmd(cmd, bypass)
    except Exception as e:
        raise Exception([
            filterMessage(
                {
                    'name':
                    'createLibFiles',
                    'msg':
                    'something went wrong, I am not sure why. Please verify your compilation or the python script itself.'
                }, e, bypass)
        ])
    if code != 0:
        raise Exception([{
            'name':
            'createLibFiles',
            'msg':
            'Could not pack your library (runcode=' + str(code) +
            ').\n      ' + tail
        }])
    print '   - created ' + LibFile
    #ModDir = path.join(cfg['MODULES'][prg[item][0]]['path'],lcfg)       # moves all the libraries relevant to a TELEMAC model
    #if path.exists(path.join(ModDir,path.basename(LibFile))): remove(path.join(ModDir,path.basename(LibFile)))
    #shutil.move(LibFile,ModDir)                                     # in the cfgdir (ModDir) of that model
    return
                                           key=MAKSYSTEL['deps'].get,
                                           reverse=True)
                HOMERES.update({item: MAKSYSTEL})

                # ~~ Creates modules and objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                for obj, lib in HOMERES[item]['add']:
                    Root, Suffix = path.splitext(obj)
                    try:
                        createObjFiles(obj.lower(), item,
                                       all[lib][Root.upper()], cfgname,
                                       options.bypass)
                    except Exception as e:
                        xcpts.addMessages([
                            filterMessage(
                                {
                                    'name':
                                    'compileTELEMAC::main:\n      +> creating objects: '
                                    + path.basename(obj)
                                }, e, options.bypass)
                        ])

# ~~ Creates libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                for lib in HOMERES[item]['deps']:
                    try:
                        createLibFiles(lib.lower(), cfgname, prg[item][0],
                                       options.bypass)
                    except Exception as e:
                        xcpts.addMessages([
                            filterMessage(
                                {
                                    'name':
                                    'compileTELEMAC::main:\n      +> creating library: '
Exemple #17
0
def runXML(xmlFile,xmlConfig,bypass):

   xcpt = []                            # try all keys for full report

   # ~~ Parse xmlFile ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   import xml.etree.ElementTree as XML
   print '... reading XML test specification file: ' + path.basename(xmlFile)
   f = open(xmlFile,'r')
   xmlTree = XML.parse(f)  # may need to try first and report error
   xmlRoot = xmlTree.getroot()
   f.close()

   # ~~ Meta data process ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   title = ""
   #meta = META(title)
   #print '\n... acquiring meta data'
   display = False

   # ~~ Action analysis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   do = ACTION(xmlFile,title,bypass)
   first = True
   for action in xmlRoot.findall("action"):
      if first:
         print '\n... looping through the todo list'
         first = False

      # ~~ Step 1. Common check for keys and CAS file ~~~~~~~~~~~~~~
      try:
         doadd = do.addAction(action)
      except Exception as e:
         xcpt.append(filterMessage({'name':'runXML','msg':'add todo to the list'},e,bypass))
         continue    # bypass rest of the loop
      else:
         casFile = path.join(do.active['path'],doadd)
         if not path.isfile(casFile):
            xcpt.append({'name':'runXML','msg':'could not find your CAS file'+path.basename(casFile)})
            continue    # bypass rest of the loop

      # ~~ Step 2. Loop over configurations ~~~~~~~~~~~~~~~~~~~~~~~~
      for cfgname in xmlConfig.keys():
         cfg = xmlConfig[cfgname]['cfg']
         if not do.addCFG(cfgname,cfg): continue

         # ~~> Parse DICO File and its IO Files default (only once)
         dicoFile = getDICO(cfg,do.active["code"])
         do.updateCFG({'dico':dicoFile})
         dico = DICOS[dicoFile]['dico']
         frgb = DICOS[dicoFile]['frgb']
         cas = readCAS(scanCAS(casFile),dico,frgb)
         if do.active["ncsize"] != '': setKeyValue('PROCESSEURS PARALLELES',cas,frgb,int(do.active["ncsize"]))
         do.updateCFG({'cas':cas})
         if not checkConsistency(cas,dico,frgb,cfg): continue

         # ~~> Create the safe
         createDirectories(do.active['safe'])
         idico = DICOS[dicoFile]['input']
         odico = DICOS[dicoFile]['output']
         # ~~> Define config-split storage
         sortieFiles,iFS,oFS = setSafe(casFile,cas,idico,odico,do.active['safe'])   # TODO: look at relative paths
         if sortieFiles != []: do.updateCFG({ 'sortie': sortieFiles })
         do.updateCFG({ 'input':iFS })
         do.updateCFG({ 'output':oFS })

         # ~~> Case of coupling
         cplages,defaut = getKeyWord('COUPLING WITH',cas,dico,frgb)
         links = {}
         for cplage in cplages:
            for mod in cfg['MODULES'].keys():
               if mod in cplage.lower():
                  # ~~> Extract the CAS File name
                  casFilePlage,defaut = getKeyWord(mod.upper()+' STEERING FILE',cas,dico,frgb)
                  if casFilePlage == []: casFilePlage = defaut[0]
                  else: casFilePlage = eval(casFilePlage[0])
                  casFilePlage = path.join(path.dirname(casFile),casFilePlage)
                  if not path.isfile(casFilePlage): raise Exception([{'name':'runCAS','msg':'missing coupling CAS file for '+mod+': '+casFilePlage}])
                  # ~~> Read the DICO File
                  dicoFilePlage = getDICO(cfg,mod)
                  dicoPlage = DICOS[dicoFilePlage]['dico']
                  frgbPlage = DICOS[dicoFilePlage]['frgb']
                  # ~~> Read the coupled CAS File
                  casPlage = readCAS(scanCAS(casFilePlage),dicoPlage,frgbPlage)
                  # ~~> Fill-in the safe
                  idicoPlage = DICOS[dicoFilePlage]['input']
                  odicoPlage = DICOS[dicoFilePlage]['output']
                  sortiePlage,iFSPlage,oFSPlage = setSafe(casFilePlage,casPlage,idicoPlage,odicoPlage,do.active['safe'])   # TODO: look at relative paths
                  links.update({mod:{}})
                  links[mod].update({ 'code':mod, 'target':path.basename(casFilePlage),
                     'cas':casPlage, 'frgb':frgbPlage, 'dico':dicoFilePlage,
                     'iFS':iFSPlage, 'oFS':oFSPlage, 'sortie':sortiePlage })
                  if sortiePlage != []: links[mod].update({ 'sortie':sortiePlage })
         if links != {}: do.updateCFG({ "links":links })

         # ~~ Step 3. Complete all actions ~~~~~~~~~~~~~~~~~~~~~~~~~
         # options.do takes: translate;run;compile and none
         doable = xmlConfig[cfgname]['options'].do
         if doable == '': doable = do.active["do"]
         if doable == '': doable = do.available
         display = display or xmlConfig[cfgname]['options'].display

         # ~~> Action type A. Translate the CAS file
         if "translate" in doable.split(';'):
            try:
               do.translateCAS(cfg['REBUILD'])
            except Exception as e:
               xcpt.append(filterMessage({'name':'runXML','msg':'   +> translate'},e,bypass))

         # ~~> Action type B. Analysis of the CAS file
         # TODO:
         # - comparison with DEFAULT values of the DICTIONARY
         #if "cas" in doable.split(';'):
         # - comparison of dictionnaries betwen configurations
         #if "dico" in doable.split(';'):

         # ~~> Action type C. Analysis of the PRINCI file
         # TODO:
         # - comparison with standard source files
         #if "princi" in doable.split(';'):
         #   out = diffTextFiles( f,t )
         # - comparison of called subroutines between configurations

         # ~~> Action type D. Compilation of PRINCI file
         # Contrary to the other step, Step 8 is completed where the original CAS file is
         # (for no particularly good reason)
         if "compile" in doable.split(';'):
            try:
               do.compilePRINCI(cfg,cfg['REBUILD'])
            except Exception as e:
               xcpt.append(filterMessage({'name':'runXML','msg':'   +> compile'},e,bypass))

         # ~~> Action type E. Running CAS files
         if "run" in doable.split(';'):
            try:
               do.runCAS(xmlConfig[cfgname]['options'],cfg,cfg['REBUILD'])
            except Exception as e:
               xcpt.append(filterMessage({'name':'runXML','msg':'   +> run'},e,bypass))

   # ~~ Extraction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   # did has all the IO references and the latest sortie files

   # ~~ Gathering targets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   plot = PLOT(title,bypass)
   first = True
   for typePlot in ["plot1d","plot2d","plot3d","plotpv"]:
      plot.addPlotType(typePlot)
      for ploting in xmlRoot.findall(typePlot):
         if first:
            print '\n... gathering targets through the plot list'
            first = False
         # ~~ Step 1. Common check for keys ~~~~~~~~~~~~~~~~~~~~~~~~
         try:
            plot.addDraw(ploting)
         except Exception as e:
            xcpt.append(filterMessage({'name':'runXML','msg':'add plot to the list'},e,bypass))
            continue   # bypass the rest of the for loop

         # ~~ Step 2. Cumul layers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         for layer in ploting.findall("layer"):
            try:
               target = plot.addLayer(layer)
            except Exception as e:
               xcpt.append(filterMessage({'name':'runXML','msg':'add layer to the list'},e,bypass))
               continue   # bypass the rest of the for loop

            # ~~> round up targets and their configurations
            xref,src = target.split(':')
            if not do.dids.has_key(xref):
               xcpt.append({'name':'runXML','msg':'could not find reference to draw the action: '+xref})

            # ~~> store layer and its configuration(s)
            try:
               findlayer = plot.findLayerConfig(do.dids[xref],src)
            except Exception as e:
               xcpt.append(filterMessage({'name':'runXML'},e))
               continue    # bypass the rest of the for loop
            else:
               plot.targetLayer(findlayer)
         plot.update(plot.drawing)

   # ~~ Matrix distribution by plot types ~~~~~~~~~~~~~~~~~~~~~~~~~~
   # /!\ configurations cannot be called "together" or "distinct" or "oneofall"
   first = True
   for typePlot in plot.dids.keys():
      if first:
         print '\n... plotting figures'
         first = False

      for xref in plot.dids[typePlot]:
         print '    +> reference: ',xref,' of type ',typePlot

         draw = plot.dids[typePlot][xref]
         xlayers = ''   # now done with strings as arrays proved to be too challenging
         for layer in draw["layers"]:
            if layer['config'] == 'together':
               xys = []
               for x in xlayers.split('|'): xys.append( (x+';'+':'.join( layer['fileName'].keys() )).strip(';') )
               xlayers = '|'.join(xys)
            elif layer['config'] == 'distinct':
               ylayers = layer['fileName'].keys()
               xys = []
               for i in range(len(ylayers)):
                  for x in xlayers.split('|'): xys.append( (x+';'+ylayers[i]).strip(';') )
               xlayers = '|'.join(xys)
            elif layer['config'] == 'oneofall':
               xys = []; cfg = layer['fileName'].keys()[0]     #/!\ you are sure to have at least one (?)
               for x in xlayers.split('|'): xys.append( (x+';'+cfg).strip(';') )
               xlayers = '|'.join(xys)
            else:
               if layer['config'] in layer['fileName'].keys():
                  xys = []
                  for x in xlayers.split('|'): xys.append( (x+';'+layer['config']).strip(';') )
               xlayers = '|'.join(xys)

         nbFig = 0; alayers = xlayers.split('|')
         for cfglist in alayers:
            # ~~> Figure name
            if len(alayers) == 1:
               figureName = '.'.join([xref,draw['outFormat']])
            else:
               nbFig += 1
               figureName = '.'.join([xref,str(nbFig),draw['outFormat']])
            print '       ~> saved as: ',figureName
            figureName = path.join(path.dirname(xmlFile),figureName)
            # ~~> Figure size
            draw["size"] = parseArrayPaires(draw["size"])
            # ~~> Create Figure
            figure = Figure(typePlot,draw,display,figureName)

            for layer,cfgs in zip(draw["layers"],cfglist.split(';')):
               for cfg in cfgs.split(':'):
                  for file in layer['fileName'][cfg][0]:

                     # ~~ 1d plots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     if typePlot == "plot1d":
                        #print typePlot,' ... drawing'
                        figure.draw( layer['fileName'][cfg][2], { 'file': file,
                           'vars': layer["vars"], 'extract':parseArrayPaires(layer["extract"]),
                           'type': draw['type'], 'time':parseArrayPaires(layer["time"])[0] } )

                     # ~~ 2d plots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     if typePlot == "plot2d":  # so far no plot type, but this may change
                        #print typePlot,' ... drawing'
                        figure.draw( layer['fileName'][cfg][2], { 'file': file,
                           'roi': parseArrayPaires(draw['roi']),
                           'vars': layer["vars"], 'extract':parseArrayPaires(layer["extract"]),
                           'type': draw['type'], 'time':parseArrayPaires(layer["time"])[0] } )


            figure.show()

   """
            # ~~> plot3d
               if plot["extract"] == '': plot["extract"] = "minmax"
   """
   # ~~ Error management ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   if xcpt != []:  # raise full report
      raise Exception({'name':'runXML','msg':'in xmlFile: '+xmlFile,'tree':xcpt})

   return