Add verbose switch to silence all output except the final report

This commit is contained in:
Darryl Green 2019-03-08 11:30:04 +00:00
parent 1d95c539e9
commit 3c3da790d2

View File

@ -52,7 +52,7 @@ class RepoVersion(object):
class AbiChecker(object): class AbiChecker(object):
"""API and ABI checker.""" """API and ABI checker."""
def __init__(self, old_version, new_version, report_dir, def __init__(self, verbose, old_version, new_version, report_dir,
keep_all_reports, brief, skip_file=None): keep_all_reports, brief, skip_file=None):
"""Instantiate the API/ABI checker. """Instantiate the API/ABI checker.
@ -65,6 +65,7 @@ class AbiChecker(object):
""" """
self.repo_path = "." self.repo_path = "."
self.log = None self.log = None
self.verbose = verbose
self._setup_logger() self._setup_logger()
self.report_dir = os.path.abspath(report_dir) self.report_dir = os.path.abspath(report_dir)
self.keep_all_reports = keep_all_reports self.keep_all_reports = keep_all_reports
@ -86,6 +87,9 @@ class AbiChecker(object):
def _setup_logger(self): def _setup_logger(self):
self.log = logging.getLogger() self.log = logging.getLogger()
if self.verbose:
self.log.setLevel(logging.DEBUG)
else:
self.log.setLevel(logging.INFO) self.log.setLevel(logging.INFO)
self.log.addHandler(logging.StreamHandler()) self.log.addHandler(logging.StreamHandler())
@ -100,7 +104,7 @@ class AbiChecker(object):
Do not modify the current worktree.""" Do not modify the current worktree."""
git_worktree_path = tempfile.mkdtemp() git_worktree_path = tempfile.mkdtemp()
if version.repository: if version.repository:
self.log.info( self.log.debug(
"Checking out git worktree for revision {} from {}".format( "Checking out git worktree for revision {} from {}".format(
version.revision, version.repository version.revision, version.repository
) )
@ -113,12 +117,12 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
fetch_output, _ = fetch_process.communicate() fetch_output, _ = fetch_process.communicate()
self.log.info(fetch_output.decode("utf-8")) self.log.debug(fetch_output.decode("utf-8"))
if fetch_process.returncode != 0: if fetch_process.returncode != 0:
raise Exception("Fetching revision failed, aborting") raise Exception("Fetching revision failed, aborting")
worktree_rev = "FETCH_HEAD" worktree_rev = "FETCH_HEAD"
else: else:
self.log.info("Checking out git worktree for revision {}".format( self.log.debug("Checking out git worktree for revision {}".format(
version.revision version.revision
)) ))
worktree_rev = version.revision worktree_rev = version.revision
@ -130,7 +134,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
worktree_output, _ = worktree_process.communicate() worktree_output, _ = worktree_process.communicate()
self.log.info(worktree_output.decode("utf-8")) self.log.debug(worktree_output.decode("utf-8"))
if worktree_process.returncode != 0: if worktree_process.returncode != 0:
raise Exception("Checking out worktree failed, aborting") raise Exception("Checking out worktree failed, aborting")
return git_worktree_path return git_worktree_path
@ -143,7 +147,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
output, _ = process.communicate() output, _ = process.communicate()
self.log.info(output.decode("utf-8")) self.log.debug(output.decode("utf-8"))
if process.returncode != 0: if process.returncode != 0:
raise Exception("git submodule update failed, aborting") raise Exception("git submodule update failed, aborting")
if not (os.path.exists(os.path.join(git_worktree_path, "crypto")) if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
@ -159,7 +163,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
fetch_output, _ = fetch_process.communicate() fetch_output, _ = fetch_process.communicate()
self.log.info(fetch_output.decode("utf-8")) self.log.debug(fetch_output.decode("utf-8"))
if fetch_process.returncode != 0: if fetch_process.returncode != 0:
raise Exception("git fetch failed, aborting") raise Exception("git fetch failed, aborting")
crypto_rev = "FETCH_HEAD" crypto_rev = "FETCH_HEAD"
@ -173,7 +177,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
checkout_output, _ = checkout_process.communicate() checkout_output, _ = checkout_process.communicate()
self.log.info(checkout_output.decode("utf-8")) self.log.debug(checkout_output.decode("utf-8"))
if checkout_process.returncode != 0: if checkout_process.returncode != 0:
raise Exception("git checkout failed, aborting") raise Exception("git checkout failed, aborting")
@ -191,7 +195,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
make_output, _ = make_process.communicate() make_output, _ = make_process.communicate()
self.log.info(make_output.decode("utf-8")) self.log.debug(make_output.decode("utf-8"))
for root, dirs, files in os.walk(git_worktree_path): for root, dirs, files in os.walk(git_worktree_path):
for file in fnmatch.filter(files, "*.so"): for file in fnmatch.filter(files, "*.so"):
version.modules[os.path.splitext(file)[0]] = ( version.modules[os.path.splitext(file)[0]] = (
@ -223,7 +227,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
abi_dump_output, _ = abi_dump_process.communicate() abi_dump_output, _ = abi_dump_process.communicate()
self.log.info(abi_dump_output.decode("utf-8")) self.log.debug(abi_dump_output.decode("utf-8"))
if abi_dump_process.returncode != 0: if abi_dump_process.returncode != 0:
raise Exception("abi-dumper failed, aborting") raise Exception("abi-dumper failed, aborting")
version.abi_dumps[mbed_module] = output_path version.abi_dumps[mbed_module] = output_path
@ -238,7 +242,7 @@ class AbiChecker(object):
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
worktree_output, _ = worktree_process.communicate() worktree_output, _ = worktree_process.communicate()
self.log.info(worktree_output.decode("utf-8")) self.log.debug(worktree_output.decode("utf-8"))
if worktree_process.returncode != 0: if worktree_process.returncode != 0:
raise Exception("Worktree cleanup failed, aborting") raise Exception("Worktree cleanup failed, aborting")
@ -361,6 +365,10 @@ def run_main():
Note: must be run from Mbed TLS root.""" Note: must be run from Mbed TLS root."""
) )
) )
parser.add_argument(
"-v", "--verbose", action="store_true",
help="set verbosity level",
)
parser.add_argument( parser.add_argument(
"-r", "--report-dir", type=str, default="reports", "-r", "--report-dir", type=str, default="reports",
help="directory where reports are stored, default is reports", help="directory where reports are stored, default is reports",
@ -413,7 +421,7 @@ def run_main():
new_version = RepoVersion("new", abi_args.new_repo, abi_args.new_rev, new_version = RepoVersion("new", abi_args.new_repo, abi_args.new_rev,
abi_args.new_crypto_repo, abi_args.new_crypto_rev) abi_args.new_crypto_repo, abi_args.new_crypto_rev)
abi_check = AbiChecker( abi_check = AbiChecker(
old_version, new_version, abi_args.report_dir, abi_args.verbose, old_version, new_version, abi_args.report_dir,
abi_args.keep_all_reports, abi_args.brief, abi_args.skip_file abi_args.keep_all_reports, abi_args.brief, abi_args.skip_file
) )
return_code = abi_check.check_for_abi_changes() return_code = abi_check.check_for_abi_changes()