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)
56 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
57 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
67 shutil.rmtree(
'/'.
join( self._pl2xml_tmpDir.split(
'/')[:-1] ) )
72 libName =
'pluginUtilities_payload2xml.so' 74 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
76 libPath = os.path.join( devLibDir, libName )
77 releaseBase = os.environ[
"CMSSW_RELEASE_BASE"]
78 devCheckout = (releaseBase !=
'')
80 logging.debug(
'Looks like the current working environment is a read-only release')
81 if not os.path.exists( libPath )
and devCheckout:
83 libDir = os.path.join( releaseBase,
'lib', os.environ[
"SCRAM_ARCH"] )
84 libPath = os.path.join( libDir, libName )
85 if not os.path.exists( libPath ):
86 if "CMSSW_FULL_RELEASE_BASE" in os.environ:
87 libDir = os.path.join( os.environ[
"CMSSW_FULL_RELEASE_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
88 libPath = os.path.join( libDir, libName )
89 if not os.path.exists( libPath ):
91 raise Exception(
'No built-in library %s found with XML converters.' %libPath)
92 logging.debug(
"Importing built-in library %s" %libPath)
93 module = importlib.import_module( libName.replace(
'.so',
'') )
94 functors =
dir(module)
95 funcName = payloadType+
'2xml' 96 if funcName
in functors:
97 logging.info(
'XML converter for payload class %s found in the built-in library.' %payloadType)
98 return getattr( module, funcName)
101 raise Exception(
'No XML converter suitable for payload class %s has been found in the built-in library.')
103 libPath = os.path.join( devLibDir, libName )
104 if os.path.exists( libPath ):
105 logging.info(
'Found local library with XML converter for class %s' %payloadType )
106 module = importlib.import_module( libName.replace(
'.so',
'') )
107 return getattr( module, funcName)
108 logging.warning(
'No XML converter for payload class %s found in the built-in library.' %payloadType)
113 converter = self.
discover(payloadType)
114 if converter:
return converter
117 startTime = time.time()
120 pluginName =
'plugin%s' % libName
121 tmpLibName =
"Tmp_payload2xml" 122 tmpPluginName =
'plugin%s' %tmpLibName
124 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
125 tmpLibFile = os.path.join( libDir,tmpPluginName+
'.so' )
126 code = payload2xmlCodeTemplate %(pluginName,payloadType)
128 tmpSrcFileName =
'Local_2XML.cpp' 130 if ( os.path.exists( tmpDir ) ) :
131 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
134 logging.debug(
'Creating temporary package %s' %self.
_pl2xml_tmpDir)
135 os.makedirs( tmpDir+
'/plugins' )
137 buildFileName =
"%s/plugins/BuildFile.xml" % (tmpDir,)
138 with open(buildFileName,
'w')
as buildFile:
139 buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
142 tmpSrcFilePath =
"%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
143 with open(tmpSrcFilePath,
'w')
as codeFile:
147 cmd =
"source $CMS_PATH/cmsset_default.sh;" 148 cmd +=
"(cd %s ; scram b 2>&1 >build.log)" %tmpDir
149 pipe = subprocess.Popen( cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
150 out, err = pipe.communicate()
151 ret = pipe.returncode
153 buildTime = time.time()-startTime
154 logging.info(
"Building done in %s sec., return code from build: %s" %(buildTime,ret) )
157 logging.error(
"Local build for xml dump failed.")
160 libFile = os.path.join(libDir,pluginName +
'.so')
161 shutil.copyfile(tmpLibFile,libFile)
163 module = importlib.import_module( pluginName )
164 funcName = payloadType+
'2xml' 165 functor = getattr( module, funcName )
171 Payload = session.get_dbtype(self.conddb.Payload)
173 result = session.query(Payload.data, Payload.object_type).
filter(Payload.hash == payloadHash).
one()
174 data, plType = result
175 logging.info(
'Found payload of type %s' %plType)
177 convFuncName =
sanitize(plType)+
'2xml' 180 if xmlConverter
is not None:
182 resultXML = obj.write(
str(data) )
186 with open(destFile,
'w')
as outFile:
187 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)