Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function migration for FWCore_Skeletons #23827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions FWCore/Skeletons/python/cms.py
Expand Up @@ -6,6 +6,7 @@
Author : Valentin Kuznetsov <vkuznet@gmail.com>
Description: CMS-related utils
"""
from __future__ import print_function

# system modules
import os
Expand All @@ -22,7 +23,7 @@ def config(tmpl, pkg_help, tmpl_dir):
etags = []
if len(sys.argv) >= 2: # user give us arguments
if sys.argv[1] in ['-h', '--help', '-help']:
print pkg_help
print(pkg_help)
sys.exit(0)
kwds['pname'] = sys.argv[1]
for idx in xrange(2, len(sys.argv)):
Expand All @@ -34,7 +35,7 @@ def config(tmpl, pkg_help, tmpl_dir):
etags.append('@%s' % opt)
continue
if opt in ['-h', '--help', '-help']:
print pkg_help
print(pkg_help)
sys.exit(0)
if opt == '-debug':
kwds['debug'] = True
Expand All @@ -44,7 +45,7 @@ def config(tmpl, pkg_help, tmpl_dir):
msg = 'Please enter %s name: ' % tmpl.lower()
kwds['pname'] = raw_input(msg)
else:
print pkg_help
print(pkg_help)
sys.exit(0)
kwds['tmpl_etags'] = etags
return kwds
Expand Down Expand Up @@ -125,7 +126,7 @@ def generate(kwds):
whereami, ldir = test_cms_environment(tmpl)
dirs = ldir.split('/')
if not dirs or not whereami:
print cms_error()
print(cms_error())
sys.exit(1)
config.update({'subsystem': dirs[1]})
config.update({'pkgname': kwds.get('pname')})
Expand All @@ -140,7 +141,7 @@ def generate(kwds):
elif whereami == 'subsystem':
config.update({'tmpl_files': 'all'})
else:
print cms_error()
print(cms_error())
sys.exit(1)
obj = code_generator(config)
obj.generate()
3 changes: 2 additions & 1 deletion FWCore/Skeletons/python/main.py
Expand Up @@ -6,6 +6,7 @@
Author : Valentin Kuznetsov <vkuznet@gmail.com>
Description:
"""
from __future__ import print_function

# system modules
import os
Expand Down Expand Up @@ -105,7 +106,7 @@ def generator():
sys.exit(0)
elif opts.templates:
for name in os.listdir(opts.tdir):
print name
print(name)
sys.exit(0)
obj.generate()

Expand Down
17 changes: 9 additions & 8 deletions FWCore/Skeletons/python/pkg.py
Expand Up @@ -8,6 +8,7 @@
Description: AbstractGenerator class provides basic functionality
to generate CMSSW class from given template
"""
from __future__ import print_function

# system modules
import os
Expand Down Expand Up @@ -70,7 +71,7 @@ def tmpl_etags(self):
def print_etags(self):
"Print out template example tags"
for key in self.tmpl_etags():
print key
print(key)

def tmpl_tags(self):
"Scan template files and return template tags"
Expand All @@ -91,7 +92,7 @@ def tmpl_tags(self):
def print_tags(self):
"Print out template keys"
for key in self.tmpl_tags():
print key
print(key)

def parse_etags(self, line):
"""
Expand Down Expand Up @@ -152,7 +153,7 @@ def get_kwds(self):
args = self.config.get('args', None)
kwds.update(args)
if self.debug:
print "Template tags:"
print("Template tags:")
pprint.pprint(kwds)
return kwds

Expand All @@ -173,7 +174,7 @@ def generate(self):
if os.path.isdir(self.pname):
msg = "Can't create package '%s'\n" % self.pname
msg += "Directory %s is already exists" % self.pname
print msg
print(msg)
sys.exit(1)
os.makedirs(self.pname)
os.chdir(self.pname)
Expand All @@ -199,7 +200,7 @@ def generate(self):
kwds = self.get_kwds()
if not sources:
msg = 'Unable to find skeleton for extension "%s"' % ext
print msg
print(msg)
sys.exit(1)
bdir = os.environ.get('CMSSW_BASE', '')
dirs = os.getcwd().replace(bdir, '').split('/')
Expand Down Expand Up @@ -233,7 +234,7 @@ def generate(self):
continue
src = src.split('/')[-1]
if self.debug:
print "Read", src
print("Read", src)
items = src.split('/')
if items[-1] == '/':
items = items[:-1]
Expand All @@ -250,7 +251,7 @@ def generate(self):
name2gen = name2gen.replace(self.tmpl, self.pname)
name2gen = os.path.join(os.getcwd(), name2gen)
if self.debug:
print "Create", name2gen
print("Create", name2gen)
if ftype == 'dir':
if not os.path.isdir(name2gen):
os.makedirs(name2gen)
Expand All @@ -267,7 +268,7 @@ def generate(self):
msg = 'Generated %s file' % ', '.join(gen_files)
if len(gen_files) > 1:
msg += 's'
print msg
print(msg)
# return back where we started
os.chdir(cdir)
if msg.find('New package') != -1:
Expand Down
23 changes: 12 additions & 11 deletions FWCore/Skeletons/python/utils.py
Expand Up @@ -6,6 +6,7 @@
Author : Valentin Kuznetsov <vkuznet@gmail.com>
Description: Utilities module
"""
from __future__ import print_function

# system modules
import os
Expand Down Expand Up @@ -40,15 +41,15 @@ def test_env(tdir, tmpl):
provide meaningful error message back to the user.
"""
if not tdir or not os.path.isdir(tdir):
print "Unable to access template dir: %s" % tdir
print("Unable to access template dir: %s" % tdir)
sys.exit(1)
if not os.listdir(tdir):
print "No template files found in template dir %s" % tdir
print("No template files found in template dir %s" % tdir)
sys.exit(0)
if not tmpl:
msg = "No template type is provided, "
msg += "see available templates via --templates option"
print msg
print(msg)
sys.exit(1)

def functor(code, kwds, debug=0):
Expand Down Expand Up @@ -82,8 +83,8 @@ def capture():
return out\n
capture()\n"""
if debug:
print "\n### generated code\n"
print func
print("\n### generated code\n")
print(func)
# compile python code as exec statement
obj = compile(func, '<string>', 'exec')
# define execution namespace
Expand All @@ -110,7 +111,7 @@ def code_generator(kwds):
"""
debug = kwds.get('debug', None)
if debug:
print "Configuration:"
print("Configuration:")
pprint.pprint(kwds)
try:
klass = kwds.get('tmpl')
Expand All @@ -120,7 +121,7 @@ def code_generator(kwds):
klass = 'AbstractPkg'
module = __import__('FWCore.Skeletons.pkg', fromlist=[klass])
if debug:
print "%s, will use %s" % (str(err), klass)
print("%s, will use %s" % (str(err), klass))
obj = getattr(module, klass)(kwds)
return obj

Expand All @@ -137,11 +138,11 @@ def tree(idir):
ndirs = len(dirs)
if ndirs > 1:
dsep = '| '*(ndirs-1)
print '%s%s/' % (dsep, dirs[-1])
print('%s%s/' % (dsep, dirs[-1]))
dtot += 1
for fname in files:
fsep = dsep + '|--'
print '%s %s' % (fsep, fname)
print('%s %s' % (fsep, fname))
ftot += 1
if dtot == -1 or not dtot:
dmsg = ''
Expand All @@ -154,6 +155,6 @@ def tree(idir):
else:
fmsg = ''
if dmsg and fmsg:
print "Total: %s %s" % (dmsg, fmsg)
print("Total: %s %s" % (dmsg, fmsg))
else:
print "No directories/files in %s" % idir
print("No directories/files in %s" % idir)