6 Author : Valentin Kuznetsov <vkuznet@gmail.com> 7 Description: CMS-related utils 15 from FWCore.Skeletons.utils
import code_generator
17 def config(tmpl, pkg_help, tmpl_dir):
18 "Parse input arguments to mk-script" 19 kwds = {
'author':
'',
'tmpl': tmpl,
20 'args': {},
'debug':
False,
21 'tmpl_dir': tmpl_dir,
'working_dir':
''}
23 if len(sys.argv) >= 2:
24 if sys.argv[1]
in [
'-h',
'--help',
'-help']:
27 kwds[
'pname'] = sys.argv[1]
28 for idx
in xrange(2, len(sys.argv)):
31 kwds[
'author'] = sys.argv[idx+1]
33 if opt.find(
'example') != -1:
34 etags.append(
'@%s' % opt)
36 if opt
in [
'-h',
'--help',
'-help']:
42 elif len(sys.argv) == 1:
44 msg =
'Please enter %s name: ' % tmpl.lower()
45 kwds[
'pname'] = raw_input(msg)
49 kwds[
'tmpl_etags'] = etags
54 Inject arguments parsed upstream into mk-scripts. 55 The arguments are parsed by the different front-ends(binaries) 56 and passed here via the args object. 59 kwds = {
'author':
'',
'tmpl': tmpl,
60 'args': {},
'debug':
False,
'tmpl_dir': tmpl_dir}
62 kwds[
'pname'] = args.subpackage_name
63 if args.author: kwds[
'author'] = args.author
64 if args.debug: kwds[
'debug'] =
True 65 if args.example: etags.append(
'@%s' % args.example)
66 kwds[
'tmpl_etags'] = etags
70 "Standard CMS error message" 71 msg =
"\nPackages must be created in a 'subsystem'." 72 msg +=
"\nPlease set your CMSSW environment and go to $CMSSW_BASE/src" 73 msg +=
"\nCreate or choose directory from there and then " 74 msg +=
"\nrun the script from that directory" 79 Test CMS environment and requirements to run within CMSSW_BASE. 80 Return True if we fullfill requirements and False otherwise. 82 base = os.environ.get(
'CMSSW_BASE',
None)
86 ldir = cdir.replace(os.path.join(base,
'src'),
'')
87 dirs = ldir.split(
'/')
89 if ldir
and ldir[0] ==
'/' and len(dirs) == 2:
90 return 'subsystem', ldir
92 if ldir
and ldir[0] ==
'/' and len(dirs) == 3:
93 return 'package', ldir
101 if ldir
and ldir[0] ==
'/' and len(dirs) == 4:
102 return dirs[-1], ldir
106 "Run generator code based on provided set of arguments" 108 tmpl = kwds.get(
'tmpl')
109 stand_alone_group = [
'Record',
'Skeleton']
110 config.update({
'not_in_dir': stand_alone_group})
111 if tmpl
in stand_alone_group:
113 dirs = ldir.split(
'/')
114 config.update({
'pkgname': kwds.get(
'pname')})
115 config.update({
'subsystem':
'Subsystem'})
116 config.update({
'pkgname':
'Package'})
119 config.update({
'subsystem': dirs[1]})
120 config.update({
'pkgname': dirs[2]})
122 config.update({
'subsystem': dirs[1]})
123 config.update({
'pkgname': dirs[1]})
126 dirs = ldir.split(
'/')
127 if not dirs
or not whereami:
130 config.update({
'subsystem': dirs[1]})
131 config.update({
'pkgname': kwds.get(
'pname')})
132 if whereami
in [
'src',
'plugins']:
133 config.update({
'working_dir': whereami})
134 config.update({
'tmpl_files':
'.cc'})
135 config.update({
'pkgname': dirs[2]})
136 elif whereami ==
'test':
137 config.update({
'working_dir': whereami})
138 config.update({
'tmpl_files':
'.cc'})
139 config.update({
'pkgname': dirs[2]})
140 elif whereami ==
'subsystem':
141 config.update({
'tmpl_files':
'all'})
def test_cms_environment(tmpl)
def config_with_parser(tmpl, args, tmpl_dir)
def config(tmpl, pkg_help, tmpl_dir)