scripts: python3: Use print function

Used print function instead of print statement to make
the code work in python 3.

(From meta-yocto rev: d6eea5a794dd8802b773a9186479a863847e6e55)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2016-05-30 18:14:46 +03:00 committed by Richard Purdie
parent fc79776fff
commit ab75075e79
3 changed files with 91 additions and 92 deletions

View File

@ -1263,13 +1263,13 @@ def conditional_filename(filename):
return None
end = filename.find(CLOSE_TAG, opentag_start)
if end == -1:
print "No close tag found for open tag in filename %s" % filename
print("No close tag found for open tag in filename %s" % filename)
sys.exit(1)
# we have a {{ tag i.e. code
tag = filename[opentag_start + len(OPEN_TAG):end].strip()
if not tag.lstrip().startswith(IF_TAG):
print "Only 'if' tags are allowed in file or directory names, filename: %s" % filename
print("Only 'if' tags are allowed in file or directory names, filename: %s" % filename)
sys.exit(1)
return CodeLine(tag)
@ -1515,7 +1515,7 @@ def expand_targets(context, bsp_output_dir, expand_common=True):
arches = os.listdir(arch_path)
if arch not in arches or arch == "common":
print "Invalid karch, exiting\n"
print("Invalid karch, exiting\n")
sys.exit(1)
target = os.path.join(arch_path, arch)
@ -1541,7 +1541,7 @@ def yocto_common_create(machine, target, scripts_path, layer_output_dir, codedum
expand_common - boolean, use the contents of (for bsp layers) arch/common
"""
if os.path.exists(layer_output_dir):
print "\nlayer output dir already exists, exiting. (%s)" % layer_output_dir
print("\nlayer output dir already exists, exiting. (%s)" % layer_output_dir)
sys.exit(1)
properties = None
@ -1550,7 +1550,7 @@ def yocto_common_create(machine, target, scripts_path, layer_output_dir, codedum
try:
infile = open(properties_file, "r")
except IOError:
print "Couldn't open properties file %s for reading, exiting" % properties_file
print("Couldn't open properties file %s for reading, exiting" % properties_file)
sys.exit(1)
properties = json.load(infile)
@ -1597,8 +1597,8 @@ def yocto_layer_create(layer_name, scripts_path, layer_output_dir, codedump, pro
"""
yocto_common_create(layer_name, "layer", scripts_path, layer_output_dir, codedump, properties_file, properties, False)
print "\nNew layer created in %s.\n" % (layer_output_dir)
print "Don't forget to add it to your BBLAYERS (for details see %s/README)." % (layer_output_dir)
print("\nNew layer created in %s.\n" % layer_output_dir)
print("Don't forget to add it to your BBLAYERS (for details see %s/README)." % layer_output_dir)
def yocto_bsp_create(machine, arch, scripts_path, bsp_output_dir, codedump, properties_file, properties=None):
@ -1616,7 +1616,7 @@ def yocto_bsp_create(machine, arch, scripts_path, bsp_output_dir, codedump, prop
"""
yocto_common_create(machine, arch, scripts_path, bsp_output_dir, codedump, properties_file, properties)
print "\nNew %s BSP created in %s" % (arch, bsp_output_dir)
print("\nNew %s BSP created in %s" % arch, bsp_output_dir)
def print_dict(items, indent = 0):
@ -1624,13 +1624,13 @@ def print_dict(items, indent = 0):
Print the values in a possibly nested dictionary.
"""
for key, val in items.iteritems():
print " "*indent + "\"%s\" :" % key,
print(" "*indent + "\"%s\" :" % key)
if type(val) == dict:
print "{"
print("{")
print_dict(val, indent + 1)
print " "*indent + "}"
print(" "*indent + "}")
else:
print "%s" % val
print("%s" % val)
def get_properties(input_lines):
@ -1681,7 +1681,7 @@ def yocto_layer_list_properties(arch, scripts_path, properties_file, expand_comm
try:
of = open(properties_file, "w")
except IOError:
print "Couldn't open properties file %s for writing, exiting" % properties_file
print("Couldn't open properties file %s for writing, exiting" % properties_file)
sys.exit(1)
json.dump(properties, of, indent=1)
@ -1755,10 +1755,10 @@ def print_values(type, values_list):
"""
if type == "choicelist":
for value in values_list:
print "[\"%s\", \"%s\"]" % (value[0], value[1])
print("[\"%s\", \"%s\"]" % (value[0], value[1]))
elif type == "boolean":
for value in values_list:
print "[\"%s\", \"%s\"]" % (value[0], value[1])
print("[\"%s\", \"%s\"]" % (value[0], value[1]))
def yocto_layer_list_property_values(arch, property, scripts_path, properties_file, expand_common=True):
@ -1789,7 +1789,7 @@ def yocto_layer_list_property_values(arch, property, scripts_path, properties_fi
input_line = find_input_line(property, input_lines)
if not input_line:
print "Couldn't find values for property %s" % property
print("Couldn't find values for property %s" % property)
return
values_list = []
@ -1818,7 +1818,7 @@ def yocto_layer_list_property_values(arch, property, scripts_path, properties_fi
try:
of = open(properties_file, "w")
except IOError:
print "Couldn't open properties file %s for writing, exiting" % properties_file
print("Couldn't open properties file %s for writing, exiting" % properties_file)
sys.exit(1)
json.dump(values_list, of)
@ -1839,11 +1839,11 @@ def yocto_bsp_list(args, scripts_path, properties_file):
lib_path = scripts_path + '/lib'
bsp_path = lib_path + '/bsp'
arch_path = bsp_path + '/substrate/target/arch'
print "Architectures available:"
print("Architectures available:")
for arch in os.listdir(arch_path):
if arch == "common" or arch == "layer":
continue
print " %s" % arch
print(" %s" % arch)
return True
else:
arch = args[0]

View File

@ -42,7 +42,7 @@ def find_bblayers():
try:
builddir = os.environ["BUILDDIR"]
except KeyError:
print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
bblayers_conf = os.path.join(builddir, "conf/bblayers.conf")
@ -53,7 +53,7 @@ def find_bblayers():
stdout=subprocess.PIPE).stdout.read()
if not bitbake_env_lines:
print "Couldn't get '%s' output, exiting." % bitbake_env_cmd
print("Couldn't get '%s' output, exiting." % bitbake_env_cmd)
sys.exit(1)
for line in bitbake_env_lines.split('\n'):
@ -62,8 +62,7 @@ def find_bblayers():
break
if not bblayers:
print "Couldn't find BBLAYERS in %s output, exiting." % \
bitbake_env_cmd
print("Couldn't find BBLAYERS in %s output, exiting." % bitbake_env_cmd)
sys.exit(1)
raw_layers = bblayers.split()
@ -110,8 +109,8 @@ def find_bsp_layer(machine):
if layer.endswith(machine):
return layer
print "Unable to find the BSP layer for machine %s." % machine
print "Please make sure it is listed in bblayers.conf"
print("Unable to find the BSP layer for machine %s." % machine)
print("Please make sure it is listed in bblayers.conf")
sys.exit(1)
@ -190,8 +189,8 @@ def yocto_kernel_config_list(scripts_path, machine):
"""
config_items = read_config_items(scripts_path, machine)
print "The current set of machine-specific kernel config items for %s is:" % machine
print gen_choices_str(config_items)
print("The current set of machine-specific kernel config items for %s is:" % machine)
print(gen_choices_str(config_items))
def yocto_kernel_config_rm(scripts_path, machine):
@ -202,7 +201,7 @@ def yocto_kernel_config_rm(scripts_path, machine):
"""
config_items = read_config_items(scripts_path, machine)
print "Specify the kernel config items to remove:"
print("Specify the kernel config items to remove:")
input = raw_input(gen_choices_str(config_items))
rm_choices = input.split()
rm_choices.sort()
@ -213,18 +212,18 @@ def yocto_kernel_config_rm(scripts_path, machine):
try:
idx = int(choice) - 1
except ValueError:
print "Invalid choice (%s), exiting" % choice
print("Invalid choice (%s), exiting" % choice)
sys.exit(1)
if idx < 0 or idx >= len(config_items):
print "Invalid choice (%d), exiting" % (idx + 1)
print("Invalid choice (%d), exiting" % (idx + 1))
sys.exit(1)
removed.append(config_items.pop(idx))
write_config_items(scripts_path, machine, config_items)
print "Removed items:"
print("Removed items:")
for r in removed:
print "\t%s" % r
print("\t%s" % r)
def yocto_kernel_config_add(scripts_path, machine, config_items):
@ -239,7 +238,7 @@ def yocto_kernel_config_add(scripts_path, machine, config_items):
for item in config_items:
if not item.startswith("CONFIG") or (not "=y" in item and not "=m" in item):
print "Invalid config item (%s), exiting" % item
print("Invalid config item (%s), exiting" % item)
sys.exit(1)
if item not in cur_items and item not in new_items:
new_items.append(item)
@ -249,16 +248,16 @@ def yocto_kernel_config_add(scripts_path, machine, config_items):
if len(new_items) > 0:
cur_items.extend(new_items)
write_config_items(scripts_path, machine, cur_items)
print "Added item%s:" % ("" if len(new_items)==1 else "s")
print("Added item%s:" % ("" if len(new_items)==1 else "s"))
for n in new_items:
print "\t%s" % n
print("\t%s" % n)
if len(dup_items) > 0:
output="The following item%s already exist%s in the current configuration, ignoring %s:" % \
(("","s", "it") if len(dup_items)==1 else ("s", "", "them" ))
print output
print(output)
for n in dup_items:
print "\t%s" % n
print("\t%s" % n)
def find_current_kernel(bsp_layer, machine):
"""
@ -348,8 +347,8 @@ def yocto_kernel_patch_list(scripts_path, machine):
"""
patches = read_patch_items(scripts_path, machine)
print "The current set of machine-specific patches for %s is:" % machine
print gen_choices_str(patches)
print("The current set of machine-specific patches for %s is:" % machine)
print(gen_choices_str(patches))
def yocto_kernel_patch_rm(scripts_path, machine):
@ -359,7 +358,7 @@ def yocto_kernel_patch_rm(scripts_path, machine):
"""
patches = read_patch_items(scripts_path, machine)
print "Specify the patches to remove:"
print("Specify the patches to remove:")
input = raw_input(gen_choices_str(patches))
rm_choices = input.split()
rm_choices.sort()
@ -368,17 +367,17 @@ def yocto_kernel_patch_rm(scripts_path, machine):
filesdir = find_filesdir(scripts_path, machine)
if not filesdir:
print "Couldn't rm patch(es) since we couldn't find a 'files' dir"
print("Couldn't rm patch(es) since we couldn't find a 'files' dir")
sys.exit(1)
for choice in reversed(rm_choices):
try:
idx = int(choice) - 1
except ValueError:
print "Invalid choice (%s), exiting" % choice
print("Invalid choice (%s), exiting" % choice)
sys.exit(1)
if idx < 0 or idx >= len(patches):
print "Invalid choice (%d), exiting" % (idx + 1)
print("Invalid choice (%d), exiting" % (idx + 1))
sys.exit(1)
filesdir_patch = os.path.join(filesdir, patches[idx])
if os.path.isfile(filesdir_patch):
@ -388,9 +387,9 @@ def yocto_kernel_patch_rm(scripts_path, machine):
write_patch_items(scripts_path, machine, patches)
print "Removed patches:"
print("Removed patches:")
for r in removed:
print "\t%s" % r
print("\t%s" % r)
def yocto_kernel_patch_add(scripts_path, machine, patches):
@ -402,19 +401,19 @@ def yocto_kernel_patch_add(scripts_path, machine, patches):
for patch in patches:
if os.path.basename(patch) in existing_patches:
print "Couldn't add patch (%s) since it's already been added" % os.path.basename(patch)
print("Couldn't add patch (%s) since it's already been added" % os.path.basename(patch))
sys.exit(1)
filesdir = find_filesdir(scripts_path, machine)
if not filesdir:
print "Couldn't add patch (%s) since we couldn't find a 'files' dir to add it to" % os.path.basename(patch)
print("Couldn't add patch (%s) since we couldn't find a 'files' dir to add it to" % os.path.basename(patch))
sys.exit(1)
new_patches = []
for patch in patches:
if not os.path.isfile(patch):
print "Couldn't find patch (%s), exiting" % patch
print("Couldn't find patch (%s), exiting" % patch)
sys.exit(1)
basename = os.path.basename(patch)
filesdir_patch = os.path.join(filesdir, basename)
@ -425,9 +424,9 @@ def yocto_kernel_patch_add(scripts_path, machine, patches):
cur_items.extend(new_patches)
write_patch_items(scripts_path, machine, cur_items)
print "Added patches:"
print("Added patches:")
for n in new_patches:
print "\t%s" % n
print("\t%s" % n)
def inc_pr(line):
@ -462,7 +461,7 @@ def kernel_contents_changed(scripts_path, machine):
kernel = find_current_kernel(layer, machine)
if not kernel:
print "Couldn't determine the kernel for this BSP, exiting."
print("Couldn't determine the kernel for this BSP, exiting.")
sys.exit(1)
kernel_bbfile = os.path.join(layer, "recipes-kernel/linux/" + kernel + ".bbappend")
@ -598,8 +597,8 @@ def yocto_kernel_feature_list(scripts_path, machine):
"""
features = read_features(scripts_path, machine)
print "The current set of machine-specific features for %s is:" % machine
print gen_choices_str(features)
print("The current set of machine-specific features for %s is:" % machine)
print(gen_choices_str(features))
def yocto_kernel_feature_rm(scripts_path, machine):
@ -610,7 +609,7 @@ def yocto_kernel_feature_rm(scripts_path, machine):
"""
features = read_features(scripts_path, machine)
print "Specify the features to remove:"
print("Specify the features to remove:")
input = raw_input(gen_choices_str(features))
rm_choices = input.split()
rm_choices.sort()
@ -621,18 +620,18 @@ def yocto_kernel_feature_rm(scripts_path, machine):
try:
idx = int(choice) - 1
except ValueError:
print "Invalid choice (%s), exiting" % choice
print("Invalid choice (%s), exiting" % choice)
sys.exit(1)
if idx < 0 or idx >= len(features):
print "Invalid choice (%d), exiting" % (idx + 1)
print("Invalid choice (%d), exiting" % (idx + 1))
sys.exit(1)
removed.append(features.pop(idx))
write_features(scripts_path, machine, features)
print "Removed features:"
print("Removed features:")
for r in removed:
print "\t%s" % r
print("\t%s" % r)
def yocto_kernel_feature_add(scripts_path, machine, features):
@ -644,7 +643,7 @@ def yocto_kernel_feature_add(scripts_path, machine, features):
for item in features:
if not item.endswith(".scc"):
print "Invalid feature (%s), exiting" % item
print("Invalid feature (%s), exiting" % item)
sys.exit(1)
new_items.append(item)
@ -653,9 +652,9 @@ def yocto_kernel_feature_add(scripts_path, machine, features):
write_features(scripts_path, machine, cur_items)
print "Added features:"
print("Added features:")
for n in new_items:
print "\t%s" % n
print("\t%s" % n)
def find_feature_url(git_url):
@ -715,7 +714,7 @@ def print_feature_descs(layer, feature_dir):
feature_dir + "/" + file)
f = open(fullpath)
feature_desc = find_feature_desc(f.readlines())
print feature_dir + "/" + file + ": " + feature_desc
print(feature_dir + "/" + file + ": " + feature_desc)
def yocto_kernel_available_features_list(scripts_path, machine):
@ -726,7 +725,7 @@ def yocto_kernel_available_features_list(scripts_path, machine):
layer = find_bsp_layer(machine)
kernel = find_current_kernel(layer, machine)
if not kernel:
print "Couldn't determine the kernel for this BSP, exiting."
print("Couldn't determine the kernel for this BSP, exiting.")
sys.exit(1)
context = create_context(machine, "arch", scripts_path)
@ -738,7 +737,7 @@ def yocto_kernel_available_features_list(scripts_path, machine):
feature_cmd = "wget -q -O - " + feature_url
tmp = subprocess.Popen(feature_cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
print "The current set of kernel features available to %s is:\n" % machine
print("The current set of kernel features available to %s is:\n" % machine)
if tmp:
tmpline = tmp.split("\n")
@ -755,9 +754,9 @@ def yocto_kernel_available_features_list(scripts_path, machine):
feature_type = feature_def[0].strip()
feature = feature_def[1].strip()
desc = get_feature_desc(giturl, feature)
print "%s: %s" % (feature, desc)
print("%s: %s" % (feature, desc))
print "[local]"
print("[local]")
print_feature_descs(layer, "cfg")
print_feature_descs(layer, "features")
@ -801,7 +800,7 @@ def yocto_kernel_feature_describe(scripts_path, machine, feature):
kernel = find_current_kernel(layer, machine)
if not kernel:
print "Couldn't determine the kernel for this BSP, exiting."
print("Couldn't determine the kernel for this BSP, exiting.")
sys.exit(1)
context = create_context(machine, "arch", scripts_path)
@ -811,7 +810,7 @@ def yocto_kernel_feature_describe(scripts_path, machine, feature):
desc = get_feature_desc(giturl, feature)
print desc
print(desc)
def check_feature_name(feature_name):
@ -819,11 +818,11 @@ def check_feature_name(feature_name):
Sanity-check the feature name for create/destroy. Return False if not OK.
"""
if not feature_name.endswith(".scc"):
print "Invalid feature name (must end with .scc) [%s], exiting" % feature_name
print("Invalid feature name (must end with .scc) [%s], exiting" % feature_name)
return False
if "/" in feature_name:
print "Invalid feature name (don't specify directory) [%s], exiting" % feature_name
print("Invalid feature name (don't specify directory) [%s], exiting" % feature_name)
return False
return True
@ -837,11 +836,11 @@ def check_create_input(feature_items):
return False
if feature_items[1].endswith(".patch") or feature_items[1].startswith("CONFIG_"):
print "Missing description and/or compatibilty [%s], exiting" % feature_items[1]
print("Missing description and/or compatibilty [%s], exiting" % feature_items[1])
return False
if feature_items[2].endswith(".patch") or feature_items[2].startswith("CONFIG_"):
print "Missing description and/or compatibility [%s], exiting" % feature_items[1]
print("Missing description and/or compatibility [%s], exiting" % feature_items[1])
return False
return True
@ -869,7 +868,7 @@ def yocto_kernel_feature_create(scripts_path, machine, feature_items):
if ("=y" in item or "=m" in item):
cfg_items.append(item)
else:
print "Invalid feature item (must be .patch or CONFIG_*) [%s], exiting" % item
print("Invalid feature item (must be .patch or CONFIG_*) [%s], exiting" % item)
sys.exit(1)
feature_dirname = "cfg"
@ -878,7 +877,7 @@ def yocto_kernel_feature_create(scripts_path, machine, feature_items):
filesdir = find_filesdir(scripts_path, machine)
if not filesdir:
print "Couldn't add feature (%s), no 'files' dir found" % feature
print("Couldn't add feature (%s), no 'files' dir found" % feature)
sys.exit(1)
featdir = os.path.join(filesdir, feature_dirname)
@ -887,7 +886,7 @@ def yocto_kernel_feature_create(scripts_path, machine, feature_items):
for patch in patches:
if not os.path.isfile(patch):
print "Couldn't find patch (%s), exiting" % patch
print("Couldn't find patch (%s), exiting" % patch)
sys.exit(1)
basename = os.path.basename(patch)
featdir_patch = os.path.join(featdir, basename)
@ -911,8 +910,8 @@ def yocto_kernel_feature_create(scripts_path, machine, feature_items):
new_feature_file.write("kconf non-hardware " + feature_basename + ".cfg\n")
new_feature_file.close()
print "Added feature:"
print "\t%s" % feature_dirname + "/" + feature
print("Added feature:")
print("\t%s" % feature_dirname + "/" + feature)
def feature_in_use(scripts_path, machine, feature):
@ -950,18 +949,18 @@ def yocto_kernel_feature_destroy(scripts_path, machine, feature):
if feature_in_use(scripts_path, machine, "features/" + feature) or \
feature_in_use(scripts_path, machine, "cfg/" + feature):
print "Feature %s is in use (use 'feature rm' to un-use it first), exiting" % feature
print("Feature %s is in use (use 'feature rm' to un-use it first), exiting" % feature)
sys.exit(1)
filesdir = find_filesdir(scripts_path, machine)
if not filesdir:
print "Couldn't destroy feature (%s), no 'files' dir found" % feature
print("Couldn't destroy feature (%s), no 'files' dir found" % feature)
sys.exit(1)
feature_dirname = "features"
featdir = os.path.join(filesdir, feature_dirname)
if not os.path.exists(featdir):
print "Couldn't find feature directory (%s)" % feature_dirname
print("Couldn't find feature directory (%s)" % feature_dirname)
sys.exit(1)
feature_fqn = os.path.join(featdir, feature)
@ -969,11 +968,11 @@ def yocto_kernel_feature_destroy(scripts_path, machine, feature):
feature_dirname = "cfg"
featdir = os.path.join(filesdir, feature_dirname)
if not os.path.exists(featdir):
print "Couldn't find feature directory (%s)" % feature_dirname
print("Couldn't find feature directory (%s)" % feature_dirname)
sys.exit(1)
feature_fqn = os.path.join(featdir, feature_filename)
if not os.path.exists(feature_fqn):
print "Couldn't find feature (%s)" % feature
print("Couldn't find feature (%s)" % feature)
sys.exit(1)
f = open(feature_fqn, "r")
@ -990,8 +989,8 @@ def yocto_kernel_feature_destroy(scripts_path, machine, feature):
feature_remove(scripts_path, machine, feature)
print "Removed feature:"
print "\t%s" % feature_dirname + "/" + feature
print("Removed feature:")
print("\t%s" % feature_dirname + "/" + feature)
def base_branches(context):
@ -1000,7 +999,7 @@ def base_branches(context):
"""
giturl = find_giturl(context)
print "Getting branches from remote repo %s..." % giturl
print("Getting branches from remote repo %s..." % giturl)
gitcmd = "git ls-remote %s *heads* 2>&1" % (giturl)
tmp = subprocess.Popen(gitcmd, shell=True, stdout=subprocess.PIPE).stdout.read()
@ -1030,7 +1029,7 @@ def all_branches(context):
"""
giturl = find_giturl(context)
print "Getting branches from remote repo %s..." % giturl
print("Getting branches from remote repo %s..." % giturl)
gitcmd = "git ls-remote %s *heads* 2>&1" % (giturl)
tmp = subprocess.Popen(gitcmd, shell=True, stdout=subprocess.PIPE).stdout.read()

View File

@ -76,15 +76,15 @@ def yocto_bsp_create_subcommand(args, usage_str):
bsp_output_dir = "meta-" + machine
if options.git_check and not options.properties_file:
print "Checking basic git connectivity..."
print("Checking basic git connectivity...")
if not verify_git_repo(GIT_CHECK_URI):
print "Couldn't verify git connectivity, exiting\n"
print "Details: couldn't access %s" % GIT_CHECK_URI
print " (this most likely indicates a network connectivity problem or"
print " a misconfigured git intallation)"
print("Couldn't verify git connectivity, exiting\n")
print("Details: couldn't access %s" % GIT_CHECK_URI)
print(" (this most likely indicates a network connectivity problem or")
print(" a misconfigured git intallation)")
sys.exit(1)
else:
print "Done.\n"
print("Done.\n")
yocto_bsp_create(machine, karch, scripts_path, bsp_output_dir, options.codedump, options.properties_file)