コード例 #1
0
    def __init__(self, fileName):

        # ~~> Read the steering file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if not path.exists(fileName):
            print '... Could not file your DELWAQ file: ', fileName
            sys.exit(1)
        self.dwqList = self.parseDWQ(getFileContent(fileName))

        # ~~> Read the geometry file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = self.dwqList['grid-indices-file']
        if not path.exists(fle):
            print '...Could not find the GEO file: ', fle
            sys.exit(1)
        self.geo = SELAFIN(fle)
        self.NPOIN3 = int(self.dwqList['grid-cells-first-direction'])
        if self.NPOIN3 != self.geo.NPOIN3:
            print '...In consistency in numbers with GEO file: ', self.NPOIN3, self.geo.NPOIN3
            sys.exit(1)
        self.NSEG3 = int(self.dwqList['grid-cells-second-direction'])

        # ~~> Read the CONLIM file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = self.dwqList['grid-coordinates-file']
        if not path.exists(fle):
            print '...Could not find the CONLIM file: ', fle
            sys.exit(1)
        self.conlim = CONLIM(fle)

        # ~~> Time records ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.HYDRO0T = int(self.dwqList['hydrodynamic-start-time'])
        self.HYDROAT = int(self.dwqList['hydrodynamic-stop-time'])
        self.HYDRODT = int(self.dwqList['hydrodynamic-timestep'])
        self.HYDROIT = 1 + (self.HYDROAT - self.HYDRO0T) / self.HYDRODT
        self.HYDRO00 = 0
        self.tfrom = self.HYDRO0T
        self.tstop = self.HYDROAT
コード例 #2
0
def runDamocles(exePath, paramFile, logFile=''):
    """
      Running the damocles executable
      param exePath Path the damocles executable
      param paramFile Path to the input aprameters file
      param logFile Redirecting ouput to that file if present
   """
    if not path.exists(exePath):
        print "You need to compile damocles to use it..."
        sys.exit(1)
    # Run Fortran program
    mes = MESSAGES(size=10)
    # TODO: Error handling when damocles crashes
    try:
        if logFile == '':
            print "%s < %s " % (exePath, paramFile)
            tail, code = mes.runCmd("%s < %s" % (exePath, paramFile), False)
        else:
            print "%s < %s > %s" % (exePath, paramFile, logFile)
            tail, code = mes.runCmd(
                "%s < %s > %s" % (exePath, paramFile, logFile), False)
    except OSError as exc:
        print exc.message
        sys.exit(1)
    if code != 0:
        raise Exception([
              {'name':'damocles',
               'msg':'Could not execute damocles'\
                     +'\n\nHere is the log:\n'
                     +'\n'.join(getFileContent(logFile))
              }])
コード例 #3
0
def PretreatmentTest(TestCasePath):
    if not path.exists(TestCasePath + sep + 'tmp'):
        mkdir(pathtotestcase + sep + 'tmp')
    chdir(pathtotestcase + sep + 'tmp')

    dicoFile = path.join(environ['HOMETEL'], 'sources', ARGS.validationFolder,
                         ARGS.validationFolder + '.dico')
    print '\n... reading the main module dictionary'
    frgb, dico = scanDICO(dicoFile)

    iFS, oFS = getIOFilesSubmit(frgb, dico)

    casFilesPath = glob.glob(pathtotestcase + sep + '*.cas')
    list_file = []
    for casFile in casFilesPath:
        shutil.copyfile(casFile, path.basename(casFile))
        cas = readCAS(scanCAS(getFileContent(casFile)), dico, frgb)
        user_fortran = None
        for key in iFS:
            print '~~~~~~~~~~>', key
            value, defaut = getKeyWord(key, cas, dico, frgb)
            if value != []:
                ffile = value[0].strip("'")
                shutil.copyfile(pathtotestcase + sep + ffile, ffile)
                if 'FORTRAN' in key:
                    user_fortran = ffile
        list_file.append((path.basename(casFile), user_fortran))
    return list_file
コード例 #4
0
def getXYn(file):
    # TODO: Read the whole header, for the time being head is copied
    #       over
    # TODO: Read multiple variables depending on type and on a list

    # ~~ Get all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    core = getFileContent(file)

    # ~~ Parse head ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    icore = 0
    fileType = None
    while re.match(ken_header, core[icore]):
        # ~~> instruction FileType
        proc = re.match(asc_FileType, core[icore])
        if proc: fileType = proc.group('type').lower()
        # ... more instruction coming ...
        icore += 1
    head = core[0:icore]
    if fileType == None:
        proc = re.match(var_3dbl, core[icore] + ' ')
        if not proc:
            proc = re.match(var_2dbl, core[icore] + ' ')
            if not proc:
                print '\nCould not parse the first record: ' + core[icore]
                sys.exit()
            else:
                fileType = 'xy'
        else:
            fileType = 'xyz'

    # /!\ icore starts the body

    # ~~ Parse body ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # This is also fairly fast, so you might not need a progress bar
    xyz = []  #; pbar = ProgressBar(maxval=len(core)).start()
    while icore < len(core):
        if fileType == 'xy':
            proc = re.match(var_2dbl, core[icore] + ' ')
            if not proc:
                print '\nCould not parse the following xyz record: ' + core[
                    icore]
                sys.exit()
            xyz.append(
                [float(proc.group('number1')),
                 float(proc.group('number2'))])
        elif fileType == 'xyz':
            proc = re.match(var_3dbl, core[icore] + ' ')
            if not proc:
                print '\nCould not parse the following xyz record: ' + core[
                    icore]
                sys.exit()
            xyz.append([
                float(proc.group('number1')),
                float(proc.group('number2')),
                float(proc.group('number3'))
            ])
        icore += 1
    #pbar.finish()

    return head, fileType, xyz
