wic: replace print statements with print function

Print statements have been replaced with print function in
Python 3. Replaced them in wic code to be able to run it
under both Python 2 and Python 3.

[YOCTO #9412]

(From OE-Core rev: ee6979a19c77931c3cf6368e695e370d46192fef)

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-04 16:06:14 +03:00 committed by Richard Purdie
parent 4dadbbdd46
commit 0c57dd96c8
4 changed files with 37 additions and 36 deletions

View File

@ -44,7 +44,7 @@ def verify_build_env():
Returns True if it is, false otherwise Returns True if it is, false otherwise
""" """
if not os.environ.get("BUILDDIR"): if not os.environ.get("BUILDDIR"):
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) sys.exit(1)
return True return True
@ -107,7 +107,7 @@ def list_canned_images(scripts_path):
desc = line[idx + len("short-description:"):].strip() desc = line[idx + len("short-description:"):].strip()
break break
basename = os.path.splitext(fname)[0] basename = os.path.splitext(fname)[0]
print " %s\t\t%s" % (basename.ljust(30), desc) print(" %s\t\t%s" % (basename.ljust(30), desc))
def list_canned_image_help(scripts_path, fullpath): def list_canned_image_help(scripts_path, fullpath):
@ -120,15 +120,15 @@ def list_canned_image_help(scripts_path, fullpath):
if not found: if not found:
idx = line.find("long-description:") idx = line.find("long-description:")
if idx != -1: if idx != -1:
print print()
print line[idx + len("long-description:"):].strip() print(line[idx + len("long-description:"):].strip())
found = True found = True
continue continue
if not line.strip(): if not line.strip():
break break
idx = line.find("#") idx = line.find("#")
if idx != -1: if idx != -1:
print line[idx + len("#:"):].rstrip() print(line[idx + len("#:"):].rstrip())
else: else:
break break
@ -140,7 +140,7 @@ def list_source_plugins():
plugins = pluginmgr.get_source_plugins() plugins = pluginmgr.get_source_plugins()
for plugin in plugins: for plugin in plugins:
print " %s" % plugin print(" %s" % plugin)
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
@ -178,7 +178,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
try: try:
oe_builddir = os.environ["BUILDDIR"] oe_builddir = os.environ["BUILDDIR"]
except KeyError: 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) sys.exit(1)
if debug: if debug:
@ -189,7 +189,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
crobj.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, crobj.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
wks_file, image_output_dir, oe_builddir, compressor or ""]) wks_file, image_output_dir, oe_builddir, compressor or ""])
print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
def wic_list(args, scripts_path): def wic_list(args, scripts_path):
@ -209,10 +209,10 @@ def wic_list(args, scripts_path):
wks_file = args[0] wks_file = args[0]
fullpath = find_canned_image(scripts_path, wks_file) fullpath = find_canned_image(scripts_path, wks_file)
if not fullpath: if not fullpath:
print "No image named %s found, exiting. "\ print("No image named %s found, exiting. "\
"(Use 'wic list images' to list available images, or "\ "(Use 'wic list images' to list available images, or "\
"specify a fully-qualified OE kickstart (.wks) "\ "specify a fully-qualified OE kickstart (.wks) "\
"filename)\n" % wks_file "filename)\n" % wks_file)
sys.exit(1) sys.exit(1)
list_canned_image_help(scripts_path, fullpath) list_canned_image_help(scripts_path, fullpath)
return True return True

View File

@ -55,7 +55,7 @@ def wic_help(args, usage_str, subcommands):
Subcommand help dispatcher. Subcommand help dispatcher.
""" """
if len(args) == 1 or not display_help(args[1], subcommands): if len(args) == 1 or not display_help(args[1], subcommands):
print usage_str print(usage_str)
def get_wic_plugins_help(): def get_wic_plugins_help():

View File

@ -187,8 +187,8 @@ class BitbakeVars(defaultdict):
for line in varsfile: for line in varsfile:
self._parse_line(line, image) self._parse_line(line, image)
else: else:
print "Couldn't get bitbake variable from %s." % fname print("Couldn't get bitbake variable from %s." % fname)
print "File %s doesn't exist." % fname print("File %s doesn't exist." % fname)
return return
else: else:
# Get bitbake -e output # Get bitbake -e output
@ -202,8 +202,8 @@ class BitbakeVars(defaultdict):
msger.set_loglevel(log_level) msger.set_loglevel(log_level)
if ret: if ret:
print "Couldn't get '%s' output." % cmd print("Couldn't get '%s' output." % cmd)
print "Bitbake failed with error:\n%s\n" % lines print("Bitbake failed with error:\n%s\n" % lines)
return return
# Parse bitbake -e output # Parse bitbake -e output

View File

