1 from __future__
import print_function
13 if os.path.join( os.environ[
'CMSSW_BASE'],
'src')
not in sys.path:
14 sys.path.append( os.path.join( os.environ[
'CMSSW_BASE'],
'src') )
18 payload2xmlCodeTemplate =
"""
20 #include "CondCore/Utilities/interface/Payload2XMLModule.h"
21 #include "CondCore/Utilities/src/CondFormats.h"
23 PAYLOAD_2XML_MODULE( %s ){
24 PAYLOAD_2XML_CLASS( %s );
29 buildFileTemplate =
"""
30 <flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable -Os"/>
31 <library file="%s" name="%s">
32 <use name="CondCore/Utilities"/>
33 <use name="py3-pybind11"/>
48 if '<' in payloadType
and '>' in payloadType:
51 if '::' in payloadType:
52 ptype = payloadType.replace(
'::',
'_')
53 return "%s_%spayload2xml" %(
sanitize(ptype),prefix)
60 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
61 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
76 libName =
'pluginUtilities_payload2xml.so'
78 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
80 libPath = os.path.join( devLibDir, libName )
81 releaseBase = os.environ[
"CMSSW_RELEASE_BASE"]
82 devCheckout = (releaseBase !=
'')
84 logging.debug(
'Looks like the current working environment is a read-only release')
85 if not os.path.exists( libPath )
and devCheckout:
87 libDir = os.path.join( releaseBase,
'lib', os.environ[
"SCRAM_ARCH"] )
88 libPath = os.path.join( libDir, libName )
89 if not os.path.exists( libPath ):
90 if "CMSSW_FULL_RELEASE_BASE" in os.environ:
91 libDir = os.path.join( os.environ[
"CMSSW_FULL_RELEASE_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
92 libPath = os.path.join( libDir, libName )
93 if not os.path.exists( libPath ):
95 raise Exception(
'No built-in library %s found with XML converters.' %libPath)
96 logging.debug(
"Importing built-in library %s" %libPath)
97 module = importlib.import_module( libName.replace(
'.so',
'') )
98 functors =
dir(module)
99 funcName = payloadType+
'2xml'
100 if funcName
in functors:
101 logging.info(
'XML converter for payload class %s found in the built-in library.' %payloadType)
102 return getattr( module, funcName)
105 raise Exception(
'No XML converter suitable for payload class %s has been found in the built-in library.')
107 libPath = os.path.join( devLibDir, libName )
108 if os.path.exists( libPath ):
109 logging.info(
'Found local library with XML converter for class %s' %payloadType )
110 module = importlib.import_module( libName.replace(
'.so',
'') )
111 return getattr( module, funcName)
112 logging.warning(
'No XML converter for payload class %s found in the built-in library.' %payloadType)
117 converter = self.
discover(payloadType)
118 if converter:
return converter
121 startTime = time.time()
124 pluginName =
'plugin%s' % libName
125 tmpLibName =
"Tmp_payload2xml"
126 tmpPluginName =
'plugin%s' %tmpLibName
128 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
129 tmpLibFile = os.path.join( libDir,tmpPluginName+
'.so' )
130 code = payload2xmlCodeTemplate %(pluginName,payloadType)
132 tmpSrcFileName =
'Local_2XML.cpp'
134 if ( os.path.exists( tmpDir ) ) :
135 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
138 logging.debug(
'Creating temporary package %s' %self.
_pl2xml_tmpDir)
139 os.makedirs( tmpDir+
'/plugins' )
141 buildFileName =
"%s/plugins/BuildFile.xml" % (tmpDir,)
142 with open(buildFileName,
'w')
as buildFile:
143 buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
146 tmpSrcFilePath =
"%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
147 with open(tmpSrcFilePath,
'w')
as codeFile:
151 cmd =
"source $CMS_PATH/cmsset_default.sh;"
152 cmd +=
"(cd %s ; scram b 2>&1 >build.log)" %tmpDir
153 pipe = subprocess.Popen( cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
154 out, err = pipe.communicate()
155 ret = pipe.returncode
157 buildTime = time.time()-startTime
158 logging.info(
"Building done in %s sec., return code from build: %s" %(buildTime,ret) )
161 logging.error(
"Local build for xml dump failed.")
164 libFile = os.path.join(libDir,pluginName +
'.so')
165 shutil.copyfile(tmpLibFile,libFile)
167 module = importlib.import_module( pluginName )
168 funcName = payloadType+
'2xml'
169 functor = getattr( module, funcName )
175 Payload = session.get_dbtype(self.
conddb.Payload)
177 result = session.query(Payload.data, Payload.object_type).
filter(Payload.hash == payloadHash).
one()
178 data, plType = result
179 logging.info(
'Found payload of type %s' %plType)
181 convFuncName =
sanitize(plType)+
'2xml'
184 if xmlConverter
is not None:
186 resultXML = obj.write( data )
190 with open(destFile,
'w')
as outFile:
191 outFile.write(resultXML)