6 Author : Valentin Kuznetsov <vkuznet@gmail.com>
7 Description: Utilities module
19 TAG = re.compile(
r'[a-zA-Z0-9]')
22 "Parse word which contas double underscore tag"
25 for idx
in xrange(0, len(words)):
27 if pat
and len(pat) > 4
and pat[:2] ==
'__':
28 tag = pat[2:pat.rfind(
'__')]
29 if tag.find(
'__') != -1:
30 for item
in tag.split(
'__'):
32 output.add(
'__%s__' % item)
34 output.add(
'__%s__' % tag)
39 Test user environment, look-up if user has run cmsenv, otherwise
40 provide meaningful error message back to the user.
42 if not tdir
or not os.path.isdir(tdir):
43 print "Unable to access template dir: %s" % tdir
45 if not os.listdir(tdir):
46 print "No template files found in template dir %s" % tdir
49 msg =
"No template type is provided, "
50 msg +=
"see available templates via --templates option"
56 Auto-generate and execute function with given code and configuration
57 For details of compile/exec/eval see
58 http://lucumr.pocoo.org/2011/2/1/exec-in-python/
61 for key, val
in kwds.items():
62 if isinstance(val, basestring):
63 arg =
'%s="%s"' % (key, val)
64 elif isinstance(val, list):
65 arg =
'%s=%s' % (key, val)
67 msg =
'Unsupported data type "%s" <%s>' % (val, type(val))
71 func +=
'\nimport StringIO'
72 func +=
"\ndef func(%s):\n" %
','.
join(args)
76 "Capture snippet printous"
77 old_stdout = sys.stdout
78 sys.stdout = StringIO.StringIO()
80 out = sys.stdout.getvalue()
81 sys.stdout = old_stdout
85 print "\n### generated code\n"
88 obj = compile(func,
'<string>',
'exec')
94 return namespace[
'capture']()
97 "Return user name and office location, based on UNIX finger"
100 pwdstr = pwd.getpwnam(os.getlogin())
101 author = pwdstr.pw_gecos
102 if author
and isinstance(author, basestring):
103 author = author.split(
',')[0]
108 Code generator function, parse user arguments, load and
109 return appropriate template generator module.
111 debug = kwds.get(
'debug',
None)
113 print "Configuration:"
116 klass = kwds.get(
'tmpl')
117 mname =
'FWCore.Skeletons.%s' % klass.lower()
118 module = __import__(mname, fromlist=[klass])
119 except ImportError
as err:
120 klass =
'AbstractPkg'
121 module = __import__(
'FWCore.Skeletons.pkg', fromlist=[klass])
123 print "%s, will use %s" % (str(err), klass)
124 obj = getattr(module, klass)(kwds)
128 "Print directory content, similar to tree UNIX command"
135 for root, dirs, files
in os.walk(idir):
136 dirs = root.split(
'/')
139 dsep =
'| '*(ndirs-1)
140 print '%s%s/' % (dsep, dirs[-1])
144 print '%s %s' % (fsep, fname)
146 if dtot == -1
or not dtot:
149 dmsg =
'%s directories,' % dtot
151 fmsg =
'%s file' % ftot
157 print "Total: %s %s" % (dmsg, fmsg)
159 print "No directories/files in %s" % idir
static std::string join(char **cmd)