コード例 #5
0
ファイル: parserJanet.py プロジェクト: ogoe/OpenTelemac
def getINSEL(file):
   # ~~ Get all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   core = getFileContent(file)
   if not re.match(dat_footer,core[len(core)-1]):
      print '\nCould not parse the following end line of the file: '+core[len(core)-1]
      sys.exit(1)

   # ~~ First scan at INSEL and DAMM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   # This is also fairly fast, so you might not need a progress bar
   core.pop(len(core)-1)
   poly = []; vals = []; typ = []; npoin = 0
   iline = 0; xyi = []; val = []; fileType = True
   while iline < len(core):
      proco = re.match(dat_openh,core[iline])
      if proco: t = 0
      procc = re.match(dat_closh,core[iline])
      if procc: t = 1
      if proco or procc:
         iline += 1
         if xyi != []:
            poly.append(xyi); npoin += len(xyi); typ.append(t); vals.append(val)
            xyi = []; val = []
      else:
         proc = re.match(var_3dbl,core[iline].strip())
         if proc:
            xyi.append((proc.group('number1'),proc.group('number2')))
            val.append(proc.group('number3'))
         else:
            fileType = False
            proc = re.match(var_2dbl,core[iline].strip())
            if proc:
               xyi.append((proc.group('number1'),proc.group('number2')))
               val.append('')
            else:
               print '\nCould not parse the following polyline record: '+core[iline]
               sys.exit(1)
      iline += 1
   poly.append(xyi); npoin += len(xyi); typ.append(t); vals.append(val)

   # ~~ Second scan at INSEL and DAMM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   # This is also fairly fast, so you might not need a progress bar
   if fileType:
      for pline in range(len(poly)):
         for iline in range(len(poly[pline])):
            a,b = poly[pline][iline]
            poly[pline][iline] = [ float(a),float(b) ]
            vals[pline][iline] = [ float(c) ]
         poly[pline] = np.asarray(poly[pline])
   else:
      for pline in range(len(poly)):
         for iline in range(len(poly[pline])):
            a,b = poly[pline][iline]
            poly[pline][iline] = [ float(a),float(b) ]
         poly[pline] = np.asarray(poly[pline])
         vals = []

   return fileType,npoin,poly,vals,typ
コード例 #6
0
ファイル: parserXML.py プロジェクト: neitomic/openmpi-docker
 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)
コード例 #7
0
def getInS(file):
    # TODO: Read the whole header, for the time being head is copied
    #       over
    # TODO: Read variables depending on type and on a list

    # ~~ Get all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    core = getFileContent(file)

    # ~~ Parse head ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    icore = 0
    while re.match(ken_header, core[icore]):
        # ~~> instruction FileType
        proc = re.match(asc_FileType, core[icore])
        if proc: fileType = proc.group('type').lower()
        # ... more instruction coming ...
        icore += 1
    head = core[0:icore]
    # /!\ icore starts the body

    # ~~ Parse body ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # This is also fairly fast, so you might not need a progress bar
    poly = []
    type = []
    npoin = 0
    while icore < len(core):
        # ~~> polygon head
        proc = re.match(var_1int, core[icore])
        if not proc:
            print '\nCould not parse the following polyline header: ' + core[
                icore]
            sys.exit()
        nrec = int(proc.group('number'))
        icore += 1
        xyi = []
        for irec in range(nrec):
            proc = re.match(var_2dbl, core[icore + irec])
            if not proc:
                print '\nCould not parse the following polyline record: ' + core[
                    icore + irec + 1]
                sys.exit()
            xyi.append(
                [float(proc.group('number1')),
                 float(proc.group('number2'))])
        if xyi != []:
            cls = 0
            if isClose(xyi[0], xyi[len(xyi) - 1], size=10):
                xyi.pop(len(xyi) - 1)
                cls = 1
            poly.append(np.asarray(xyi))
            type.append(cls)
        npoin += len(xyi)
        icore += nrec

    return head, fileType, npoin, poly, type
コード例 #8
0
def getLQD(file):
    # ~~ Get all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    core = getFileContent(file)

    # ~~ Parse head ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    icore = 0
    while re.match(lqd_header, core[icore]):
        icore += 1
    head = core[0:icore]
    # /!\ icore starts the body

    # ~~ Parse variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    jcore = icore + 1
    while icore < len(core) and jcore < len(core):
        if re.match(lqd_header, core[icore]):
            icore += 1
            jcore += 1
            continue
        if re.match(lqd_header, core[jcore]):
            jcore += 1
            continue
        core[icore].replace(',', ' ')
        core[jcore].replace(',', ' ')
        # ~~> Variable header
        if core[icore].split()[0].upper() != 'T':
            print '\nThought I would find T for this LQD file on this line: ' + core[
                icore]
            sys.exit(1)
        if len(core[icore].split()) != len(core[jcore].split()):
            print '\nThought I to corresponding units for this LQD file on this line: ' + core[
                jcore]
            sys.exit(1)
        vrs = zip(core[icore].upper().split(), core[jcore].upper().split())

    # ~~ Size valid values ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    icore = jcore + 1
    while icore < len(core):
        if not re.match(lqd_header, core[jcore]): icore += 1

    # ~~ Parse body ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # This is also fairly fast, so you might not need a progress bar
    t = np.zeros(jcore - icore)
    z = np.zeros(len(vrs) - 1, jcore - icore)
    itime = 0
    for icore in core[jcore + 1:]:
        if re.match(lqd_header, icore): continue
        values = icore.replace(',', ' ').split()
        t[itime] = float(values[0])
        for ivar in range(len(values[1:])):
            z[itime][ivar] = float(values[ivar])

    return head, vrs[1:], t, z
