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,
'tmpl_dir': tmpl_dir}
22 if len(sys.argv) >= 2:
23 if sys.argv[1]
in [
'-h',
'--help',
'-help']:
26 kwds[
'pname'] = sys.argv[1]
27 for idx
in xrange(2, len(sys.argv)):
30 kwds[
'author'] = sys.argv[idx+1]
32 if opt.find(
'example') != -1:
33 etags.append(
'@%s' % opt)
35 if opt
in [
'-h',
'--help',
'-help']:
41 elif len(sys.argv) == 1:
43 msg =
'Please enter %s name: ' % tmpl.lower()
44 kwds[
'pname'] = raw_input(msg)
48 kwds[
'tmpl_etags'] = etags
53 Inject arguments parsed upstream into mk-scripts. 54 The arguments are parsed by the different front-ends(binaries) 55 and passed here via the args object. 58 kwds = {
'author':
'',
'tmpl': tmpl,
59 'args': {},
'debug':
False,
'tmpl_dir': tmpl_dir}
61 kwds[
'pname'] = args.subpackage_name
62 if args.author: kwds[
'author'] = args.author
63 if args.debug: kwds[
'debug'] =
True 64 if args.example: etags.append(
'@%s' % args.example)
65 kwds[
'tmpl_etags'] = etags
69 "Standard CMS error message" 70 msg =
"\nPackages must be created in a 'subsystem'." 71 msg +=
"\nPlease set your CMSSW environment and go to $CMSSW_BASE/src" 72 msg +=
"\nCreate or choose directory from there and then " 73 msg +=
"\nrun the script from that directory" 78 Test CMS environment and requirements to run within CMSSW_BASE. 79 Return True if we fullfill requirements and False otherwise. 81 base = os.environ.get(
'CMSSW_BASE',
None)
85 ldir = cdir.replace(os.path.join(base,
'src'),
'')
86 dirs = ldir.split(
'/')
88 if ldir
and ldir[0] ==
'/' and len(dirs) == 2:
89 return 'subsystem', ldir
91 if ldir
and ldir[0] ==
'/' and len(dirs) == 3:
92 return 'package', ldir
100 if ldir
and ldir[0] ==
'/' and len(dirs) == 4:
101 return dirs[-1], ldir
105 "Run generator code based on provided set of arguments" 107 tmpl = kwds.get(
'tmpl')
108 stand_alone_group = [
'Record',
'Skeleton']
109 config.update({
'not_in_dir': stand_alone_group})
110 if tmpl
in stand_alone_group:
112 dirs = ldir.split(
'/')
113 config.update({
'pkgname': kwds.get(
'pname')})
114 config.update({
'subsystem':
'Subsystem'})
115 config.update({
'pkgname':
'Package'})
118 config.update({
'subsystem': dirs[1]})
119 config.update({
'pkgname': dirs[2]})
121 config.update({
'subsystem': dirs[1]})
122 config.update({
'pkgname': dirs[1]})
125 dirs = ldir.split(
'/')
126 if not dirs
or not whereami:
129 config.update({
'subsystem': dirs[1]})
130 config.update({
'pkgname': kwds.get(
'pname')})
131 if whereami
in [
'src',
'plugins']:
132 config.update({
'tmpl_files':
'.cc'})
133 config.update({
'pkgname': dirs[2]})
134 elif whereami ==
'subsystem':
135 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)