From 50fcd9d1b9a20d49bc873467a82a071f2f2f8b5a Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 29 Jun 2016 15:12:03 +1200 Subject: recipetool: create: avoid decoding errors with Python 3 We're opening source files with the default encoding (utf-8) but we can't necessarily be sure that they are UTF-8 clean - for example, recipetool create ftp://mama.indstate.edu/linux/tree/tree-1.7.0.tgz prior to this patch resulted in a UnicodeDecodeError. Use the "surrogateescape" mode to avoid this. Fixes [YOCTO #9822]. Signed-off-by: Paul Eggleton Signed-off-by: Ross Burton --- scripts/lib/recipetool/create.py | 6 +++--- scripts/lib/recipetool/create_buildsys.py | 14 +++++++------- scripts/lib/recipetool/create_kernel.py | 2 +- scripts/lib/recipetool/create_kmod.py | 4 ++-- scripts/lib/recipetool/create_npm.py | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 129742807f..042e7009cb 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py @@ -390,7 +390,7 @@ def create_recipe(args): srcsubdir = dirlist[0] srctree = os.path.join(srctree, srcsubdir) else: - with open(singleitem, 'r') as f: + with open(singleitem, 'r', errors='surrogateescape') as f: if ' 10: break diff --git a/scripts/lib/recipetool/create_kmod.py b/scripts/lib/recipetool/create_kmod.py index fe39edb288..7cf188db21 100644 --- a/scripts/lib/recipetool/create_kmod.py +++ b/scripts/lib/recipetool/create_kmod.py @@ -53,7 +53,7 @@ class KernelModuleRecipeHandler(RecipeHandler): break else: continue - with open(cfile, 'r') as f: + with open(cfile, 'r', errors='surrogateescape') as f: for line in f: if module_inc_re.match(line.strip()): is_module = True @@ -73,7 +73,7 @@ class KernelModuleRecipeHandler(RecipeHandler): in_install = False in_compile = False install_target = None - with open(makefile, 'r') as f: + with open(makefile, 'r', errors='surrogateescape') as f: for line in f: if line.startswith('install:'): if not install_lines: diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py index fcc0172af8..e5aaa60bf8 100644 --- a/scripts/lib/recipetool/create_npm.py +++ b/scripts/lib/recipetool/create_npm.py @@ -92,7 +92,7 @@ class NpmRecipeHandler(RecipeHandler): return False def read_package_json(fn): - with open(fn, 'r') as f: + with open(fn, 'r', errors='surrogateescape') as f: return json.loads(f.read()) files = RecipeHandler.checkfiles(srctree, ['package.json']) -- cgit 1.2.3-korg