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="boost_python"/> 47 if '<' in payloadType
and '>' in payloadType:
49 return "%s_%spayload2xml" %(
sanitize(payloadType),prefix)
52 import pluginUtilities_payload2xml
as mod2XML
53 bv = mod2XML.BoostVersion()
61 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
62 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
72 shutil.rmtree(
'/'.
join( self._pl2xml_tmpDir.split(
'/')[:-1] ) )
77 libName =
'pluginUtilities_payload2xml.so' 79 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
81 libPath = os.path.join( devLibDir, libName )
82 releaseBase = os.environ[
"CMSSW_RELEASE_BASE"]
83 devCheckout = (releaseBase !=
'')
85 logging.debug(
'Looks like the current working environment is a read-only release')
86 if not os.path.exists( libPath )
and devCheckout:
88 libDir = os.path.join( releaseBase,
'lib', os.environ[
"SCRAM_ARCH"] )
89 libPath = os.path.join( libDir, libName )
90 if not os.path.exists( libPath ):
91 if "CMSSW_FULL_RELEASE_BASE" in os.environ:
92 libDir = os.path.join( os.environ[
"CMSSW_FULL_RELEASE_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
93 libPath = os.path.join( libDir, libName )
94 if not os.path.exists( libPath ):
96 raise Exception(
'No built-in library %s found with XML converters.' %libPath)
97 logging.debug(
"Importing built-in library %s" %libPath)
98 module = importlib.import_module( libName.replace(
'.so',
'') )
99 functors =
dir(module)
100 funcName = payloadType+
'2xml' 101 if funcName
in functors:
102 logging.info(
'XML converter for payload class %s found in the built-in library.' %payloadType)
103 return getattr( module, funcName)
106 raise Exception(
'No XML converter suitable for payload class %s has been found in the built-in library.')
108 libPath = os.path.join( devLibDir, libName )
109 if os.path.exists( libPath ):
110 logging.info(
'Found local library with XML converter for class %s' %payloadType )
111 module = importlib.import_module( libName.replace(
'.so',
'') )
112 return getattr( module, funcName)
113 logging.warning(
'No XML converter for payload class %s found in the built-in library.' %payloadType)
118 converter = self.
discover(payloadType)
119 if converter:
return converter
122 startTime = time.time()
125 pluginName =
'plugin%s' % libName
126 tmpLibName =
"Tmp_payload2xml" 127 tmpPluginName =
'plugin%s' %tmpLibName
129 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
130 tmpLibFile = os.path.join( libDir,tmpPluginName+
'.so' )
131 code = payload2xmlCodeTemplate %(pluginName,payloadType)
133 tmpSrcFileName =
'Local_2XML.cpp' 135 if ( os.path.exists( tmpDir ) ) :
136 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
139 logging.debug(
'Creating temporary package %s' %self.
_pl2xml_tmpDir)
140 os.makedirs( tmpDir+
'/plugins' )
142 buildFileName =
"%s/plugins/BuildFile.xml" % (tmpDir,)
143 with open(buildFileName,
'w')
as buildFile:
144 buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
147 tmpSrcFilePath =
"%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
148 with open(tmpSrcFilePath,
'w')
as codeFile:
152 cmd =
"source $CMS_PATH/cmsset_default.sh;" 153 cmd +=
"(cd %s ; scram b 2>&1 >build.log)" %tmpDir
154 pipe = subprocess.Popen( cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
155 out, err = pipe.communicate()
156 ret = pipe.returncode
158 buildTime = time.time()-startTime
159 logging.info(
"Building done in %s sec., return code from build: %s" %(buildTime,ret) )
162 logging.error(
"Local build for xml dump failed.")
165 libFile = os.path.join(libDir,pluginName +
'.so')
166 shutil.copyfile(tmpLibFile,libFile)
168 module = importlib.import_module( pluginName )
169 funcName = payloadType+
'2xml' 170 functor = getattr( module, funcName )
176 Payload = session.get_dbtype(self.conddb.Payload)
178 result = session.query(Payload.data, Payload.object_type).
filter(Payload.hash == payloadHash).
one()
179 data, plType = result
180 logging.info(
'Found payload of type %s' %plType)
182 convFuncName =
sanitize(plType)+
'2xml' 185 if xmlConverter
is not None:
187 resultXML = obj.write(
str(data) )
191 with open(destFile,
'w')
as outFile:
192 outFile.write(resultXML)
def __init__(self, condDBIn)
def localLibName(payloadType)
def payload2xml(self, session, payloadHash, destFile)
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
def prepPayload2xml(self, payloadType)
def discover(self, payloadType)
static std::string join(char **cmd)
def boost_version_for_this_release()