diff --git a/tools/exec_util.py b/tools/exec_util.py index ceabc5b090..554273693c 100644 --- a/tools/exec_util.py +++ b/tools/exec_util.py @@ -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 diff --git a/tools/file_util.py b/tools/file_util.py index a5fb76585c..469ca32541 100644 --- a/tools/file_util.py +++ b/tools/file_util.py @@ -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: @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tools/git_util.py b/tools/git_util.py index b6aa0fa977..bc293e41f5 100644 --- a/tools/git_util.py +++ b/tools/git_util.py @@ -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. @@ -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('', patch_name)) + write_indented_output(result['out'].decode('utf-8').replace('', 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('', patch_name)) return 'fail' @@ -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') diff --git a/tools/patcher.py b/tools/patcher.py index 4dcf6e567e..907697702e 100644 --- a/tools/patcher.py +++ b/tools/patcher.py @@ -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}