Use print() instead of print in rtc_tools/ python scripts.

Bug: None
Change-Id: I065f8363583b0934b0b0e3d901b75d558514063c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146861
Reviewed-by: Oleh Prypin <oprypin@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28688}
This commit is contained in:
Mirko Bonadei
2019-07-25 18:38:54 +02:00
committed by Commit Bot
parent be4fcb63a2
commit 67f88a0d30
3 changed files with 40 additions and 30 deletions

View File

@ -7,6 +7,9 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import json
import optparse
import os
@ -102,7 +105,7 @@ def _RunFrameAnalyzer(options, yuv_directory=None):
stdout=sys.stdout, stderr=sys.stderr)
frame_analyzer.wait()
if frame_analyzer.returncode != 0:
print 'Failed to run frame analyzer.'
print('Failed to run frame analyzer.')
return frame_analyzer.returncode
@ -132,7 +135,7 @@ def _RunVmaf(options, yuv_directory, logfile):
stdout=sys.stdout, stderr=sys.stderr)
vmaf.wait()
if vmaf.returncode != 0:
print 'Failed to run VMAF.'
print('Failed to run VMAF.')
return 1
# Read per-frame scores from VMAF output and print.
@ -141,7 +144,7 @@ def _RunVmaf(options, yuv_directory, logfile):
vmaf_scores = []
for frame in vmaf_data['frames']:
vmaf_scores.append(frame['metrics']['vmaf'])
print 'RESULT VMAF: %s=' % options.label, vmaf_scores
print('RESULT VMAF: %s=' % options.label, vmaf_scores)
return 0

View File

@ -9,10 +9,14 @@
"""Utilities for all our deps-management stuff."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import shutil
import sys
import subprocess
import sys
import tarfile
import time
import zipfile
@ -26,15 +30,15 @@ def RunSubprocessWithRetry(cmd):
return
except subprocess.CalledProcessError as exception:
backoff = pow(2, i)
print 'Got %s, retrying in %d seconds...' % (exception, backoff)
print('Got %s, retrying in %d seconds...' % (exception, backoff))
time.sleep(backoff)
print 'Giving up.'
print('Giving up.')
raise exception
def DownloadFilesFromGoogleStorage(path, auto_platform=True):
print 'Downloading files in %s...' % path
print('Downloading files in %s...' % path)
extension = 'bat' if 'win32' in sys.platform else 'py'
cmd = ['download_from_google_storage.%s' % extension,
@ -64,20 +68,20 @@ def RemoveDirectory(*path):
works. :/
"""
file_path = os.path.join(*path)
print 'Deleting `{}`.'.format(file_path)
print('Deleting `{}`.'.format(file_path))
if not os.path.exists(file_path):
print '`{}` does not exist.'.format(file_path)
print('`{}` does not exist.'.format(file_path))
return
if sys.platform == 'win32':
# Give up and use cmd.exe's rd command.
file_path = os.path.normcase(file_path)
for _ in xrange(3):
print 'RemoveDirectory running %s' % (' '.join(
['cmd.exe', '/c', 'rd', '/q', '/s', file_path]))
print('RemoveDirectory running %s' % (' '.join(
['cmd.exe', '/c', 'rd', '/q', '/s', file_path])))
if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
break
print ' Failed'
print(' Failed')
time.sleep(3)
return
else:
@ -93,7 +97,7 @@ def UnpackArchiveTo(archive_path, output_dir):
def _UnzipArchiveTo(archive_path, output_dir):
print 'Unzipping {} in {}.'.format(archive_path, output_dir)
print('Unzipping {} in {}.'.format(archive_path, output_dir))
zip_file = zipfile.ZipFile(archive_path)
try:
zip_file.extractall(output_dir)
@ -102,7 +106,7 @@ def _UnzipArchiveTo(archive_path, output_dir):
def _UntarArchiveTo(archive_path, output_dir):
print 'Untarring {} in {}.'.format(archive_path, output_dir)
print('Untarring {} in {}.'.format(archive_path, output_dir))
tar_file = tarfile.open(archive_path, 'r:gz')
try:
tar_file.extractall(output_dir)

View File

