Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3894808imm; Tue, 17 Jul 2018 12:07:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf5rbv9GNPTHw5ifdR4huhM26d/pM93XTiy6lz7Vvikmq50ZAo2Zs/Ep3JmIMOun8YcvZLJ X-Received: by 2002:aa7:88d3:: with SMTP id p19-v6mr1941919pfo.160.1531854479331; Tue, 17 Jul 2018 12:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531854479; cv=none; d=google.com; s=arc-20160816; b=JUwk3UbxpOeYusMAKrzSEGfVxNuYuntP6RQ2hjkEA/h4fFskmltwqtOlhC0bJBBC1h rdQfniRuQZYgq3CMFL+R58/VCCDYfu470b20NE+8CwtpwfYXQGjeseHAqzaxUzRLy/0V w6yDiB2hcpnC0Kiq3uj9gzDx1Fhr9hIhQf4mMfrIMZKkvJ7MlOpds4Zwo/gx95WbJx8W Rg1451Pyc9Wbx88gJ8kP1zkdzNQaMmPvVJ7WA2wrbvrmwMIHJGi77rQtSSyrHD3Pv1wu h9qwePRd0I8ZXNjWl0a8RXiYkd7W2wdSTc4xhRqMUMUoG/Jw89WXlsJBflOm8keBbFSt VpFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LbCNtMp3ZsfgI8UnlAz44oYqZ/1Nmg9HG+G+ZrVYfUc=; b=mo5t0P6kULF7SXYY8Y079tCfZTk0o28Amstrs7DPG0zBONdRVvHbY+Ay2wmeXXhAF6 9uv4awYTVAQC1frGS5UwtrO4o0VWfLj/aen1COYlO6OzKhF48xUSK7IEUvM/Z2YQHJUx q0QOrkvUay5Git9q4/Wwa2T8LOe14CWCgAExFYIIkUwmXzlO2VEL1V9Nj5ydG5s6yOBx C0ouD4DPMjmlinJQUSgSHXNccSlji5GM0yLUB790A7VgCg93adQ0EWVSgb451L0bXOhl EGNYF4tefk6iOD1ZOT8LE7JJKNiJ55l6sc2H8IBmsyWwrfwzLn8F48jB5vFYeaeJIus4 W4KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5-v6si1451570pls.372.2018.07.17.12.07.44; Tue, 17 Jul 2018 12:07:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729989AbeGQTlK (ORCPT + 99 others); Tue, 17 Jul 2018 15:41:10 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36366 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729755AbeGQTlK (ORCPT ); Tue, 17 Jul 2018 15:41:10 -0400 Received: by mail-qk0-f194.google.com with SMTP id a132-v6so1113058qkg.3 for ; Tue, 17 Jul 2018 12:07:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LbCNtMp3ZsfgI8UnlAz44oYqZ/1Nmg9HG+G+ZrVYfUc=; b=oUu3efYWOZxWQfUiBN5RJgigWCeabkUoVVESGDJWKiOQqaoczF6ylmwKxCHOGhHs/X g9iB6Yix28HxAwidwvoTx4dHoIcGXVU8hpYGLCtfzgQVvco/l/Xel9JWZQPDzB3Sut26 S1zrE26S9907Qe8nvdYPtLXuIuyzg/jDzpOtq2B8I+ZK7xRrPcKWiH4gQEm+EScgcAn9 vMqLDFtuTxv7QTLqHmTpMuhehFH2DsBdfA9Do8jv7EifkZ51zwcEP/SJNTBaPm+70uUa 9LBtpLCB4Q/88/enx7EZC17knFMHBGhMeJ9XraQ5WcWU7Y6h6VG/Xdt2ZE/5pjImiWoC GVxw== X-Gm-Message-State: AOUpUlGvatxDdjZVzffn2RdmuimdusI52NZ8xtwgnZc2pj8jvRrKeBEp o/ZiFv+Ruf5r2AysHey9IkBK+Q== X-Received: by 2002:a37:1741:: with SMTP id i62-v6mr2674011qkh.147.1531854430186; Tue, 17 Jul 2018 12:07:10 -0700 (PDT) Received: from laptop.jcline.org.com (nat-pool-rdu-t.redhat.com. [66.187.233.202]) by smtp.gmail.com with ESMTPSA id u8-v6sm1581080qtc.76.2018.07.17.12.07.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jul 2018 12:07:09 -0700 (PDT) From: Jeremy Cline To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH] scripts: Add Python 3 compatibility to spdxcheck.py Date: Tue, 17 Jul 2018 15:06:35 -0400 Message-Id: <20180717190635.29467-1-jcline@redhat.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "dict.has_key(key)" on dictionaries has been replaced with "key in dict". Additionally, when run under Python 3 some files don't decode with the default encoding (tested with UTF-8). To handle that, don't open the file in text mode and decode text line-by-line, ignoring encoding errors. This remains compatible with Python 2 and should have no functional change. Signed-off-by: Jeremy Cline --- scripts/spdxcheck.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py index a6041f29b18e..839e190bbd7a 100755 --- a/scripts/spdxcheck.py +++ b/scripts/spdxcheck.py @@ -4,6 +4,7 @@ from argparse import ArgumentParser from ply import lex, yacc +import locale import traceback import sys import git @@ -102,7 +103,7 @@ class id_parser(object): raise ParserException(tok, 'Invalid License ID') self.lastid = id elif tok.type == 'EXC': - if not self.spdx.exceptions.has_key(id): + if id not in self.spdx.exceptions: raise ParserException(tok, 'Invalid Exception ID') if self.lastid not in self.spdx.exceptions[id]: raise ParserException(tok, 'Exception not valid for license %s' %self.lastid) @@ -167,6 +168,7 @@ class id_parser(object): self.curline = 0 try: for line in fd: + line = line.decode(locale.getpreferredencoding(False), errors='ignore') self.curline += 1 if self.curline > maxlines: break @@ -201,7 +203,8 @@ def scan_git_tree(tree): continue if not os.path.isfile(el.path): continue - parser.parse_lines(open(el.path), args.maxlines, el.path) + with open(el.path, 'rb') as fd: + parser.parse_lines(fd, args.maxlines, el.path) def scan_git_subtree(tree, path): for p in path.strip('/').split('/'): -- 2.17.1