scripts/bitbake-whatchanged: migrate from optparse to argparse

The script bitbake-whatchanged uses optparse library, which is
deprecated since python 2.7. This migrates to argparse library.

[Yocto #9634]

(From OE-Core rev: b6c71616e66708bb1c456b83f98913b198f49a4a)

Signed-off-by: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Humberto Ibarra 2016-05-19 14:51:54 -05:00 committed by Richard Purdie
parent aac36591db
commit 21af6c60b0
1 changed files with 12 additions and 20 deletions

View File

@ -25,7 +25,7 @@ import shutil
import re import re
import warnings import warnings
import subprocess import subprocess
from optparse import OptionParser import argparse
scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
lib_path = scripts_path + '/lib' lib_path = scripts_path + '/lib'
@ -38,6 +38,8 @@ bitbakepath = scriptpath.add_bitbake_lib_path()
if not bitbakepath: if not bitbakepath:
sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n") sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
sys.exit(1) sys.exit(1)
scriptpath.add_oe_lib_path()
import argparse_oe
import bb.siggen import bb.siggen
import bb.process import bb.process
@ -219,9 +221,7 @@ def main():
3) Use bb.siggen.compare_sigfiles to diff the old and new stamps 3) Use bb.siggen.compare_sigfiles to diff the old and new stamps
""" """
parser = OptionParser( parser = argparse_oe.ArgumentParser(usage = """%(prog)s [options] [package ...]
version = "1.0",
usage = """%prog [options] [package ...]
print what will be done between the current and last builds, for example: print what will be done between the current and last builds, for example:
$ bitbake core-image-sato $ bitbake core-image-sato
@ -236,17 +236,9 @@ Note:
The "nostamp" task is not included. The "nostamp" task is not included.
""" """
) )
parser.add_option("-v", "--verbose", help = "print the verbose changes", parser.add_argument("recipe", help="recipe to check")
action = "store_true", dest = "verbose") parser.add_argument("-v", "--verbose", help = "print the verbose changes", action = "store_true")
args = parser.parse_args()
options, args = parser.parse_args(sys.argv)
verbose = options.verbose
if len(args) != 2:
parser.error("Incorrect number of arguments")
else:
recipe = args[1]
# Get the STAMPS_DIR # Get the STAMPS_DIR
print("Figuring out the STAMPS_DIR ...") print("Figuring out the STAMPS_DIR ...")
@ -256,7 +248,7 @@ Note:
except: except:
raise raise
if not stampsdir: if not stampsdir:
print("ERROR: No STAMPS_DIR found for '%s'" % recipe, file=sys.stderr) print("ERROR: No STAMPS_DIR found for '%s'" % args.recipe, file=sys.stderr)
return 2 return 2
stampsdir = stampsdir.rstrip("\n") stampsdir = stampsdir.rstrip("\n")
if not os.path.isdir(stampsdir): if not os.path.isdir(stampsdir):
@ -272,7 +264,7 @@ Note:
try: try:
# Generate the new stamps dir # Generate the new stamps dir
print("Generating the new stamps ... (need several minutes)") print("Generating the new stamps ... (need several minutes)")
cmdline = "STAMPS_DIR=%s bitbake -S none %s" % (new_stampsdir, recipe) cmdline = "STAMPS_DIR=%s bitbake -S none %s" % (new_stampsdir, args.recipe)
# FIXME # FIXME
# The "bitbake -S" may fail, not fatal error, the stamps will still # The "bitbake -S" may fail, not fatal error, the stamps will still
# be generated, this might be a bug of "bitbake -S". # be generated, this might be a bug of "bitbake -S".
@ -310,17 +302,17 @@ Note:
# PV (including PE) and PR changed # PV (including PE) and PR changed
# Let the bb.siggen handle them if verbose # Let the bb.siggen handle them if verbose
cnt_rv = {} cnt_rv = {}
if not verbose: if not args.verbose:
for i in ('pv', 'pr'): for i in ('pv', 'pr'):
cnt_rv[i] = print_vrchanged(new_recon, old_recon, i) cnt_rv[i] = print_vrchanged(new_recon, old_recon, i)
# Dependencies changed (use bitbake-diffsigs) # Dependencies changed (use bitbake-diffsigs)
cnt_dep = print_depchanged(new_recon, old_recon, verbose) cnt_dep = print_depchanged(new_recon, old_recon, args.verbose)
total_changed = cnt_added + (cnt_rv.get('pv') or 0) + (cnt_rv.get('pr') or 0) + cnt_dep total_changed = cnt_added + (cnt_rv.get('pv') or 0) + (cnt_rv.get('pr') or 0) + cnt_dep
print("\n=== Summary: (%s changed, %s unchanged)" % (total_changed, cnt_unchanged)) print("\n=== Summary: (%s changed, %s unchanged)" % (total_changed, cnt_unchanged))
if verbose: if args.verbose:
print("Newly added: %s\nDependencies changed: %s\n" % \ print("Newly added: %s\nDependencies changed: %s\n" % \
(cnt_added, cnt_dep)) (cnt_added, cnt_dep))
else: else: