Warning, /FWCore/Skeletons/scripts/mkesprod is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python3
0002 #-*- coding: utf-8 -*-
0003 #pylint: disable-msg=
0004 """
0005 File : mkesprod
0006 Author : Valentin Kuznetsov <vkuznet@gmail.com>
0007 Description: mkesprod code
0008 """
0009
0010 # system modules
0011 import sys
0012
0013 if sys.version_info < (2, 6):
0014 raise Exception("This script requires python 2.6 or greater")
0015
0016 # package modules
0017 from FWCore.Skeletons.cms import generate
0018
0019 def pkg_help():
0020 "mkesprod help function"
0021 msg = '\nmkesprod script generates CMS ESProducer code'
0022 msg += '\nUsage : mkesprod MyProd RecName DataType1 DataType2 ...'
0023 msg += '\n -author "FirstName LastName"'
0024 msg += '\n'
0025 msg += '\n MyProd = name of the producer'
0026 msg += '\n RecName = name of the record to which the producer adds data'
0027 msg += '\n DataType1 = data type created by the producer'
0028 msg += '\nOutput : '
0029 msg += """
0030 MyProd/
0031 | plugins/
0032 | |-- BuildFile.xml
0033 | |-- MyProd.cc
0034 | python/
0035 | test/
0036 | doc/
0037 """
0038 msg += '\nExample:'
0039 msg += '\n # create new ESProducer code'
0040 msg += '\n mkesprod MyProd'
0041 msg += '\n # create new ESProducer code with given author'
0042 msg += '\n mkesprod MyProd -author "First Last"'
0043 msg += '\n # create new ESProducer code with given RecName'
0044 msg += '\n mkesprod MyProd MyRec'
0045 msg += '\n # create new ESProducer code with given RecName/DataType'
0046 msg += '\n mkesprod MyProd MyRec MyType'
0047 msg += '\n'
0048 return msg
0049
0050 def config(tmpl, pkg_help):
0051 "Parse input arguments to mk-script"
0052 kwds = {'author': '', 'tmpl': tmpl,
0053 'args': {}, 'debug': False}
0054 etags = []
0055 args = []
0056 if len(sys.argv) >= 2: # user give us arguments
0057 if sys.argv[1] in ['-h', '--help', '-help']:
0058 print(pkg_help)
0059 sys.exit(0)
0060 kwds['pname'] = sys.argv[1]
0061 for idx in range(2, len(sys.argv)):
0062 opt = sys.argv[idx]
0063 if opt == '-author':
0064 kwds['author'] = sys.argv[idx+1]
0065 elif opt.find('example') != -1:
0066 etags.append('@%s' % opt)
0067 continue
0068 elif opt in ['-h', '--help', '-help']:
0069 print(pkg_help)
0070 sys.exit(0)
0071 elif opt == '-debug':
0072 kwds['debug'] = True
0073 continue
0074 elif sys.argv[idx-1] != '-author':
0075 args.append(opt)
0076 elif len(sys.argv) == 1:
0077 # need to walk
0078 msg = 'Please enter %s name: ' % tmpl.lower()
0079 kwds['pname'] = input(msg)
0080 msg = 'Please enter record name: '
0081 args.append(input(msg))
0082 msg = 'Please enter data types (separate by space): '
0083 args += [t for t in input(msg).split()]
0084 else:
0085 print(pkg_help)
0086 sys.exit(0)
0087 if args:
0088 # first element is record name, others are data types
0089 record = args[0]
0090 datatypes = args[1:] if len(args) > 1 else ['MyData']
0091 kwds['args'] = {'__record__': record, '__datatypes__': datatypes}
0092 else:
0093 kwds['args'] = {'__record__': 'MyRecord', '__datatypes__': ['MyType']}
0094 kwds['tmpl_etags'] = etags
0095 return kwds
0096
0097 if __name__ == '__main__':
0098 generate(config('ESProducer', pkg_help()))