コード例 #9
0
def generate_ref_from_dict(exePath, dictionary, latexFile, lng, cleanup):
    """
      brief Generate the Latex file for the
            reference manual from the dictionary

      param exePath Path to homere_damocles executable
      param dictionary Path to the dictionary to read
      param latexFile Name of the outpu latex file that will
                      contain the reference manual
      param lng Language for the reference manual
                1: French
                2: English
   """
    #Building input parameter file
    paramFile = path.join(path.dirname(latexFile), 'gen_ref.par')
    logFile = path.join(path.dirname(latexFile), 'gen_ref.log')
    # Cleanup
    if (cleanup):
        if path.exists(paramFile):
            remove(paramFile)
        if path.exists(logFile):
            remove(logFile)
        if path.exists(latexFile):
            remove(latexFile)
    else:
        # Creating parameter file for damocles
        with open(paramFile, 'w') as f:
            f.write('LATEX' + '\n')
            f.write(dictionary + '\n')
            f.write(latexFile + '\n')
            f.write(lng + '\n')
        # Removing LaTeX file if already there
        if path.exists(latexFile):
            remove(latexFile)
        # Run Fortran program
        mes = MESSAGES(size=10)
        # TODO: Error handling when damocles crashes
        try:
            print "%s < %s > %s" % (exePath, paramFile, logFile)
            tail, code = mes.runCmd(
                "%s < %s > %s" % (exePath, paramFile, logFile), False)
        except OSError as exc:
            print exc.message
            sys.exit(1)
        if code != 0:
            raise Exception([
                  {'name':'runPARTEL',
                   'msg':'Could not generated data from dictionary '\
                         +'\n\nHere is the log:\n'
                         +'\n'.join(getFileContent(logFile))
                  }])
コード例 #10
0
def scanCAS(cas):
    keylist = []
    casLines = getFileContent(cas)
    # ~~ clean comments
    core = []
    for i in range(len(casLines)):
        line = casLines[i].replace('"""',
                                   "'''").replace('"', "'").replace("''", '"')
        proc = re.match(key_comment, line + '/')
        line = proc.group('before').strip() + ' '
        proc = re.match(emptyline, line)
        if not proc: core.append(line)
    casStream = (' '.join(core)).replace('  ', ' ')
    # ~~ clean values to keep only the keys
    while casStream != '':
        # ~~ non-key
        proc = re.match(key_none, casStream)
        if proc:
            casStream = proc.group('after')
            continue
        # ~~ key
        proc = re.match(key_equals, casStream)
        if not proc:
            print '... hmmm, did not see this one coming ...'
            break
        kw = proc.group('key').strip()
        casStream = proc.group('after')  # still hold the separator
        # ~~ val
        proc = re.match(val_equals, casStream)
        if not proc:
            print 'no value to keyword ', kw
            sys.exit()
        val = []
        while proc:
            val.append(proc.group('val').replace("'", ''))
            casStream = proc.group('after')  # still hold the separator
            proc = re.match(val_equals, casStream)
        keylist.append([kw, val])

    # ~~ sort out the groups, starting with 'NOM'
    keywords = {}
    while keylist != []:
        keywords.update({keylist[0][0]: keylist[0][1]})
        keylist.pop(0)

    return keywords
コード例 #11
0
def gretel_python(t2d, ncsize, casFile):
    dicoFile = path.join(environ['HOMETEL'], 'sources', ARGS.validationFolder,
                         ARGS.validationFolder + '.dico')
    print '\n... reading the main module dictionary'
    frgb, dico = scanDICO(dicoFile)
    _, oFS = getIOFilesSubmit(frgb, dico)
    cas = readCAS(scanCAS(getFileContent(casFile)), dico, frgb)
    value, defaut = getKeyWord('GEOMETRY FILE', cas, dico, frgb)
    geo_file = value[0].strip("'")
    for key in oFS:
        value, defaut = getKeyWord(key, cas, dico, frgb)
        if value != []:
            ffile = value[0].strip("'")
            if oFS[key].split(';')[5][0:7] == 'SELAFIN':
                ierr = t2d.api_inter.run_gretel(t2d.my_id, geo_file,
                                                'SERAFIN ', ffile, 'SERAFIN ',
                                                ncsize, 0)
コード例 #12
0
def partel_python(t2d, ncsize, casFile):
    dicoFile = path.join(environ['HOMETEL'], 'sources', ARGS.validationFolder,
                         ARGS.validationFolder + '.dico')
    print '\n... reading the main module dictionary'
    frgb, dico = scanDICO(dicoFile)
    iFS, _ = getIOFilesSubmit(frgb, dico)
    cas = readCAS(scanCAS(getFileContent(casFile)), dico, frgb)
    value, defaut = getKeyWord('BOUNDARY CONDITIONS FILE', cas, dico, frgb)
    cli_file = value[0].strip("'")
    for key in iFS:
        value, defaut = getKeyWord(key, cas, dico, frgb)
        if value != []:
            ffile = value[0].strip("'")
            if iFS[key].split(';')[5][0:7] == 'SELAFIN':
                ierr = t2d.api_inter.run_partel(t2d.my_id, ffile, cli_file,
                                                ncsize, 1, 'SERAFIN ', ' ',
                                                ' ', ' ')
