def prepareReplaceDict(line, comment, replaceDict): """take a line and a corresponding comment and prepare the replaceDict such that it can be found again in the python version """ allKeywords = [ 'module', 'int32', 'vint32', 'uint32', 'vuint32', 'double', 'vdouble', 'InputTag', 'VInputTag', 'PSet', 'VPSet', 'string', 'vstring', 'bool', 'vbool', 'path', 'sequence', 'schedule', 'endpath', 'es_source', 'es_module', 'block', 'FileInPath' ] unnamedKeywords = ['es_source', 'es_module'] words = line.lstrip().split() # at least <keyword> <label> = " if len(words) > 1: firstWord = words[0] if firstWord in allKeywords and len(words) > 2 and words[2] == '=': tokenInPython = words[1] + " = " replaceDict[tokenInPython] = comment elif firstWord == 'untracked' and len( words) > 3 and words[1] in allKeywords and words[3] == '=': tokenInPython = words[2] + " = cms.untracked" replaceDict[tokenInPython] = comment elif firstWord.startswith('include'): # handling of include statements pythonModule = cfgName2py.cfgName2py(line.split('"')[1]) pythonModule = pythonModule.replace("/", ".").replace( "python.", "").replace(".py", "") tokenInPython = "from " + pythonModule tokenInPython = tokenInPython.replace("/", ".").replace( "python.", "").replace(".py", "") replaceDict[tokenInPython] = comment # if a cfg tokenInPython = "process.load(\"" + pythonModule replaceDict[tokenInPython] = comment elif firstWord == 'source' and len(words) > 1 and words[1] == '=': replaceDict['source = '] = comment elif firstWord in unnamedKeywords and len( words) > 2 and words[1] == '=': tokenInPython = words[2] + ' = cms.ES' replaceDict[tokenInPython] = comment elif firstWord == 'replace' and len(words) > 2 and words[2] == '=': tokenInPython = words[1] + " = " replaceDict[tokenInPython] = comment elif firstWord == 'replace' and len(words) > 2 and words[2] == '=': tokenInPython = words[1] + " = " replaceDict[tokenInPython] = comment # if it's a cfg tokenInPython = 'process.' + tokenInPython replaceDict[tokenInPython] = comment elif firstWord == 'using' and len(words) == 2: tokenInPython = words[1] replaceDict[tokenInPython] = comment # if it's a significant line, we're not in a comment any more else: replaceDict["@beginning"] += "\n" + comment.value
def prepareReplaceDict(line, comment, replaceDict): """take a line and a corresponding comment and prepare the replaceDict such that it can be found again in the python version """ allKeywords = ['module','int32','vint32','uint32', 'vuint32','double','vdouble','InputTag', 'VInputTag', 'PSet', 'VPSet', 'string', 'vstring', 'bool', 'vbool', 'path', 'sequence', 'schedule', 'endpath', 'es_source', 'es_module', 'block', 'FileInPath'] unnamedKeywords = ['es_source', 'es_module'] words = line.lstrip().split() # at least <keyword> <label> = " if len(words) > 1: firstWord = words[0] if firstWord in allKeywords and len(words) > 2 and words[2] == '=': tokenInPython = words[1] + " = " replaceDict[tokenInPython] = comment elif firstWord == 'untracked' and len(words) > 3 and words[1] in allKeywords and words[3] == '=': tokenInPython = words[2] + " = cms.untracked" replaceDict[tokenInPython] = comment elif firstWord.startswith('include'): # handling of include statements pythonModule = cfgName2py.cfgName2py(line.split('"')[1]) pythonModule = pythonModule.replace("/",".").replace("python.","").replace(".py","") tokenInPython = "from "+pythonModule tokenInPython = tokenInPython.replace("/",".").replace("python.","").replace(".py","") replaceDict[tokenInPython] = comment # if a cfg tokenInPython = "process.load(\""+pythonModule replaceDict[tokenInPython] = comment elif firstWord == 'source' and len(words) > 1 and words[1] == '=': replaceDict['source = '] = comment elif firstWord in unnamedKeywords and len(words) > 2 and words[1] == '=': tokenInPython = words[2] + ' = cms.ES' replaceDict[tokenInPython] = comment elif firstWord == 'replace' and len(words) > 2 and words[2] == '=': tokenInPython= words[1] + " = " replaceDict[tokenInPython] = comment elif firstWord == 'replace' and len(words) > 2 and words[2] == '=': tokenInPython= words[1] + " = " replaceDict[tokenInPython] = comment # if it's a cfg tokenInPython = 'process.'+tokenInPython replaceDict[tokenInPython] = comment elif firstWord == 'using' and len(words) == 2: tokenInPython= words[1] replaceDict[tokenInPython] = comment # if it's a significant line, we're not in a comment any more else: replaceDict["@beginning"] +="\n"+comment.value
def loopfile(cfgFileName): cfgFile = file(cfgFileName) cfgString = cfgFile.read() pyFileName = cfgName2py.cfgName2py(cfgFileName) try: pyFile = file(pyFileName) pyString = pyFile.read() except IOError: print pyFileName, "does not exist" return comments = identifyComments(cfgString) print "Opening", pyFileName newPyString = modifyPythonVersion(pyString, comments) pyFile.close() pyOutFile = file(pyFileName, "w") pyOutFile.write(newPyString) print "Wrote", pyFileName pyOutFile.close()
def loopfile(cfgFileName): cfgFile = file(cfgFileName) cfgString = cfgFile.read() pyFileName = cfgName2py.cfgName2py(cfgFileName) try: pyFile = file(pyFileName) pyString = pyFile.read() except IOError: print pyFileName, "does not exist" return comments = identifyComments(cfgString) print "Opening", pyFileName newPyString = modifyPythonVersion(pyString, comments) pyFile.close() pyOutFile = file(pyFileName,"w") pyOutFile.write(newPyString) print "Wrote", pyFileName pyOutFile.close()
if nToks < 3: globList.append('data') if nToks < 4: globList.append('*cf[fi]') files = glob.glob('/'.join(globList)) else: # single file files.append(argv[1]) overwrite = True if argv[len(argv)-1] == 'no_overwrite': overwrite = False for fileName in files: if fileName.endswith('cfg'): newName = cfgName2py.cfgName2py(fileName) if os.path.exists(newName) and not overwrite: continue newPath = os.path.dirname(newName) if newPath != '' and not os.path.exists(newPath): os.makedirs(newPath) f = open(newName, 'w') try: f.write(cmsParse.dumpCfg(fileName)) except: print "ERROR in "+fileName f.close() os.remove(newName) else: f.close() else: