6 Author : Valentin Kuznetsov <vkuznet@gmail.com> 7 Description: Utilities module 9 from __future__
import print_function
12 from builtins
import range
21 TAG = re.compile(
r'[a-zA-Z0-9]')
24 "Parse word which contas double underscore tag" 27 for idx
in range(0, len(words)):
29 if pat
and len(pat) > 4
and pat[:2] ==
'__':
30 tag = pat[2:pat.rfind(
'__')]
31 if tag.find(
'__') != -1:
32 for item
in tag.split(
'__'):
34 output.add(
'__%s__' % item)
36 output.add(
'__%s__' % tag)
41 Test user environment, look-up if user has run cmsenv, otherwise 42 provide meaningful error message back to the user. 44 if not tdir
or not os.path.isdir(tdir):
45 print(
"Unable to access template dir: %s" % tdir)
47 if not os.listdir(tdir):
48 print(
"No template files found in template dir %s" % tdir)
51 msg =
"No template type is provided, " 52 msg +=
"see available templates via --templates option" 58 Auto-generate and execute function with given code and configuration 59 For details of compile/exec/eval see 60 http://lucumr.pocoo.org/2011/2/1/exec-in-python/ 63 for key, val
in kwds.items():
64 if isinstance(val, str):
65 arg =
'%s="%s"' % (key, val)
66 elif isinstance(val, list):
67 arg =
'%s=%s' % (key, val)
69 msg =
'Unsupported data type "%s" <%s>' % (val, type(val))
73 func +=
'\nimport StringIO' 74 func +=
"\ndef func(%s):\n" %
','.
join(args)
78 "Capture snippet printous" 79 old_stdout = sys.stdout 80 sys.stdout = StringIO.StringIO() 82 out = sys.stdout.getvalue() 83 sys.stdout = old_stdout 87 print(
"\n### generated code\n")
90 obj = compile(func,
'<string>',
'exec')
96 return namespace[
'capture']()
99 "Return user name and office location, based on UNIX finger" 102 pwdstr = pwd.getpwnam(os.getlogin())
103 author = pwdstr.pw_gecos
104 if author
and isinstance(author, str):
105 author = author.split(
',')[0]
110 Code generator function, parse user arguments, load and 111 return appropriate template generator module. 113 debug = kwds.get(
'debug',
None)
115 print(
"Configuration:")
118 klass = kwds.get(
'tmpl')
119 mname =
'FWCore.Skeletons.%s' % klass.lower()
120 module = __import__(mname, fromlist=[klass])
121 except ImportError
as err:
122 klass =
'AbstractPkg' 123 module = __import__(
'FWCore.Skeletons.pkg', fromlist=[klass])
125 print(
"%s, will use %s" % (
str(err), klass))
126 obj = getattr(module, klass)(kwds)
130 "Print directory content, similar to tree UNIX command" 137 for root, dirs, files
in os.walk(idir):
138 dirs = root.split(
'/')
141 dsep =
'| '*(ndirs-1)
142 print(
'%s%s/' % (dsep, dirs[-1]))
146 print(
'%s %s' % (fsep, fname))
148 if dtot == -1
or not dtot:
151 dmsg =
'%s directories,' % dtot
153 fmsg =
'%s file' % ftot
159 print(
"Total: %s %s" % (dmsg, fmsg))
161 print(
"No directories/files in %s" % idir)
def user_info(ainput=None)
S & print(S &os, JobReport::InputFile const &f)
static std::string join(char **cmd)
def functor(code, kwds, debug=0)