コード例 #13
0
   def draw(self,type,what,fig):
      
      if 'sortie' in type.lower():
         # ~~> Load data
         sortie = getFileContent(what['file'])
         # ~~> Extract data
         data = getValueHistorySortie(sortie,what['vars'])
         # ~~> Deco
         # ~~> Draw data
         drawHistoryLines(plt,data,deco)

      elif 'SELAFIN' in type.upper():
         # ~~> Load data
         slf = SELAFIN(what['file'])

         if what['type'] == 'history':
            # ~~> Extract data
            vars = subsetVariablesSLF(what["vars"],slf.VARNAMES)
            support = xyLocateMeshSLF(what["extract"],slf.NELEM3,slf.IKLE,slf.MESHX,slf.MESHY)
            data = getValueHistorySLF(slf.file,slf.tags,what['time'],support,slf.TITLE,slf.NVAR,slf.NPOIN3,vars)
            # ~~> Deco
            if what.has_key('roi'):
               if what['roi'] != []: deco['roi'] = what['roi']
            # ~~> Draw data
            drawHistoryLines(plt,data,deco)
            
         elif what['type'] == 'v-section':
            # ~~> Extract data
            vars = subsetVariablesSLF(what["vars"],slf.VARNAMES)
            support = crossLocateMeshSLF(what["extract"],slf.NELEM3,slf.IKLE,slf.MESHX,slf.MESHY)
            data = getValuePolylineSLF(slf.file,slf.tags,what['time'],support,slf.TITLE,slf.NVAR,slf.NPOIN3,vars)
            # ~~> Deco
            deco['roi'] = [ [np.min(slf.MESHX),np.min(slf.MESHY)], [np.max(slf.MESHX),np.max(slf.MESHY)] ]
            if what.has_key('roi'):
               if what['roi'] != []: deco['roi'] = what['roi']
            # ~~> Draw data
            drawPolylineLines(plt,data,deco)

         else: print '... do not know how to draw this type: ' + what['type']

      else:
         print '... do not know how to draw this format: ' + type
コード例 #14
0
    def getNextFile(self):
        # ~~ always 1st file in the list ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        while 1:
            if self.leftFileNames == []: return False
            frf = self.leftFileNames.pop(0)
            frd = path.dirname(frf)
            gbd = path.join(path.dirname(frd), self.linguist)
            if not path.isdir(gbd): mkdir(gbd)
            self.outFileName = path.join(gbd, path.basename(frf))
            if path.isfile(path.splitext(self.outFileName)[0] + '.noe'):
                frf = path.splitext(self.outFileName)[0] + '.noe'
                break
            if not path.isfile(self.outFileName):
                break

        self.doneLines = []
        self.leftLines = getFileContent(frf)

        if path.splitext(frf)[1] == '.noe': remove(frf)

        return True
コード例 #15
0
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    cfgs = parseConfigFile(options.configFile, options.configName)

    #  /!\  for testing purposes ... no real use
    for cfgname in cfgs:
        # still in lower case
        if not cfgs[cfgname].has_key('root'): cfgs[cfgname]['root'] = PWD
        if options.rootDir != '': cfgs[cfgname]['root'] = options.rootDir
        # parsing for proper naming
        if options.rank != '': cfgs[cfgname]['val_rank'] = options.rank
        cfg = parseConfig_ValidateTELEMAC(cfgs[cfgname])

        debug = True

        for mod in cfg['VALIDATION']:
            # ~~ Scans all CAS files to launch validation ~~~~~~~~~~~~~~~~~~~~~~
            print '\n\nConfiguration ' + cfgname + ', Module ' + mod + '\n' + '~' * 72 + '\n'
            print '... reading module dictionary'
            frgb, dico = scanDICO(
                path.join(path.join(cfg['MODULES'][mod]['path'], 'lib'),
                          mod + '.dico'))
            for casFile in cfg['VALIDATION'][mod]:
                print '... CAS file: ', casFile
                casKeys = readCAS(scanCAS(getFileContent(casFile)), dico, frgb)
                #/!\ for testing purposes ... no real use.
                #/!\ Note that casKeys is made of lines,(keys,values)

    sys.exit(0)
コード例 #16
0
        print '\n    +> ' + '\n    |  '.join(
            cfgs[cfgname]['brief'].split('\n')) + '\n'
    print '    +> root:          ' + cfgs[cfgname]['root']
    print '    +> modules:       ' + cfgs[cfgname][
        'modules'] + '\n\n' + '~' * 72 + '\n'

    # ~~ Scans all source files to build a relation database ~~
    fic, mdl, sbt, fct, prg, dep, racine = scanSources(cfgname, cfg, BYPASS)

    # ~~ Scann all source files to update Doxygen ~~~~~~~~~~~~~~~~
    for mod in fic:
        print '\nCreating the DOXYGEN headers for ' + mod + '\n' + '~' * 72 + '\n'
        for ifile in fic[mod]:

            # ~~ Read the content of the source file ~~~~~~~~~~~~
            ilines = getFileContent(ifile)
            # ~~ Update its Doxygen content ~~~~~~~~~~~~~~~~~~~~~
            olines = createDOXYGEN(ifile, ilines, mod, racine)
            # ~~ Make sure the distination exists ~~~~~~~~~~~~~~~
            ofile = ifile.replace(cfg['root'], cfg['doxydocs'])
            createDirectories(path.dirname(ofile))
            # ~~ Write the content of the source file ~~~~~~~~~~~
            putFileContent(ofile, olines)

    # ~~ Run Doxygen ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print '\nNow running DOXYGEN within ' + cfg[
        'doxydocs'] + '\n' + '~' * 72 + '\n'
    chdir(cfg['doxydocs'])
    if not path.exists(cfgs[cfgname]['cmd_doxygen']):
        print 'Do not know where to find ', cfgs[cfgname]['cmd_doxygen']
        print ' ... you can correct this through the key cmd_doxygen in your configuration file'
