chore: make apply_all_patches.py work in both python2 and python3 (#19872)

This commit is contained in:
Charles Kerr 2019-08-23 17:48:27 -05:00 committed by Samuel Attard
parent 81e9dab52f
commit ef6d4a46c2
3 changed files with 4 additions and 3 deletions

View file

@ -11,7 +11,7 @@ from lib.patches import patch_from_dir
def apply_patches(dirs):
threeway = os.environ.get("ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES")
for patch_dir, repo in dirs.iteritems():
for patch_dir, repo in dirs.items():
git.import_patches(repo=repo, patch_data=patch_from_dir(patch_dir),
threeway=threeway is not None,
committer_name="Electron Scripts", committer_email="scripts@electron")

View file

@ -61,7 +61,7 @@ def am(repo, patch_data, threeway=False, directory=None, exclude=None,
proc = subprocess.Popen(
command,
stdin=subprocess.PIPE)
proc.communicate(patch_data)
proc.communicate(patch_data.encode('utf-8'))
if proc.returncode != 0:
raise RuntimeError("Command {} returned {}".format(command,
proc.returncode))

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
import codecs
import os
@ -7,7 +8,7 @@ def read_patch(patch_dir, patch_filename):
"""Read a patch from |patch_dir/filename| and amend the commit message with
metadata about the patch file it came from."""
ret = []
with open(os.path.join(patch_dir, patch_filename)) as f:
with codecs.open(os.path.join(patch_dir, patch_filename), encoding='utf-8') as f:
for l in f.readlines():
if l.startswith('diff -'):
ret.append('Patch-Filename: {}\n'.format(patch_filename))