Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:40

0001 import sys
0002 
0003 args = sys.argv
0004 
0005 if len(args) == 1:
0006     print("file names must be passed as arguments")
0007     exit(-1)
0008 if args[1] == '-h' or args[1] == '--help':
0009     print(
0010 """python edm_modernize_messagelogger.py [-h/--help] filename [...]
0011     
0012    Converts explicit constructions of cms.Service("MessageLogger") from old MessageLogger
0013    configration syntax to new the new syntax.
0014    The script expects a list of files to be modified in place.
0015     
0016    NOTE: The script is known to miss some corner-cases in the conversion so always check
0017    the results of the transformation.
0018 """
0019     )
0020     exit(0)
0021 
0022 for arg in args[1:]:
0023     execfile(arg)
0024     
0025     ml = process.MessageLogger.clone()
0026     if hasattr(process.MessageLogger, "statistics"):
0027         stat = process.MessageLogger.statistics
0028         for s in stat:
0029             dest = getattr(ml, s.value())
0030             dest.enableStatistics = cms.untracked.bool(True)
0031         del ml.statistics
0032     dest = process.MessageLogger.destinations
0033     files = cms.untracked.PSet()
0034     if 'cerr' not in dest:
0035         ml.cerr = cms.untracked.PSet(enable = cms.untracked.bool(False))
0036     for d in dest:
0037         if 'cout' == d:
0038             continue
0039         if 'cerr' == d:
0040             continue
0041         setattr(files, d, getattr(ml,d.value()))
0042         delattr(ml, d)
0043             
0044     if hasattr(ml,'categories'):
0045         del ml.categories
0046     del ml.destinations
0047     
0048     f = open(arg)
0049     newF = open(arg+"new", "w")
0050     
0051     processingML = False
0052     parenthesis = 0
0053     for l in f.readlines():
0054         if not processingML:
0055             if 'process.MessageLogger' == l[0:21]:
0056                 processingML = True
0057                 parenthesis = l.count('(')
0058                 parenthesis -= l.count(')')
0059                 if 0 == parenthesis:
0060                     processingML = False
0061                 continue
0062             newF.write(l)
0063         else:
0064             parenthesis += l.count('(')
0065             parenthesis -= l.count(')')
0066             if 0 == parenthesis:
0067                 processingML = False
0068                 newF.write('process.MessageLogger = '+ml.dumpPython())
0069         
0070