6 Author : Valentin Kuznetsov <vkuznet@gmail.com> 7 Description: CMS-related utils 9 from __future__
import print_function
12 from builtins
import range
17 from FWCore.Skeletons.utils
import code_generator
19 def config(tmpl, pkg_help, tmpl_dir):
20 "Parse input arguments to mk-script" 21 kwds = {
'author':
'',
'tmpl': tmpl,
22 'args': {},
'debug':
False,
23 'tmpl_dir': tmpl_dir,
'working_dir':
''}
25 if len(sys.argv) >= 2:
26 if sys.argv[1]
in [
'-h',
'--help',
'-help']:
29 kwds[
'pname'] = sys.argv[1]
30 for idx
in range(2, len(sys.argv)):
33 kwds[
'author'] = sys.argv[idx+1]
35 if opt.find(
'example') != -1:
36 etags.append(
'@%s' % opt)
38 if opt
in [
'-h',
'--help',
'-help']:
44 elif len(sys.argv) == 1:
46 msg =
'Please enter %s name: ' % tmpl.lower()
47 kwds[
'pname'] = raw_input(msg)
51 kwds[
'tmpl_etags'] = etags
56 Inject arguments parsed upstream into mk-scripts. 57 The arguments are parsed by the different front-ends(binaries) 58 and passed here via the args object. 61 kwds = {
'author':
'',
'tmpl': tmpl,
62 'args': {},
'debug':
False,
'tmpl_dir': tmpl_dir}
64 kwds[
'pname'] = args.subpackage_name
65 if args.author: kwds[
'author'] = args.author
66 if args.debug: kwds[
'debug'] =
True 67 if args.example: etags.append(
'@%s' % args.example)
68 kwds[
'tmpl_etags'] = etags
72 "Standard CMS error message" 73 msg =
"\nPackages must be created in a 'subsystem'." 74 msg +=
"\nPlease set your CMSSW environment and go to $CMSSW_BASE/src" 75 msg +=
"\nCreate or choose directory from there and then " 76 msg +=
"\nrun the script from that directory" 81 Test CMS environment and requirements to run within CMSSW_BASE. 82 Return True if we fullfill requirements and False otherwise. 84 base = os.environ.get(
'CMSSW_BASE',
None)
88 ldir = cdir.replace(os.path.join(base,
'src'),
'')
89 dirs = ldir.split(
'/')
91 if ldir
and ldir[0] ==
'/' and len(dirs) == 2:
92 return 'subsystem', ldir
94 if ldir
and ldir[0] ==
'/' and len(dirs) == 3:
95 return 'package', ldir
103 if ldir
and ldir[0] ==
'/' and len(dirs) == 4:
104 return dirs[-1], ldir
108 "Run generator code based on provided set of arguments" 110 tmpl = kwds.get(
'tmpl')
111 stand_alone_group = [
'Record',
'Skeleton']
112 config.update({
'not_in_dir': stand_alone_group})
113 if tmpl
in stand_alone_group:
115 dirs = ldir.split(
'/')
116 config.update({
'pkgname': kwds.get(
'pname')})
117 config.update({
'subsystem':
'Subsystem'})
118 config.update({
'pkgname':
'Package'})
121 config.update({
'subsystem': dirs[1]})
122 config.update({
'pkgname': dirs[2]})
124 config.update({
'subsystem': dirs[1]})
125 config.update({
'pkgname': dirs[1]})
128 dirs = ldir.split(
'/')
129 if not dirs
or not whereami:
132 config.update({
'subsystem': dirs[1]})
133 config.update({
'pkgname': kwds.get(
'pname')})
134 if whereami
in [
'src',
'plugins']:
135 config.update({
'working_dir': whereami})
136 config.update({
'tmpl_files':
'.cc'})
137 config.update({
'pkgname': dirs[2]})
138 elif whereami ==
'test':
139 config.update({
'working_dir': whereami})
140 config.update({
'tmpl_files':
'.cc'})
141 config.update({
'pkgname': dirs[2]})
142 elif whereami ==
'subsystem':
143 config.update({
'tmpl_files':
'all'})
def test_cms_environment(tmpl)
S & print(S &os, JobReport::InputFile const &f)
def config_with_parser(tmpl, args, tmpl_dir)
def config(tmpl, pkg_help, tmpl_dir)