12 if os.path.join( os.environ[
'CMSSW_BASE'],
'src')
not in sys.path:
13 sys.path.append( os.path.join( os.environ[
'CMSSW_BASE'],
'src') )
17 payload2xmlCodeTemplate =
""" 19 #include "CondCore/Utilities/interface/Payload2XMLModule.h" 20 #include "CondCore/Utilities/src/CondFormats.h" 22 PAYLOAD_2XML_MODULE( %s ){ 23 PAYLOAD_2XML_CLASS( %s ); 28 buildFileTemplate =
""" 29 <flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable -Os"/> 30 <library file="%s" name="%s"> 31 <use name="CondCore/Utilities"/> 32 <use name="boost_python"/> 46 if '<' in payloadType
and '>' in payloadType:
48 return "%s_%spayload2xml" %(
sanitize(payloadType),prefix)
55 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
56 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
58 self.fakePkgName =
"fakeSubSys4pl/fakePkg4pl" 59 self._pl2xml_tmpDir = os.path.join( os.environ[
'CMSSW_BASE'],
'src', self.fakePkgName )
61 self.doCleanup =
False 66 shutil.rmtree(
'/'.
join( self._pl2xml_tmpDir.split(
'/')[:-1] ) )
71 libName =
'pluginUtilities_payload2xml.so' 73 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
75 libPath = os.path.join( devLibDir, libName )
76 releaseBase = os.environ[
"CMSSW_RELEASE_BASE"]
77 devCheckout = (releaseBase !=
'')
79 logging.debug(
'Looks like the current working environment is a read-only release')
80 if not os.path.exists( libPath )
and devCheckout:
82 libDir = os.path.join( releaseBase,
'lib', os.environ[
"SCRAM_ARCH"] )
83 libPath = os.path.join( libDir, libName )
84 if not os.path.exists( libPath ):
85 if "CMSSW_FULL_RELEASE_BASE" in os.environ:
86 libDir = os.path.join( os.environ[
"CMSSW_FULL_RELEASE_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
87 libPath = os.path.join( libDir, libName )
88 if not os.path.exists( libPath ):
90 raise Exception(
'No built-in library %s found with XML converters.' %libPath)
91 logging.debug(
"Importing built-in library %s" %libPath)
92 module = importlib.import_module( libName.replace(
'.so',
'') )
93 functors =
dir(module)
94 funcName = payloadType+
'2xml' 95 if funcName
in functors:
96 logging.info(
'XML converter for payload class %s found in the built-in library.' %payloadType)
97 return getattr( module, funcName)
100 raise Exception(
'No XML converter suitable for payload class %s has been found in the built-in library.')
102 libPath = os.path.join( devLibDir, libName )
103 if os.path.exists( libPath ):
104 logging.info(
'Found local library with XML converter for class %s' %payloadType )
105 module = importlib.import_module( libName.replace(
'.so',
'') )
106 return getattr( module, funcName)
107 logging.warning(
'No XML converter for payload class %s found in the built-in library.' %payloadType)
112 converter = self.
discover(payloadType)
113 if converter:
return converter
116 startTime = time.time()
119 pluginName =
'plugin%s' % libName
120 tmpLibName =
"Tmp_payload2xml" 121 tmpPluginName =
'plugin%s' %tmpLibName
123 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
124 tmpLibFile = os.path.join( libDir,tmpPluginName+
'.so' )
125 code = payload2xmlCodeTemplate %(pluginName,payloadType)
127 tmpSrcFileName =
'Local_2XML.cpp' 128 tmpDir = self._pl2xml_tmpDir
129 if ( os.path.exists( tmpDir ) ) :
130 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
133 logging.debug(
'Creating temporary package %s' %self._pl2xml_tmpDir)
134 os.makedirs( tmpDir+
'/plugins' )
136 buildFileName =
"%s/plugins/BuildFile.xml" % (tmpDir,)
137 with open(buildFileName,
'w')
as buildFile:
138 buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
141 tmpSrcFilePath =
"%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
142 with open(tmpSrcFilePath,
'w')
as codeFile:
146 cmd =
"source $CMS_PATH/cmsset_default.sh;" 147 cmd +=
"(cd %s ; scram b 2>&1 >build.log)" %tmpDir
148 pipe = subprocess.Popen( cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
149 out, err = pipe.communicate()
150 ret = pipe.returncode
152 buildTime = time.time()-startTime
153 logging.info(
"Building done in %s sec., return code from build: %s" %(buildTime,ret) )
156 logging.error(
"Local build for xml dump failed.")
159 libFile = os.path.join(libDir,pluginName +
'.so')
160 shutil.copyfile(tmpLibFile,libFile)
162 module = importlib.import_module( pluginName )
163 funcName = payloadType+
'2xml' 164 functor = getattr( module, funcName )
165 self.doCleanup =
True 170 Payload = session.get_dbtype(self.conddb.Payload)
172 result = session.query(Payload.data, Payload.object_type).
filter(Payload.hash == payloadHash).
one()
173 data, plType = result
174 logging.info(
'Found payload of type %s' %plType)
176 convFuncName =
sanitize(plType)+
'2xml' 179 if xmlConverter
is not None:
181 resultXML = obj.write(
str(data) )
185 with open(destFile,
'w')
as outFile:
186 outFile.write(resultXML)
def __init__(self, condDBIn)
def localLibName(payloadType)
def payload2xml(self, session, payloadHash, destFile)
def replace(string, replacements)
def prepPayload2xml(self, payloadType)
def discover(self, payloadType)
static std::string join(char **cmd)