6 Author : Valentin Kuznetsov <vkuznet@gmail.com> 7 Description: CMS-related utils 9 from __future__
import print_function
16 from FWCore.Skeletons.utils
import code_generator
18 def config(tmpl, pkg_help, tmpl_dir):
19 "Parse input arguments to mk-script" 20 kwds = {
'author':
'',
'tmpl': tmpl,
21 'args': {},
'debug':
False,
22 'tmpl_dir': tmpl_dir,
'working_dir':
''}
24 if len(sys.argv) >= 2:
25 if sys.argv[1]
in [
'-h',
'--help',
'-help']:
28 kwds[
'pname'] = sys.argv[1]
29 for idx
in xrange(2, len(sys.argv)):
32 kwds[
'author'] = sys.argv[idx+1]
34 if opt.find(
'example') != -1:
35 etags.append(
'@%s' % opt)
37 if opt
in [
'-h',
'--help',
'-help']:
43 elif len(sys.argv) == 1:
45 msg =
'Please enter %s name: ' % tmpl.lower()
46 kwds[
'pname'] = raw_input(msg)
50 kwds[
'tmpl_etags'] = etags
55 Inject arguments parsed upstream into mk-scripts. 56 The arguments are parsed by the different front-ends(binaries) 57 and passed here via the args object. 60 kwds = {
'author':
'',
'tmpl': tmpl,
61 'args': {},
'debug':
False,
'tmpl_dir': tmpl_dir}
63 kwds[
'pname'] = args.subpackage_name
64 if args.author: kwds[
'author'] = args.author
65 if args.debug: kwds[
'debug'] =
True 66 if args.example: etags.append(
'@%s' % args.example)
67 kwds[
'tmpl_etags'] = etags
71 "Standard CMS error message" 72 msg =
"\nPackages must be created in a 'subsystem'." 73 msg +=
"\nPlease set your CMSSW environment and go to $CMSSW_BASE/src" 74 msg +=
"\nCreate or choose directory from there and then " 75 msg +=
"\nrun the script from that directory" 80 Test CMS environment and requirements to run within CMSSW_BASE. 81 Return True if we fullfill requirements and False otherwise. 83 base = os.environ.get(
'CMSSW_BASE',
None)
87 ldir = cdir.replace(os.path.join(base,
'src'),
'')
88 dirs = ldir.split(
'/')
90 if ldir
and ldir[0] ==
'/' and len(dirs) == 2:
91 return 'subsystem', ldir
93 if ldir
and ldir[0] ==
'/' and len(dirs) == 3:
94 return 'package', ldir
102 if ldir
and ldir[0] ==
'/' and len(dirs) == 4:
103 return dirs[-1], ldir
107 "Run generator code based on provided set of arguments" 109 tmpl = kwds.get(
'tmpl')
110 stand_alone_group = [
'Record',
'Skeleton']
111 config.update({
'not_in_dir': stand_alone_group})
112 if tmpl
in stand_alone_group:
114 dirs = ldir.split(
'/')
115 config.update({
'pkgname': kwds.get(
'pname')})
116 config.update({
'subsystem':
'Subsystem'})
117 config.update({
'pkgname':
'Package'})
120 config.update({
'subsystem': dirs[1]})
121 config.update({
'pkgname': dirs[2]})
123 config.update({
'subsystem': dirs[1]})
124 config.update({
'pkgname': dirs[1]})
127 dirs = ldir.split(
'/')
128 if not dirs
or not whereami:
131 config.update({
'subsystem': dirs[1]})
132 config.update({
'pkgname': kwds.get(
'pname')})
133 if whereami
in [
'src',
'plugins']:
134 config.update({
'working_dir': whereami})
135 config.update({
'tmpl_files':
'.cc'})
136 config.update({
'pkgname': dirs[2]})
137 elif whereami ==
'test':
138 config.update({
'working_dir': whereami})
139 config.update({
'tmpl_files':
'.cc'})
140 config.update({
'pkgname': dirs[2]})
141 elif whereami ==
'subsystem':
142 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)