Skip to content

Python fixes #8279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/exec_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def exec_cmd(cmd, path, input_string=None):
stdout=PIPE,
stderr=PIPE,
shell=(sys.platform == 'win32'))
out, err = process.communicate(input=input_string)
except IOError, (errno, strerror):
out, err = process.communicate(input=input_string.encode('utf-8'))
except IOError as e:
errno, strerror = e.args
raise
except:
raise
Expand Down
24 changes: 16 additions & 8 deletions tools/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def read_file(name, normalize = True):
# normalize line endings
data = data.replace("\r\n", "\n")
return data
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to read file '+name+': '+strerror)
raise
else:
Expand All @@ -30,7 +31,8 @@ def write_file(name, data):
f = open(name, 'w')
# write the data
f.write(data)
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to write file '+name+': '+strerror)
raise
else:
Expand All @@ -50,7 +52,8 @@ def copy_file(src, dst, quiet = True):
shutil.copy(src, dst)
if not quiet:
sys.stdout.write('Transferring '+src+' file.\n')
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to copy file from '+src+' to '+dst+': '+strerror)
raise

Expand All @@ -60,7 +63,8 @@ def move_file(src, dst, quiet = True):
shutil.move(src, dst)
if not quiet:
sys.stdout.write('Moving '+src+' file.\n')
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to move file from '+src+' to '+dst+': '+strerror)
raise

Expand All @@ -80,7 +84,8 @@ def remove_file(name, quiet = True):
os.remove(name)
if not quiet:
sys.stdout.write('Removing '+name+' file.\n')
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to remove file '+name+': '+strerror)
raise

Expand All @@ -91,7 +96,8 @@ def copy_dir(src, dst, quiet = True):
shutil.copytree(src, dst)
if not quiet:
sys.stdout.write('Transferring '+src+' directory.\n')
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to copy directory from '+src+' to '+dst+': '+strerror)
raise

Expand All @@ -102,7 +108,8 @@ def remove_dir(name, quiet = True):
shutil.rmtree(name)
if not quiet:
sys.stdout.write('Removing '+name+' directory.\n')
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to remove directory '+name+': '+strerror)
raise

Expand All @@ -113,7 +120,8 @@ def make_dir(name, quiet = True):
if not quiet:
sys.stdout.write('Creating '+name+' directory.\n')
os.makedirs(name)
except IOError, (errno, strerror):
except IOError as e:
errno, strerror = e.args
sys.stderr.write('Failed to create directory '+name+': '+strerror)
raise

Expand Down
10 changes: 5 additions & 5 deletions tools/git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def git_apply_patch_file(patch_path, patch_dir):
sys.stdout.write('... patch file does not exist.\n')
return 'fail'

patch_string = open(patch_path, 'rb').read()
patch_string = open(patch_path, 'rb').read().decode('utf-8')
if sys.platform == 'win32':
# Convert the patch to Unix line endings. This is necessary to avoid
# whitespace errors with git apply.
Expand All @@ -97,19 +97,19 @@ def git_apply_patch_file(patch_path, patch_dir):
# Output patch contents.
cmd = '%s apply -p0 --numstat' % git_exe
result = exec_cmd(cmd, patch_dir, patch_string)
write_indented_output(result['out'].replace('<stdin>', patch_name))
write_indented_output(result['out'].decode('utf-8').replace('<stdin>', patch_name))

# Reverse check to see if the patch has already been applied.
cmd = '%s apply -p0 --reverse --check' % git_exe
result = exec_cmd(cmd, patch_dir, patch_string)
if result['err'].find('error:') < 0:
if result['err'].decode('utf-8').find('error:') < 0:
sys.stdout.write('... already applied (skipping).\n')
return 'skip'

# Normal check to see if the patch can be applied cleanly.
cmd = '%s apply -p0 --check' % git_exe
result = exec_cmd(cmd, patch_dir, patch_string)
if result['err'].find('error:') >= 0:
if result['err'].decode('utf-8').find('error:') >= 0:
sys.stdout.write('... failed to apply:\n')
write_indented_output(result['err'].replace('<stdin>', patch_name))
return 'fail'
Expand All @@ -118,7 +118,7 @@ def git_apply_patch_file(patch_path, patch_dir):
# command succeeded.
cmd = '%s apply -p0' % git_exe
result = exec_cmd(cmd, patch_dir, patch_string)
if result['err'] == '':
if result['err'].decode('utf-8') == '':
sys.stdout.write('... successfully applied.\n')
else:
sys.stdout.write('... successfully applied (with warnings):\n')
Expand Down
2 changes: 1 addition & 1 deletion tools/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def apply_patch_config():

# Parse the configuration file.
scope = {}
execfile(config_file, scope)
exec(open(config_file).read(),scope)
patches = scope["patches"]

results = {'apply': 0, 'skip': 0, 'fail': 0}
Expand Down