Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /FWCore/ParameterSet/scripts/edmConfigSplit is written in an unsupported language. File is not indexed.

0001 #! /usr/bin/env python3
0002 
0003 import sys
0004 import os
0005 import argparse
0006 
0007 from FWCore.ParameterSet.processFromFile import processFromFile
0008 from FWCore.ParameterSet.Mixins import PrintOptions
0009 
0010 parser = argparse.ArgumentParser(
0011   description = '%(prog)s splits the given CMSSW configuration file into one file per top-level object, and outputs the configuration for the main process object.',
0012 )
0013 parser.add_argument('file', metavar = 'FILE')
0014 parser.add_argument("configArgs",
0015   nargs=argparse.REMAINDER, help="arguments that will be passed to Python configuration file")
0016 
0017 parser.add_argument('-o', '--output',
0018   metavar = 'OUT',
0019   type = argparse.FileType('w'),
0020   default = sys.stdout,
0021   help = 'write the process configuration to %(metavar)s instead of standard output')
0022 parser.add_argument('-d', '--output-directory',
0023   metavar = 'DIR',
0024   type = str,
0025   default = None,
0026   help = 'create the individual files and subdirectories under %(metavar)s instead of the current directory; if %(metavar)s does not exist it will be created first')
0027 parser.add_argument('-s', '--subdirectories',
0028   action = "store_true",
0029   default = False,
0030   help = 'create subdirectories for different modules categories')
0031 
0032 args = parser.parse_args()
0033 
0034 # make the behaviour of 'cmsRun file.py' and 'edmConfigSplit file.py' more consistent
0035 sys.path.append(os.getcwd())
0036 
0037 process = processFromFile(args.file, args.configArgs)
0038 
0039 options = PrintOptions()
0040 options.useSubdirectories = args.subdirectories
0041 options.targetDirectory = args.output_directory
0042 
0043 files = process.splitPython(options)
0044 for fn, c in files.items():
0045   if fn == '-':
0046     continue
0047   d = os.path.dirname(fn)
0048   if d and not os.path.isdir(d):
0049     os.makedirs(d)
0050   with open(fn, 'w') as f:
0051     f.write(c)
0052 
0053 args.output.write(files['-'])
0054 args.output.close()