コード例 #17
0
def replaceDOXYGEN(doxydocs):

    iTextList = [('<!DOCTYPE HTML PUBLIC', '<BODY BGCOLOR="#FFFFFF">'),
                 ('<DIV class="div-page">', '<hr>'),
                 ('<div class="header">', '<div class="summary">'),
                 ('<hr>\n<div class="div-footer">', '</html>'),
                 ('<dl class="user"><dt><b', '>'), ('</b></dt><d', 'd><br/>')]
    oTextList = [
        r"""<!DOCTYPE install PUBLIC "-//Joomla! 2.5//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.6/template-install.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
   <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <meta name="keywords" content="open, telemac, mascaret, hydraulique, surface libre, houle, vague, hydraulic, free surface, wave, sediment" />
      <meta name="robots" content="index, follow" />
      <meta name="date" content="2013-07-24T16:49:04+0100"/>
      <meta name="description" content="The open TELEMAC-MASCARET system is a set of software for free surface numerical modelling of:\n* 2D, 3D Hydrodynamics,\n* Sediment (sand and muds),\n* Waves." />
      <TITLE>The open TELEMAC-MASCARET system: 2D, 3D hydrodynamics sediment waves simulation system</TITLE>
      <link rel="shortcut icon" href="./images/favicon.ico" type="image/vnd.microsoft.icon" />
      <script src="./images/jquery-1.4.2.min.js" type="text/javascript"></script>
      <link rel="stylesheet" href="./images/system.css" type="text/css" />
      <link rel="stylesheet" href="./images/position.css" type="text/css" media="screen,projection" />
      <link rel="stylesheet" href="./images/layout.css" type="text/css" media="screen,projection" />
      <link rel="stylesheet" href="./images/general.css" type="text/css" />
      <link rel="stylesheet" href="./images/principal.css" type="text/css" />
      <style type="text/css">
      #ahgalleryOTconsortium { margin-left: auto; margin-right: auto; margin-top: 0px !important; margin-bottom: 0px !important; width: 1000px; }
      #ahgalleryOTconsortium ul.hover_block0, #ahgalleryOTconsortium ul.hover_block1, #ahgalleryOTconsortium ul.hover_block2 { display: block; overflow: hidden; padding-top: 20px; padding-left: 2px; background: transparent; margin-left: 2px; margin-top: 0 !important; margin-bottom: 0 !important; }
      #ahgalleryOTconsortium ul.bottom_block { padding-bottom: 20px ; }
      #ahgalleryOTconsortium ul.hover_block0 li.item, #ahgalleryOTconsortium ul.hover_block1 li.item, #ahgalleryOTconsortium ul.hover_block2 li.item { margin-left: 0; padding-left: 0; list-style:none; list-style-position: inside; float:left; background: transparent; width: 150px; position: relative; }
      #ahgalleryOTconsortium ul.hover_block0 li a.teaser, #ahgalleryOTconsortium ul.hover_block1 li a.teaser , #ahgalleryOTconsortium ul.hover_block2 li a.teaser{ display: block; position: relative; overflow: hidden; height: 60px; width: 130px; padding: 1px; }
      #ahgalleryOTconsortium ul.hover_block0 li div.teaser, #ahgalleryOTconsortium ul.hover_block1 li div.teaser , #ahgalleryOTconsortium ul.hover_block2 li div.teaser { display: block; position: relative; overflow: hidden; height: 60px; width: 140px; padding: 1px; }
      #ahgalleryOTconsortium ul.hover_block0 li img.overlay, #ahgalleryOTconsortium ul.hover_block1 li img.overlay, #ahgalleryOTconsortium ul.hover_block2 li img.overlay { margin: 0; position: absolute; top: 5px; left: 0; border: 0; }
      </style>
      <script type="text/javascript" src="./images/hide.js"></script>
      <script type="text/javascript">
         window.addEvent(\'load\', function() {
            new JCaption(\'img.caption\');
         });
         window.addEvent(\'domready\', function() {
            $$(\'.hasTip\').each(function(el) {
               var title = el.get(\'title\');
               if (title) {
                  var parts = title.split(\'::\', 2);
                  el.store(\'tip:title\', parts[0]);
                  el.store(\'tip:text\', parts[1]);
            }});
            var JTooltips = new Tips($$(\'.hasTip\'), { maxTitleChars: 50, fixed: false});
         });
      </script>
      <link href="./images/tabsVTK.css" rel="stylesheet" type="text/css"/>
      <link href="./images/searchVTK.css" rel="stylesheet" type="text/css"/>
      <script type="text/javaScript" src="./images/searchVTK.js"></script>
      <link href="./images/doxygenVTK.css" rel="stylesheet" type="text/css"/>
      </HEAD>
   <BODY BGCOLOR="#FFFFFF">""", """<div id="all">
    <div id="header">
        <div class="logoheader">
            <h1 id="logo">open TELEMAC-MASCARET               <span class="header1">The mathematically superior suite of solvers</span></h1>
         </div>
         <div class="bar-top" >
         <ul class="menu">
          <li><a href="http://www.opentelemac.org/" ><img src="./images/OTM_Home-icon_15pix_212-118-0.png" alt="Home" /><span class="image-title">Home</span> </a></li>
       <li><a href="http://www.opentelemac.org/index.php/contact2"><img src="./images/OTM_Mail-icon_15pix_212-118-0.png" alt="Contact"/><span class="image-title">CONTACT</span> </a></li>
       <li><span class="separator"><img src="./images/OTM_transparent_15x080pix.png" /><img src="./images/OTM_transparent_15x080pix.png" /></span></li>
       <li><a href="http://www.opentelemac.org/index.php/community"><span class="image-title">COMMUNITY</span> </a></li>
       <li><a href="http://www.opentelemac.org/index.php/user-conference"><span class="image-title">CONFERENCE</span> </a></li>
       <li><a href="http://www.opentelemac.org/index.php/download"><span class="image-title">DOWNLOAD</span> </a></li>
          <li><a href="http://docs.opentelemac.org/" style="color:#333;background:#ffd1a3;padding:10px;"><span class="image-title">DOXY DOCS</span> </a></li>
       <li><a href="http://www.opentelemac.org/index.php/kunena"><span class="image-title">FORUM</span> </a></li>
          <li><a href="http://wiki.opentelemac.org/doku.php"><span class="image-title">WIKI</span> </a></li>
            </ul>
            </div>
            </div>

      <!-- Generated by Doxygen 1.7.0 -->
      <script type="text/javascript">
      function hasClass(ele,cls) {
        return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
      }
      function addClass(ele,cls) {
        if (!this.hasClass(ele,cls)) ele.className += " "+cls;
      }
      function removeClass(ele,cls) {
        if (hasClass(ele,cls)) {
          var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
          ele.className=ele.className.replace(reg,' ');
        }
      }
      function toggleVisibility(linkObj) {
       var base = linkObj.getAttribute('id');
       var summary = document.getElementById(base + '-summary');
       var content = document.getElementById(base + '-content');
       var trigger = document.getElementById(base + '-trigger');
       if ( hasClass(linkObj,'closed') ) {
         summary.style.display = 'none';
         content.style.display = 'block';
         trigger.src = 'open.png';
         removeClass(linkObj,'closed');
         addClass(linkObj,'opened');
       } else if ( hasClass(linkObj,'opened') ) {
         summary.style.display = 'block';
         content.style.display = 'none';
         trigger.src = 'closed.png';
         removeClass(linkObj,'opened');
         addClass(linkObj,'closed');
       }
       return false;
      }
      </script>
      <br>""", """<div  id="main" >
         <div  class="header" >
         <div  class="summary" >""", """<br>
      </div></div>
               <h2 class="unseen">Generated on Fri Aug 31 2013 18:12:58 by S.E.Bourban (HRW) using <A href="http://www.doxygen.org/index.html"><img class="footer" width=70px src="doxygen.png" alt="doxygen"/></A> 1.7.0</h2>
               <div  id="footer-outer" ><div id="footer-inner"><div id="bottom"><div class="box box1"><div class="moduletable">
               <script type="text/javascript">
              jQuery.noConflict();
        jQuery(document).ready(function($)
         {
          $('#ahgalleryOTconsortium ul.hover_block0 li.item').hover(function(){
           $(this).find('img.overlay').animate({top:'60px'},{queue:false,duration:500});
          }, function(){
           $(this).find('img.overlay').animate({top:'5px'},{queue:false,duration:500});
          });
        });
        </script>
               <div id="ahgalleryOTconsortium">
                  <ul class="hover_block0 bottom_block">
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://www.arteliagroup.com/" target="_blank"><img class="overlay" src="./images/Sogreah-Artelia.jpg" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">Artelia</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://www.baw.de/de/index.php.html" target="_blank"><img class="overlay" src="./images/logo_baw.png" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">BundesAnstalt fur Wasserbau</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://www.cetmef.equipement.gouv.fr/" target="_blank"><img class="overlay" src="./images/logo_cetmef_v2.png" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">CETMEF</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://www.stfc.ac.uk/About%20STFC/45.aspx" target="_blank"><img class="overlay" src="./images/logo_Daresbury_v3.gif" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">Daresbury Laboratory</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://research.edf.com/research-and-innovation-44204.html&amp;tab=44205" target="_blank"><img class="overlay" src="./images/logo_edfR&D.jpg" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">EDF R&D</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                     <li class="item"><a class="teaser" style="background-color:transparent !important;  font-weight: normal; text-decoration: none;" href="http://www.hrwallingford.com" target="_blank"><img class="overlay" src="./images/logo_HRW.png" alt="" />
                        <span style="color:grey; font-size: 14px; font-weight: bold; line-height: 18px; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em; display: block; text-align: center;">HR Wallingford</span>
                        <span style="color:white; display: block; font-size: 12px; font-weight: normal; font-family: arial; margin-bottom: 0.5em; margin-top: 0.5em;"></span></a></li>
                  </ul></div>
        <div class="clr"></div>
       </div></div>
       </div></div>
               <div id="footer-sub"><div id="footer">
                  <ul class="menu">
                     <li class="item-187"><a href="http://www.opentelemac.org/index.php/forum-rules" >Forum rules</a></li>
                     <li class="item-111"><a href="http://www.opentelemac.org/index.php/licence" >Licence</a></li>
                     <li class="item-112"><a href="http://www.opentelemac.org/index.php/privacy" >Privacy</a></li>
                     <li class="item-112"><a href="http://www.opentelemac.org/index.php/terms-and-conditions" >Terms &amp; Conditions</a></li>
                  </ul>
               </div>
       </div></div>
      </body></html>""", '<dl class="user"><dt><h3><b>',
        '</b></h3></dt><dd><br/>'
    ]

    text = r'(?P<before>[\s\S]*?)(?P<text>%s)(?P<after>[\s\S]*)'
    if path.exists(doxydocs):
        dirpath, _, filenames = walk(doxydocs).next()
        for fle in filenames:
            head, tail = path.splitext(fle)
            if tail == '.html':
                print '    +> ', fle
                lines = ''.join(getFileContent(path.join(dirpath, fle)))
                proc = True
                while proc:
                    proc = False
                    for itext, otext in zip(iTextList, oTextList):
                        proc0 = re.match(re.compile(text % (itext[0]), re.I),
                                         lines)
                        if proc0:
                            a = proc0.group('before')
                            proc1 = re.match(
                                re.compile(text % (itext[1]), re.I),
                                proc0.group('after'))
                            if proc1:
                                proc = True
                                b = proc1.group('after')
                                lines = a + otext + b
                                #print 'replacing: ',proc0.group('text')+proc1.group('before')
                putFileContent(path.join(dirpath, fle), [lines])

    return
