triage_version.py: added `--no-quiet`, `--no-stderr` and `--no-stdout` for more granular output control (#4713)

This commit is contained in:
Oliver Stöneberg 2023-01-18 17:00:57 +01:00 committed by GitHub
parent dee2ad8756
commit c99c444877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -17,6 +17,9 @@ parser.add_argument('--debug-warnings', action='store_true', help='passed throug
parser.add_argument('--check-library', action='store_true', help='passed through to binary if supported') parser.add_argument('--check-library', action='store_true', help='passed through to binary if supported')
parser.add_argument('--timeout', type=int, default=2, help='the amount of seconds to wait for the analysis to finish') parser.add_argument('--timeout', type=int, default=2, help='the amount of seconds to wait for the analysis to finish')
parser.add_argument('--compact', action='store_true', help='only print versions with changes with --compare') parser.add_argument('--compact', action='store_true', help='only print versions with changes with --compare')
parser.add_argument('--no-quiet', action='store_true', default=False, help='do not specify -q')
parser.add_argument('--no-stderr', action='store_true', default=False, help='do not display stdout')
parser.add_argument('--no-stdout', action='store_true', default=False, help='do not display stderr')
args = parser.parse_args() args = parser.parse_args()
def sort_commit_hashes(commits): def sort_commit_hashes(commits):
@ -36,6 +39,10 @@ if args.compact:
print('error: --compact requires --compare') print('error: --compact requires --compare')
sys.exit(1) sys.exit(1)
if args.no_stdout and args.no_stderr:
print('error: cannot specify --no-stdout and --no-stderr at once')
sys.exit(1)
directory = args.dir directory = args.dir
input_file = args.infile input_file = args.infile
git_repo = args.repo git_repo = args.repo
@ -99,7 +106,7 @@ for entry in versions:
cmd = exe cmd = exe
cmd += ' ' cmd += ' '
if do_compare: if do_compare and not args.no_quiet:
cmd += ' -q ' cmd += ' -q '
if args.debug and Version(version) >= Version('1.45'): if args.debug and Version(version) >= Version('1.45'):
cmd += '--debug ' cmd += '--debug '
@ -121,7 +128,13 @@ for entry in versions:
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=exe_path, universal_newlines=True) p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=exe_path, universal_newlines=True)
try: try:
comm = p.communicate(timeout=args.timeout) comm = p.communicate(timeout=args.timeout)
out = comm[0] + '\n' + comm[1] out = ''
if not args.no_stdout:
out += comm[0]
if not args.no_stderr and not args.no_stderr:
out += '\n'
if not args.no_stderr:
out += comm[1]
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
out = "timeout" out = "timeout"
p.kill() p.kill()