@ -7,6 +7,9 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import glob
import optparse
import os
@ -186,7 +189,7 @@ def FindUsbPortForV4lDevices(ref_video_device, test_video_device):
ref_path = str(v4l_ref_device).split('driver')[1].split('/')
test_path = str(v4l_test_device).split('driver')[1].split('/')
except IndexError:
print 'Could not find one or both of the specified recording devices.'
print('Could not find one or both of the specified recording devices.')
else:
paths.append(ref_path)
paths.append(test_path)
@ -227,7 +230,7 @@ def RestartMagewellDevices(ref_video_device_path, test_video_device_path):
if len(magewell_usb_ports) == 0:
raise MagewellError('No magewell devices found.')
else:
print '\nResetting USB ports where magewell devices are connected...'
print('\nResetting USB ports where magewell devices are connected...')
# Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices
# (i.e. soft eject and insert).
for usb_port in magewell_usb_ports:
@ -247,7 +250,7 @@ def RestartMagewellDevices(ref_video_device_path, test_video_device_path):
echo_bind.stdout.close()
bind.wait()
if bind.returncode == 0:
print 'Reset done!\n'
print('Reset done!\n')
def StartRecording(options, ref_file_location, test_file_location):
@ -302,14 +305,14 @@ def StartRecording(options, ref_file_location, test_file_location):
'-r', '%d' % options.framerate,
test_file
]
print 'Trying to record from reference recorder...'
print('Trying to record from reference recorder...')
ref_recorder = subprocess.Popen(ref_cmd)
# Start the 2nd recording a little later to ensure the 1st one has started.
# TODO(jansson) Check that the ref_recorder output file exists rather than
# using sleep.
time.sleep(options.time_between_recordings)
print 'Trying to record from test recorder...'
print('Trying to record from test recorder...')
test_recorder = subprocess.Popen(test_cmd)
test_recorder.wait()
ref_recorder.wait()
@ -321,9 +324,9 @@ def StartRecording(options, ref_file_location, test_file_location):
shutil.rmtree(test_file_location)
raise FfmpegError('Recording failed, check ffmpeg output.')
else:
print 'Ref file recorded to: ' + os.path.abspath(ref_file)
print 'Test file recorded to: ' + os.path.abspath(test_file)
print 'Recording done!\n'
print('Ref file recorded to: ' + os.path.abspath(ref_file))
print('Test file recorded to: ' + os.path.abspath(test_file))
print('Recording done!\n')
return FlipAndCropRecordings(options, test_file_name, test_file_location,
ref_file_name, ref_file_location)
@ -349,7 +352,7 @@ def FlipAndCropRecordings(options, test_file_name, test_file_location,
Raises:
FfmpegError: If the ffmpeg command fails.
"""
print 'Trying to crop videos...'
print('Trying to crop videos...')
# Ref file cropping.
cropped_ref_file_name = 'cropped_' + ref_file_name
@ -393,9 +396,9 @@ def FlipAndCropRecordings(options, test_file_name, test_file_location,
shutil.rmtree(test_file_location)
raise FfmpegError('Cropping failed, check ffmpeg output.')
else:
print 'Ref file cropped to: ' + cropped_ref_file
print 'Test file cropped to: ' + cropped_test_file
print 'Cropping done!\n'
print('Ref file cropped to: ' + cropped_ref_file)
print('Test file cropped to: ' + cropped_test_file)
print('Cropping done!\n')
# Need to return these so they can be used by other parts.
cropped_recordings = {
@ -420,8 +423,8 @@ def CompareVideos(options, cropped_ref_file, cropped_test_file):
Raises:
CompareVideosError: If compare_videos.py fails.
"""
print 'Starting comparison...'
print 'Grab a coffee, this might take a few minutes...'
print('Starting comparison...')
print('Grab a coffee, this might take a few minutes...')
compare_videos_script = os.path.abspath(options.compare_videos_script)
rec_path = os.path.abspath(os.path.join(
os.path.dirname(cropped_test_file)))
@ -451,8 +454,8 @@ def CompareVideos(options, cropped_ref_file, cropped_test_file):
except subprocess.CalledProcessError as error:
raise CompareVideosError('Failed to perform comparison: %s' % error)
else:
print 'Result recorded to: %s' % os.path.abspath(result_file_name)
print 'Comparison done!'
print('Result recorded to: %s' % os.path.abspath(result_file_name))
print('Comparison done!')
return compare_video_recordings