Improve print statement compatibility with Python3

This commit is contained in:
marmeladema 2019-10-14 00:15:02 +01:00
parent eda6d3e0c5
commit 4e1ee07a79
4 changed files with 24 additions and 16 deletions

View file

@ -7,6 +7,8 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from __future__ import print_function
from errno import ENOENT as NO_SUCH_FILE_OR_DIRECTORY
from glob import glob
import shutil
@ -350,15 +352,15 @@ class CommandBase(object):
version_line = subprocess.check_output(["rustup" + BIN_SUFFIX, "--version"])
except OSError as e:
if e.errno == NO_SUCH_FILE_OR_DIRECTORY:
print "It looks like rustup is not installed. See instructions at " \
"https://github.com/servo/servo/#setting-up-your-environment"
print
print("It looks like rustup is not installed. See instructions at "
"https://github.com/servo/servo/#setting-up-your-environment")
print()
return 1
raise
version = tuple(map(int, re.match("rustup (\d+)\.(\d+)\.(\d+)", version_line).groups()))
if version < (1, 11, 0):
print "rustup is at version %s.%s.%s, Servo requires 1.11.0 or more recent." % version
print "Try running 'rustup self update'."
print("rustup is at version %s.%s.%s, Servo requires 1.11.0 or more recent." % version)
print("Try running 'rustup self update'.")
return 1
toolchain = self.toolchain()
if platform.system() == "Windows":

View file

@ -7,6 +7,8 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from __future__ import print_function
import os
import sys
@ -20,7 +22,7 @@ class Lint(LintRunner):
def _get_wpt_files(self, suite):
working_dir = os.path.join(WPT_PATH, suite, '')
file_iter = self.get_files(working_dir, exclude_dirs=[])
print '\nRunning the WPT lint on %s...' % working_dir
print('\nRunning the WPT lint on %s...' % working_dir)
for f in file_iter:
if filter_file(f):
yield f[len(working_dir):]

View file

@ -7,6 +7,8 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from __future__ import print_function
import fileinput
import re
import random
@ -28,7 +30,7 @@ def init_variables(if_blocks):
def deleteStatements(file_name, line_numbers):
for line in fileinput.input(file_name, inplace=True):
if fileinput.lineno() not in line_numbers:
print line.rstrip()
print(line.rstrip())
class Strategy:
@ -48,7 +50,7 @@ class Strategy:
for line in fileinput.input(file_name, inplace=True):
if fileinput.lineno() == mutation_line_number:
line = re.sub(self._replace_strategy['regex'], self._replace_strategy['replaceString'], line)
print line.rstrip()
print(line.rstrip())
return mutation_line_number

View file

@ -7,6 +7,8 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from __future__ import print_function
import contextlib
import fnmatch
import imp
@ -514,7 +516,7 @@ def check_manifest_dirs(config_file, print_text=True):
lines = conf_file.splitlines(True)
if print_text:
print '\rChecking the wpt manifest file...'
print('\rChecking the wpt manifest file...')
p = parser.parse(lines)
paths = rec_parse(wpt_path("web-platform-tests"), p)
@ -908,7 +910,7 @@ def check_config_file(config_file, print_text=True):
lines = conf_file.splitlines(True)
if print_text:
print '\rChecking the config file...'
print('\rChecking the config file...')
config_content = toml.loads(conf_file)
exclude = config_content.get("ignore", {})
@ -995,7 +997,7 @@ def parse_config(config_file):
def check_directory_files(directories, print_text=True):
if print_text:
print '\rChecking directories for correct file extensions...'
print('\rChecking directories for correct file extensions...')
for directory, file_extensions in directories.items():
files = sorted(os.listdir(directory))
for filename in files:
@ -1015,7 +1017,7 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
if not has_element:
raise StopIteration
if print_text:
print '\rChecking files for tidiness...'
print('\rChecking files for tidiness...')
for filename in files_to_check:
if not os.path.exists(filename):
@ -1037,7 +1039,7 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
def get_dep_toml_files(only_changed_files=False):
if not only_changed_files:
print '\nRunning the dependency licensing lint...'
print('\nRunning the dependency licensing lint...')
for root, directories, filenames in os.walk(".cargo"):
for filename in filenames:
if filename == "Cargo.toml":
@ -1136,11 +1138,11 @@ def scan(only_changed_files=False, progress=True, stylo=False):
error = None
for error in errors:
colorama.init()
print "\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
print("\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error))
print
print()
if error is None:
colorama.init()
print "\033[92mtidy reported no errors.\033[0m"
print("\033[92mtidy reported no errors.\033[0m")
return int(error is not None)