コード例 #18
0
 def getFileContent(self, fileName):
     if not path.exists(fileName):
         print '... could not find your CSV file: ', fileName
         sys.exit(1)
     self.sortie = getFileContent(fileName)
コード例 #19
0
ファイル: parserKenue.py プロジェクト: ogoe/OpenTelemac
    def parseContent(self, fileName):
        # TODO: Read the whole header

        # ~~ Get all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        core = getFileContent(fileName)

        # ~~ Parse head ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        icore = 0
        self.atrbut = {}
        self.natrbut = 0
        self.oatrbut = []
        while re.match(ken_header, core[icore].strip()):
            # ~~> instruction FileType
            proc = re.match(asc_FileType, core[icore].strip())
            if proc: self.fileType = proc.group('type').lower()
            # ~~> instruction AttributeName
            proc = re.match(asc_AttributeName, core[icore].strip())
            if proc:
                self.natrbut += 1
                if self.natrbut == int(proc.group('number')):
                    self.oatrbut.append(proc.group('after').strip())
                    self.atrbut.update({self.oatrbut[-1]: []})
                else:
                    print '... Could not read the order of your Attributes:', core[
                        icore]
                    sys.exit(1)
            # ... more instruction coming ...
            icore += 1
        self.head = core[0:icore]
        # /!\ icore starts the body

        # ~~ Parse body ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # This is also fairly fast, so you might not need a progress bar
        self.poly = []
        self.vals = []
        self.type = []
        self.npoin = 0
        while icore < len(core):
            if core[icore].strip() == '':
                icore += 1
                continue
            # ~~> polygon head
            proc = re.match(var_1int, core[icore].strip())
            if not proc:
                print '\nCould not parse the following polyline header: ' + core[
                    icore].strip()
                sys.exit(1)
            nrec = int(proc.group('number'))
            a = proc.group('after').strip().split()
            if len(a) != self.natrbut:
                if self.natrbut != 0:
                    print '... Could not find the correct number of attribute:', core[
                        icore].strip(), ', ', self.natrbut, ' expected'
                    sys.exit(1)
                else:
                    self.natrbut = len(a)
                    self.oatrbut = range(1, len(a) + 1)
                    self.atrbut = dict([(i + 1, [a[i]])
                                        for i in range(len(a))])
            else:
                for i in range(len(self.oatrbut)):
                    self.atrbut[self.oatrbut[i]].append(a[i])
            xyi = []
            val = []
            icore += 1
            for irec in range(nrec):
                nbres = core[icore + irec].strip().split()
                proc = re.match(var_1dbl, nbres[0])
                if not proc:
                    proc = re.match(var_1int, nbres[0])
                    if not proc:
                        print '\nCould not parse the following polyline record: ' + core[
                            icore + irec].strip()
                        sys.exit(1)
                nbres[0] = float(proc.group('number'))
                procd = re.match(var_1dbl, nbres[1])
                proci = re.match(var_1int, nbres[1])
                if procd: nbres[1] = float(procd.group('number'))
                elif proci: nbres[1] = float(procd.group('number'))
                xyi.append(nbres[:2])
                val.append(nbres[2:])
            if xyi != []:
                cls = 0
                if isClose(xyi[0], xyi[len(xyi) - 1], size=10):
                    xyi.pop(len(xyi) - 1)
                    val.pop(len(val) - 1)
                    cls = 1
                self.poly.append(np.asarray(xyi, dtype=np.float))
                self.vals.append(np.asarray(val, dtype=np.float))
                self.type.append(cls)
            self.npoin += len(xyi)
            icore += nrec

        self.npoly = len(self.poly)
