Warning, /FWCore/Skeletons/scripts/mkedlpr 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 : mkedlpr
0006 Author : Valentin Kuznetsov <vkuznet@gmail.com>
0007 Description: mkedlpr 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 "mkedlpr help function"
0021 msg = '\nmkedlpr script generates CMS EDLooper code'
0022 msg += '\nUsage : mkedlpr MyLooper -author "FirstName LastName"'
0023 msg += '\nUsage : mkedlpr MyLooper RecName DataType1 DataType2 ...'
0024 msg += '\n -author "FirstName LastName"'
0025 msg += '\n'
0026 msg += '\n MyLooper = name of the looper'
0027 msg += '\n RecName = name of the record to which the looper adds data'
0028 msg += '\n DataType1 = data type created by the looper'
0029 msg += '\nOutput : '
0030 msg += """
0031 MyLooper/
0032 | plugins/
0033 | |-- BuildFile.xml
0034 | |-- MyLooper.cc
0035 | python/
0036 | test/
0037 | doc/
0038 """
0039 msg += '\nExample:'
0040 msg += '\n # create new EDLooper code'
0041 msg += '\n mkedlpr MyLooper'
0042 msg += '\n # create new EDLooper code with given author'
0043 msg += '\n mkedlpr MyLooper -author "First Last"'
0044 msg += '\n'
0045 return msg
0046
0047 def config(tmpl, pkg_help):
0048 "Parse input arguments to mk-script"
0049 kwds = {'author': '', 'tmpl': tmpl,
0050 'args': {}, 'debug': False}
0051 etags = []
0052 args = []
0053 if len(sys.argv) >= 2: # user give us arguments
0054 if sys.argv[1] in ['-h', '--help', '-help']:
0055 print(pkg_help)
0056 sys.exit(0)
0057 kwds['pname'] = sys.argv[1]
0058 for idx in range(2, len(sys.argv)):
0059 opt = sys.argv[idx]
0060 if opt == '-author':
0061 kwds['author'] = sys.argv[idx+1]
0062 elif opt.find('example') != -1:
0063 etags.append('@%s' % opt)
0064 continue
0065 elif opt in ['-h', '--help', '-help']:
0066 print(pkg_help)
0067 sys.exit(0)
0068 elif opt == '-debug':
0069 kwds['debug'] = True
0070 continue
0071 elif sys.argv[idx-1] != '-author':
0072 args.append(opt)
0073 elif len(sys.argv) == 1:
0074 # need to walk
0075 msg = 'Please enter %s name: ' % tmpl.lower()
0076 kwds['pname'] = input(msg)
0077 msg = 'Please enter record name: '
0078 args.append(input(msg))
0079 msg = 'Please enter data types (separate by space): '
0080 args += [t for t in input(msg).split()]
0081 else:
0082 print(pkg_help)
0083 sys.exit(0)
0084 if args:
0085 # first element is record name, others are data types
0086 record = args[0]
0087 datatypes = args[1:] if len(args) > 1 else ['MyData']
0088 kwds['args'] = {'__record__': record, '__datatypes__': datatypes}
0089 else:
0090 kwds['args'] = {'__record__': 'MyRecord', '__datatypes__': ['MyType']}
0091 kwds['tmpl_etags'] = etags
0092 return kwds
0093
0094 if __name__ == '__main__':
0095 generate(config('EDLooper', pkg_help()))