From owner-svn-ports-all@freebsd.org Tue Jan 29 14:44:13 2019 Return-Path: Delivered-To: svn-ports-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5D55E14BFA0A; Tue, 29 Jan 2019 14:44:13 +0000 (UTC) (envelope-from tobik@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0344D895AE; Tue, 29 Jan 2019 14:44:13 +0000 (UTC) (envelope-from tobik@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E714791C3; Tue, 29 Jan 2019 14:44:12 +0000 (UTC) (envelope-from tobik@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x0TEiCpB016073; Tue, 29 Jan 2019 14:44:12 GMT (envelope-from tobik@FreeBSD.org) Received: (from tobik@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x0TEiC1P016072; Tue, 29 Jan 2019 14:44:12 GMT (envelope-from tobik@FreeBSD.org) Message-Id: <201901291444.x0TEiC1P016072@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tobik set sender to tobik@FreeBSD.org using -f From: Tobias Kortkamp Date: Tue, 29 Jan 2019 14:44:12 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r491566 - head/Tools/scripts X-SVN-Group: ports-head X-SVN-Commit-Author: tobik X-SVN-Commit-Paths: head/Tools/scripts X-SVN-Commit-Revision: 491566 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0344D895AE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.95)[-0.954,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2019 14:44:13 -0000 Author: tobik Date: Tue Jan 29 14:44:12 2019 New Revision: 491566 URL: https://svnweb.freebsd.org/changeset/ports/491566 Log: Make Tools/scripts/patchtool.py compatible with Python 3.x PR: 233776 Submitted by: sobomax Modified: head/Tools/scripts/patchtool.py Modified: head/Tools/scripts/patchtool.py ============================================================================== --- head/Tools/scripts/patchtool.py Tue Jan 29 14:21:29 2019 (r491565) +++ head/Tools/scripts/patchtool.py Tue Jan 29 14:44:12 2019 (r491566) @@ -23,9 +23,14 @@ import os, os.path, subprocess, sys, getopt, glob, errno, types # Some global variables used as constants -True = 1 -False = 0 +#True = 1 +#False = 0 +def isStr(obj): + try: + return isinstance(obj, basestring) + except NameError: + return isinstance(obj, str) # Tweakable global variables. User is able to override any of these by setting # appropriate environment variable prefixed by `PT_', eg: @@ -116,7 +121,7 @@ def locateportdir(path, wrkdirprefix= '', strict = Fal def querymakevar(varname, path = 'Makefile', strict = False, cache = {}): path = os.path.abspath(path) - if cache.has_key((varname, path)) == 1: + if (varname, path) in cache: return cache[(varname, path)] origpath = path @@ -134,7 +139,7 @@ def querymakevar(varname, path = 'Makefile', strict = stdout = subprocess.PIPE, stderr = devnull, close_fds = True) retval = '' for line in pipe.stdout.readlines(): - retval = retval + line.strip() + ' ' + retval = retval + line.decode().strip() + ' ' retval = retval[:-1] if strict == True and retval.strip() == '': raise MakeVarError(path, varname) @@ -200,7 +205,7 @@ def gendiff(path, wrksrc, outfile = ''): devnull = open('/dev/null', 'a') pipe = subprocess.Popen(cmdline, shell = True, stdin = subprocess.PIPE, \ stdout = subprocess.PIPE, stderr = devnull, close_fds = True) - outbuf = pipe.stdout.readlines() + outbuf = [x.decode() for x in pipe.stdout.readlines()] exitval = pipe.wait() if exitval == 0: # No differences were found retval = False @@ -241,7 +246,7 @@ def makepatchname(path, patchdir = ''): # Write a specified message to stderr. # def write_msg(message): - if type(message) == types.StringType: + if isStr(message): message = message, sys.stderr.writelines(message) @@ -267,7 +272,7 @@ def query_yn(message, default = False): return False elif reply == '' and default in (True, False): return default - print 'Wrong answer "%s", please try again' % reply + print('Wrong answer "%s", please try again' % reply) return default @@ -443,7 +448,7 @@ class PatchesCollection: def addpatchfile(self, path, wrksrc): path = os.path.abspath(path) - if not self.patches.has_key(path): + if path not in self.patches: self.addpatchobj(Patch(path, wrksrc)) def addpatchobj(self, patchobj): @@ -451,7 +456,7 @@ class PatchesCollection: def lookupbyname(self, path): path = os.path.abspath(path) - if self.patches.has_key(path): + if path in self.patches: return self.patches[path] return None @@ -494,7 +499,7 @@ def truepath(path): def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'afui') - except getopt.GetoptError, msg: + except getopt.GetoptError as msg: usage(2, msg) automatic = False @@ -678,8 +683,9 @@ def update(args, automatic, force, ignoremtime): if __name__ == '__main__': try: main() - except (PatchError, ECmdError, MakeVarError, LocatePDirError), msg: + except (PatchError, ECmdError, MakeVarError, LocatePDirError) as msg: sys.exit('ERROR: ' + str(msg)) - except IOError, (code, msg): + except IOError as ex: + code, msg = ex sys.exit('ERROR: %s: %s' % (str(msg), os.strerror(code)))