6 Author : Valentin Kuznetsov <vkuznet@gmail.com>
9 from __future__
import print_function
15 from optparse
import OptionParser
18 from FWCore.Skeletons.utils
import code_generator, test_env, template_directory
20 if sys.version_info < (2, 6):
21 raise Exception(
"This script requires python 2.6 or greater")
24 "Skeleton option parser"
26 cname = os.environ.get(
'MKTMPL_CMD',
'main.py')
27 usage =
"Usage: %s [options]\n" % cname
28 self.
parser = OptionParser(usage=usage)
30 self.
parser.add_option(
"--debug", action=
"store_true",
31 default=
False, dest=
"debug", help=msg)
32 msg =
"specify template, e.g. EDProducer"
33 self.
parser.add_option(
"--tmpl", action=
"store", type=
"string",
34 default=
'', dest=
"tmpl", help=msg)
35 msg =
"specify package name, e.g. MyProducer"
36 self.
parser.add_option(
"--name", action=
"store", type=
"string",
37 default=
"TestPkg", dest=
"pname", help=msg)
38 msg =
"specify author name"
39 self.
parser.add_option(
"--author", action=
"store", type=
"string",
40 default=
"", dest=
"author", help=msg)
41 msg =
"specify file type to generate, "
42 msg +=
"e.g. --ftype=header, default is all files"
43 self.
parser.add_option(
"--ftype", action=
"store", type=
"string",
44 default=
"all", dest=
"ftype", help=msg)
45 msg =
"list examples tags which should be kept in "
46 msg +=
"generate code, e.g. "
47 msg +=
"--keep-etags='@example_trac,@example_hist'"
48 self.
parser.add_option(
"--keep-etags", action=
"store", type=
"string",
49 default=
None, dest=
"ketags", help=msg)
50 msg =
"list template tags"
51 self.
parser.add_option(
"--tags", action=
"store_true",
52 default=
False, dest=
"tags", help=msg)
53 msg =
"list template example tags"
54 self.
parser.add_option(
"--etags", action=
"store_true",
55 default=
False, dest=
"etags", help=msg)
56 msg =
"list supported templates"
57 self.
parser.add_option(
"--templates", action=
"store_true",
58 default=
False, dest=
"templates", help=msg)
60 "Returns parse list of options"
64 "Parse input arguments"
67 key, val = arg.split(
'=')
70 if val[0] ==
'[' and val[-1] ==
']':
71 val = eval(val, {
"__builtins__":
None }, {})
77 Code generator function, parse user arguments and load appropriate
78 template module. Once loaded, run its data method depending on
79 user requested input parameter, e.g. print_etags, print_tags or
80 generate template code.
83 opts, args = optmgr.get_opt()
84 test_env(os.path.join(opts.tdir, opts.tmpl), opts.tmpl)
85 config = {
'pname': opts.pname,
'tmpl': opts.tmpl,
'author': opts.author,
89 etags = opts.ketags.split(
',')
90 config.update({
'tmpl_etags': etags})
92 config.update({
'tmpl_etags': []})
106 if __name__ ==
'__main__':