@ -28,6 +28,7 @@
# AUTHORS # AUTHORS
# Tom Zanussi <tom.zanussi (at] linux.intel.com> # Tom Zanussi <tom.zanussi (at] linux.intel.com>
# #
from __future__ import print_function
__version__ = "0.2.0" __version__ = "0.2.0"
@ -140,8 +141,8 @@ def wic_create_subcommand(args, usage_str):
if not val: if not val:
missed.append(opt) missed.append(opt)
if missed: if missed:
print "The following build artifacts are not specified:" print("The following build artifacts are not specified:")
print " " + ", ".join(missed) print(" " + ", ".join(missed))
sys.exit(1) sys.exit(1)
if options.image_name: if options.image_name:
@ -153,12 +154,12 @@ def wic_create_subcommand(args, usage_str):
BB_VARS.vars_dir = options.vars_dir BB_VARS.vars_dir = options.vars_dir
if options.build_check: if options.build_check:
print "Checking basic build environment..." print("Checking basic build environment...")
if not engine.verify_build_env(): if not engine.verify_build_env():
print "Couldn't verify build environment, exiting\n" print("Couldn't verify build environment, exiting\n")
sys.exit(1) sys.exit(1)
else: else:
print "Done.\n" print("Done.\n")
bootimg_dir = "" bootimg_dir = ""
@ -168,7 +169,7 @@ def wic_create_subcommand(args, usage_str):
if options.debug: if options.debug:
argv.append("--debug") argv.append("--debug")
print "Building rootfs...\n" print("Building rootfs...\n")
if bitbake_main(BitBakeConfigParameters(argv), if bitbake_main(BitBakeConfigParameters(argv),
cookerdata.CookerConfiguration()): cookerdata.CookerConfiguration()):
sys.exit(1) sys.exit(1)
@ -179,7 +180,7 @@ def wic_create_subcommand(args, usage_str):
options.image_name) options.image_name)
else: else:
if options.build_rootfs: if options.build_rootfs:
print "Image name is not specified, exiting. (Use -e/--image-name to specify it)\n" print("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n")
sys.exit(1) sys.exit(1)
wks_file = args[0] wks_file = args[0]
@ -187,9 +188,9 @@ def wic_create_subcommand(args, usage_str):
if not wks_file.endswith(".wks"): if not wks_file.endswith(".wks"):
wks_file = engine.find_canned_image(scripts_path, wks_file) wks_file = engine.find_canned_image(scripts_path, wks_file)
if not wks_file: if not wks_file:
print "No image named %s found, exiting. (Use 'wic list images' "\ print("No image named %s found, exiting. (Use 'wic list images' "\
"to list available images, or specify a fully-qualified OE "\ "to list available images, or specify a fully-qualified OE "\
"kickstart (.wks) filename)\n" % args[0] "kickstart (.wks) filename)\n" % args[0])
sys.exit(1) sys.exit(1)
image_output_dir = "" image_output_dir = ""
@ -204,16 +205,16 @@ def wic_create_subcommand(args, usage_str):
kernel_dir = options.kernel_dir kernel_dir = options.kernel_dir
native_sysroot = options.native_sysroot native_sysroot = options.native_sysroot
if rootfs_dir and not os.path.isdir(rootfs_dir): if rootfs_dir and not os.path.isdir(rootfs_dir):
print "--roofs-dir (-r) not found, exiting\n" print("--roofs-dir (-r) not found, exiting\n")
sys.exit(1) sys.exit(1)
if not os.path.isdir(bootimg_dir): if not os.path.isdir(bootimg_dir):
print "--bootimg-dir (-b) not found, exiting\n" print("--bootimg-dir (-b) not found, exiting\n")
sys.exit(1) sys.exit(1)
if not os.path.isdir(kernel_dir): if not os.path.isdir(kernel_dir):
print "--kernel-dir (-k) not found, exiting\n" print("--kernel-dir (-k) not found, exiting\n")
sys.exit(1) sys.exit(1)
if not os.path.isdir(native_sysroot): if not os.path.isdir(native_sysroot):
print "--native-sysroot (-n) not found, exiting\n" print("--native-sysroot (-n) not found, exiting\n")
sys.exit(1) sys.exit(1)
else: else:
not_found = not_found_dir = "" not_found = not_found_dir = ""
@ -226,12 +227,12 @@ def wic_create_subcommand(args, usage_str):
if not_found: if not_found:
if not not_found_dir: if not not_found_dir:
not_found_dir = "Completely missing artifact - wrong image (.wks) used?" not_found_dir = "Completely missing artifact - wrong image (.wks) used?"
print "Build artifacts not found, exiting." print("Build artifacts not found, exiting.")
print " (Please check that the build artifacts for the machine" print(" (Please check that the build artifacts for the machine")
print " selected in local.conf actually exist and that they" print(" selected in local.conf actually exist and that they")
print " are the correct artifacts for the image (.wks file)).\n" print(" are the correct artifacts for the image (.wks file)).\n")
print "The artifact that couldn't be found was %s:\n %s" % \ print("The artifact that couldn't be found was %s:\n %s" % \
(not_found, not_found_dir) (not_found, not_found_dir))
sys.exit(1) sys.exit(1)
krootfs_dir = options.rootfs_dir krootfs_dir = options.rootfs_dir
@ -241,7 +242,7 @@ def wic_create_subcommand(args, usage_str):
rootfs_dir = rootfs_dir_to_args(krootfs_dir) rootfs_dir = rootfs_dir_to_args(krootfs_dir)
print "Creating image(s)...\n" print("Creating image(s)...\n")
engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, scripts_path, image_output_dir, native_sysroot, scripts_path, image_output_dir,
options.compressor, options.debug) options.compressor, options.debug)
@ -318,6 +319,6 @@ if __name__ == "__main__":
try: try:
sys.exit(main(sys.argv[1:])) sys.exit(main(sys.argv[1:]))
except WicError as err: except WicError as err:
print >> sys.stderr, "ERROR:", err print("ERROR:", err, file=sys.stderr)
sys.exit(1) sys.exit(1)