Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#! /usr/bin/env python3

import sys
import os 
import argparse
from FWCore.ParameterSet.processFromFile import processFromFile

# make the behaviour of 'cmsRun file.py' and 'edmConfigDump file.py' more consistent
sys.path.append(os.getcwd())

parser = argparse.ArgumentParser(description="Expand python configuration")
parser.add_argument("filename",
                    help="Python configuration file")
parser.add_argument("--prune", action="store_true",
                    help="Prune the configuration before printing it")
parser.add_argument("--pruneVerbose", action="store_true",
                    help="With --prune, be verbose on what is pruned")
parser.add_argument("-o", "--output", type=str, default=None,
                    help="Save the configuration dump into this file. In this case any printouts from the configuration continue to be printed to stdout. Default is to print the configuration dump to stdout.")
parser.add_argument("configArgs",
                    nargs=argparse.REMAINDER, help="arguments that will be passed to Python configuration file")

options = parser.parse_args()
cmsProcess = processFromFile(options.filename, options.configArgs)

if options.prune:
    cmsProcess.prune(options.pruneVerbose)

if options.output is not None:
    with open(options.output, "w") as f:
        f.write(cmsProcess.dumpPython())
else:
    print(cmsProcess.dumpPython())