From 0249e408d3a254cdc83c0a7a9e0f8431421c85df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 3 Dec 2018 18:15:07 +0100 Subject: [PATCH] donate-cpu: Try to fix exception in hasInclude --- tools/donate-cpu.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index 5541290b0..711949f1b 100644 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -19,7 +19,6 @@ # Quick start: just run this script without any arguments import shutil -import glob import os import subprocess import sys @@ -190,17 +189,15 @@ def unpackPackage(workPath, tgz): os.chdir(workPath) -def hasInclude(path,inc): - for g in glob.glob(path + '/*'): - if os.path.isfile(g): - f = open(g,'rt') - filedata = f.read() +def hasInclude(path, inc): + for root, _, files in os.walk(path): + for name in files: + filename = os.path.join(root, name) + f = open(filename, 'rt') + filedata = f.read().decode(encoding='utf-8', errors='ignore') f.close() if filedata.find('\n#include ' + inc) >= 0: return True - elif os.path.isdir(g) and not g.startswith('.'): - if hasInclude(g, inc) is True: - return True return False