CMS 3D CMS Logo

main.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
3 #pylint: disable-msg=
4 """
5 File : Skeleton.py
6 Author : Valentin Kuznetsov <vkuznet@gmail.com>
7 Description:
8 """
9 from __future__ import print_function
10 
11 # system modules
12 import os
13 import sys
14 import pprint
15 from optparse import OptionParser
16 
17 # package modules
18 from FWCore.Skeletons.utils import code_generator, test_env
19 
20 if sys.version_info < (2, 6):
21  raise Exception("This script requires python 2.6 or greater")
22 
23 def tmpl_dir():
24  "Retturn default location of template directory"
25  return '%s/templates' % '/'.join(__file__.split('/')[:-1])
26 
28  "Skeleton option parser"
29  def __init__(self):
30  cname = os.environ.get('MKTMPL_CMD', 'main.py')
31  usage = "Usage: %s [options]\n" % cname
32  self.parser = OptionParser(usage=usage)
33  msg = "debug output"
34  self.parser.add_option("--debug", action="store_true",
35  default=False, dest="debug", help=msg)
36  msg = "specify template, e.g. EDProducer"
37  self.parser.add_option("--tmpl", action="store", type="string",
38  default='', dest="tmpl", help=msg)
39  msg = "specify package name, e.g. MyProducer"
40  self.parser.add_option("--name", action="store", type="string",
41  default="TestPkg", dest="pname", help=msg)
42  msg = "specify author name"
43  self.parser.add_option("--author", action="store", type="string",
44  default="", dest="author", help=msg)
45  msg = "specify file type to generate, "
46  msg += "e.g. --ftype=header, default is all files"
47  self.parser.add_option("--ftype", action="store", type="string",
48  default="all", dest="ftype", help=msg)
49  msg = "list examples tags which should be kept in "
50  msg += "generate code, e.g. "
51  msg += "--keep-etags='@example_trac,@example_hist'"
52  self.parser.add_option("--keep-etags", action="store", type="string",
53  default=None, dest="ketags", help=msg)
54  msg = "specify template directory, "
55  self.parser.add_option("--tdir", action="store", type="string",
56  default=tmpl_dir(), dest="tdir", help=msg)
57  msg = "list template tags"
58  self.parser.add_option("--tags", action="store_true",
59  default=False, dest="tags", help=msg)
60  msg = "list template example tags"
61  self.parser.add_option("--etags", action="store_true",
62  default=False, dest="etags", help=msg)
63  msg = "list supported templates"
64  self.parser.add_option("--templates", action="store_true",
65  default=False, dest="templates", help=msg)
66  def get_opt(self):
67  "Returns parse list of options"
68  return self.parser.parse_args()
69 
70 def parse_args(args):
71  "Parse input arguments"
72  output = {}
73  for arg in args:
74  key, val = arg.split('=')
75  key = key.strip()
76  val = val.strip()
77  if val[0] == '[' and val[-1] == ']':
78  val = eval(val, { "__builtins__": None }, {})
79  output[key] = val
80  return output
81 
82 def generator():
83  """
84  Code generator function, parse user arguments and load appropriate
85  template module. Once loaded, run its data method depending on
86  user requested input parameter, e.g. print_etags, print_tags or
87  generate template code.
88  """
89  optmgr = SkeletonOptionParser()
90  opts, args = optmgr.get_opt()
91  test_env(os.path.join(opts.tdir, opts.tmpl), opts.tmpl)
92  config = {'pname': opts.pname, 'tmpl': opts.tmpl, 'author': opts.author,
93  'args': parse_args(args), 'debug': opts.debug,
94  'ftype': opts.ftype, 'tmpl_dir': opts.tdir}
95  if opts.ketags:
96  etags = opts.ketags.split(',')
97  config.update({'tmpl_etags': etags})
98  else:
99  config.update({'tmpl_etags': []})
100  obj = code_generator(config)
101  if opts.etags:
102  obj.print_etags()
103  sys.exit(0)
104  elif opts.tags:
105  obj.print_tags()
106  sys.exit(0)
107  elif opts.templates:
108  for name in os.listdir(opts.tdir):
109  print(name)
110  sys.exit(0)
111  obj.generate()
112 
113 if __name__ == '__main__':
114  generator()
def get_opt(self)
Definition: main.py:66
def generator()
Definition: main.py:82
def tmpl_dir()
Definition: main.py:23
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def __init__(self)
Definition: main.py:29
def parse_args(args)
Definition: main.py:70
def test_env(tdir, tmpl)
Definition: utils.py:38
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def code_generator(kwds)
Definition: utils.py:107