File indexing completed on 2024-04-06 11:58:28
0001
0002
0003
0004
0005
0006
0007 from configparser import RawConfigParser
0008
0009
0010
0011
0012
0013 class CrabConfigParser(RawConfigParser):
0014
0015
0016 def __init__(self):
0017 RawConfigParser.__init__(self)
0018 self.optionxform = str
0019
0020
0021
0022
0023
0024 def writeCrabConfig(self,filename):
0025 sections = self.sections()
0026 fixedsections = ['General','JobType','Data','Site','User','Debug']
0027 outlines = []
0028
0029 outlines.append('from WMCore.Configuration import Configuration \n')
0030 outlines.append('config = Configuration()')
0031
0032 for fixedsection in fixedsections:
0033 if fixedsection in sections:
0034 outlines.extend(self.getSectionLines(fixedsection))
0035 sections.remove(fixedsection)
0036
0037 for section in sections:
0038 outlines.extend(self.getSectionLines(section))
0039
0040 with open(filename,'w') as outfile:
0041 for line in outlines:
0042 outfile.write(f"{line}\n")
0043
0044
0045
0046
0047
0048
0049
0050 def getSectionLines(self,section):
0051 sectionLines = []
0052 sectionLines.append('\nconfig.section_("%s")'%section)
0053 configItems = self.items(section)
0054 for configItem in configItems:
0055 if not isinstance(configItem[1], str):
0056 sectionLines.append('config.%s.%s = %s'%(section,configItem[0],configItem[1]))
0057 elif "True" in configItem[1] or "False" in configItem[1]:
0058 sectionLines.append('config.%s.%s = %s'%(section,configItem[0],configItem[1]))
0059 else:
0060 parsed = False
0061 if configItem[0]=="runRange" :
0062 sectionLines.append('config.%s.%s = \'%s\''%(section,configItem[0],configItem[1]))
0063 parsed = True
0064 if not parsed:
0065 try:
0066 sectionLines.append('config.%s.%s = %d'%(section,configItem[0],int(configItem[1])))
0067 parsed = True
0068 except:
0069 pass
0070 if not parsed:
0071 try:
0072 sectionLines.append('config.%s.%s = %.2f'%(section,configItem[0],float(configItem[1])))
0073 parsed = True
0074 except:
0075 pass
0076 if not parsed:
0077 if isinstance(configItem[1], list):
0078 sectionLines.append('config.%s.%s = %s'%(section,configItem[0],str(configItem[1])))
0079 parsed = True
0080 if not parsed:
0081 sectionLines.append('config.%s.%s = \'%s\''%(section,configItem[0],configItem[1]))
0082
0083 return sectionLines