コード例 #20
0
      if v == "voltotal": y0.append(y1)
      elif v == "volfluxes": y0.append(y2)
      elif v == "volerror": y0.append(y3)
      else:
         print '... do not know how to extract: ' + v + ' of support ' + s
         sys.exit()
   
   return x0,y0

# _____             ________________________________________________
# ____/ MAIN CALL  /_______________________________________________/
#

__author__="David H. Roscoe; Sebastien E. Bourban"
__date__ ="$2-Aug-2011 11:51:36$"

if __name__ == "__main__":

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   #sortieFile = "C:\\opentelemac\\validation\\telemac2d\\tel2d_v6p2\\011_bumpflu\\t2d_bumpflu_v1p0.cas_2011-08-29-08h29min55s.sortie"
   sortieFile = "C:\\opentelemac\\validation\\telemac2d\\tel2d_v6p2\\011_bumpflu\\t2d_bumpflu_v1p0.cas_2011-09-11-15h40min27s.sortie"
   sortie = { 'fileName': sortieFile, 'typePlot': "voltotal", 'outFormat': '.png' }

   # ~~ Extract data
   content = getFileContent(sortieFile)
   title = getNameOfStudy(content)
   i,x = getTimeProfile(content)
   y1,y2,y3 = getValueProfile(content)

   print 'my job is done'
コード例 #21
0
def scanDICO(dicoFile):
    keylist = []
    dicoLines = getFileContent(dicoFile)
    # ~~ buddle continuations (long strings) and remove comments and empty lines
    core = []
    i = -1
    while i < len(dicoLines) - 1:
        i = i + 1
        line = ''
        l = dicoLines[i].strip()
        #proc = re.match(key_comment,l)
        #if proc: l = proc.group('before').strip() + ' '
        if l.strip()[0:1] == '/': continue
        proc = re.match(emptyline, l)
        if proc: continue
        proc = re.match(key_none, l)
        if proc: continue
        proc = re.match(entryquote, l)
        line = proc.group('before')
        l = proc.group('after')
        while l != '':
            if l[0:1] == '"':
                proc = re.match(exitdquote, l + ' ')
                if proc:
                    line = line + "'" + proc.group('before').replace("'",
                                                                     '"') + "'"
                    proc = re.match(entryquote, proc.group('after').strip())
                    line = line + proc.group('before')
                    l = proc.group('after').strip()
                    print '>', l
                else:
                    i = i + 1
                    l = l.strip() + ' ' + dicoLines[i].strip()
            elif l[0:1] == "'":
                proc = re.match(exitsquote, l + ' ')
                if proc:
                    line = line + "'" + proc.group('before').replace("'",
                                                                     '"') + "'"
                    proc = re.match(entryquote, proc.group('after').strip())
                    line = line + proc.group('before')
                    l = proc.group('after').strip()
                else:
                    i = i + 1
                    l = l.strip() + ' ' + dicoLines[i].strip()
        core.append(line)
    dicoStream = (' '.join(core)).replace('  ', ' ').replace('""', '"')
    # ~~ clean values to keep only the keys
    while dicoStream != '':
        # ~~ non-key
        proc = re.match(key_none, dicoStream)
        if proc:
            dicoStream = proc.group('after')
            continue
        # ~~ key
        proc = re.match(key_equals, dicoStream)
        if not proc: break
        kw = proc.group('key').strip()
        if kw not in dicokeys:
            print 'unknown key ', kw, proc.group('after'), dicoStream
            sys.exit(1)
        dicoStream = proc.group('after')  # still hold the separator
        # ~~ val
        proc = re.match(val_equals, dicoStream)
        if not proc:
            print 'no value to keyword ', kw
            sys.exit(1)
        val = []
        while proc:
            if proc.group('val')[0] == "'":
                val.append(proc.group('val')[1:len(proc.group('val')) - 1])
            else:
                val.append(proc.group('val'))
            dicoStream = proc.group('after')  # still hold the separator
            proc = re.match(val_equals, dicoStream)
        keylist.append([kw, val])
    # ~~ sort out the groups, starting with 'NOM'
    dico = {
        'FR': {},
        'GB': {},
        'DICO': dicoFile
    }
    keywords = {}
    while keylist != []:
        if keylist[0][0] != 'NOM' and keylist[1][0] != 'NOM1':
            print 'could not read NOM or NOM1 from ', keylist[0][1]
            sys.exit(1)
        dico['FR'].update({
            keylist[0][1][0].replace('"', "'"):
            keylist[1][1][0].replace('"', "'")
        })
        dico['GB'].update({
            keylist[1][1][0].replace('"', "'"):
            keylist[0][1][0].replace('"', "'")
        })
        key = keylist[0][1][0].replace('"', "'")
        words = {}
        words = {'NOM': keylist[0][1]}
        keylist.pop(0)
        while keylist != []:
            if keylist[0][0] == 'NOM': break
            words.update({keylist[0][0]: keylist[0][1]})
            keylist.pop(0)
        keywords.update({key: words})

    return dico, keywords
コード例 #22
0
def translateCAS(cas, frgb):
    casLines = getFileContent(cas)

    core = []
    for i in range(len(casLines)):
        # ~~> scan through to remove all comments
        casLines[i] = casLines[i].replace('"""', "'''").replace('"', "'")
        proc = re.match(key_comment, casLines[i] + '/')
        head = proc.group('before').strip()
        core.append(head)
    casStream = ' '.join(core)

    frLines = []
    gbLines = []
    for i in range(len(casLines)):

        # ~~> split comments
        casLines[i] = casLines[i].replace('"""', "'''").replace('"', "'")
        proc = re.match(key_comment, casLines[i] + '/')
        head = proc.group('before').strip()
        tail = proc.group('after').rstrip('/').strip()  # /!\ is not translated
        # ~~ special keys starting with '&'
        p = re.match(key_none, head + ' ')
        if p:
            head = ''
            tail = casLines[i].strip()
        frline = head
        gbline = head

        if head != '' and casStream == '':
            raise Exception([{
                'name':
                'translateCAS',
                'msg':
                'could not translate this cas file after the line:\n' + head
            }])
        # ~~> this is a must for multiple keywords on one line
        while casStream != '':
            proc = re.match(key_equals, casStream)
            if not proc:
                raise Exception([{
                    'name':
                    'scanCAS',
                    'msg':
                    '... hmmm, did not see this one coming ...\n   around there :'
                    + casStream[:100]
                }])
            kw = proc.group('key').strip()
            if kw not in head: break  # move on to next line

            # ~~> translate the keyword
            head = head.replace(kw, '', 1)
            if kw.upper() in frgb['GB']:
                frline = frline.replace(kw, frgb['GB'][kw], 1)
            if kw.upper() in frgb['FR']:
                gbline = gbline.replace(kw, frgb['FR'][kw], 1)

            # ~~> look for less obvious keywords
            casStream = proc.group('after')  # still hold the separator
            proc = re.match(val_equals, casStream)
            if not proc:
                raise Exception([{
                    'name': 'translateCAS',
                    'msg': 'no value to keyword: ' + kw
                }])
            while proc:
                casStream = proc.group('after')  # still hold the separator
                proc = re.match(val_equals, casStream)

        # final append
        if frline != '': frline = ' ' + frline
        frLines.append(frline + tail)
        if gbline != '': gbline = ' ' + gbline
        gbLines.append(gbline + tail)

    # ~~ print FR and GB versions of the CAS file
    putFileContent(cas + '.fr', frLines)
    putFileContent(cas + '.gb', gbLines)

    return cas + '.fr', cas + '.gb'