View | Details | Raw Unified | Return to bug 233776
Collapse All | Expand All

(-)b/Tools/scripts/patchtool.py (-12 / +18 lines)
Lines 23-31 Link Here
23
import os, os.path, subprocess, sys, getopt, glob, errno, types
23
import os, os.path, subprocess, sys, getopt, glob, errno, types
24
24
25
# Some global variables used as constants
25
# Some global variables used as constants
26
True = 1
26
#True = 1
27
False = 0
27
#False = 0
28
28
29
def isStr(obj):
30
    try:
31
        return isinstance(obj, basestring)
32
    except NameError:
33
        return isinstance(obj, str)
29
34
30
# Tweakable global variables. User is able to override any of these by setting
35
# Tweakable global variables. User is able to override any of these by setting
31
# appropriate environment variable prefixed by `PT_', eg:
36
# appropriate environment variable prefixed by `PT_', eg:
Lines 116-122 def locateportdir(path, wrkdirprefix= '', strict = False): Link Here
116
def querymakevar(varname, path = 'Makefile', strict = False, cache = {}):
121
def querymakevar(varname, path = 'Makefile', strict = False, cache = {}):
117
	path = os.path.abspath(path)
122
	path = os.path.abspath(path)
118
123
119
	if cache.has_key((varname, path)) == 1:
124
	if (varname, path) in cache:
120
		return cache[(varname, path)]
125
		return cache[(varname, path)]
121
126
122
	origpath = path
127
	origpath = path
Lines 134-140 def querymakevar(varname, path = 'Makefile', strict = False, cache = {}): Link Here
134
            stdout = subprocess.PIPE, stderr = devnull, close_fds = True)
139
            stdout = subprocess.PIPE, stderr = devnull, close_fds = True)
135
	retval = ''
140
	retval = ''
136
	for line in pipe.stdout.readlines():
141
	for line in pipe.stdout.readlines():
137
		retval = retval + line.strip() + ' '
142
		retval = retval + line.decode().strip() + ' '
138
	retval = retval[:-1]
143
	retval = retval[:-1]
139
	if strict == True and retval.strip() == '':
144
	if strict == True and retval.strip() == '':
140
		raise MakeVarError(path, varname)
145
		raise MakeVarError(path, varname)
Lines 200-206 def gendiff(path, wrksrc, outfile = ''): Link Here
200
	devnull = open('/dev/null', 'a')
205
	devnull = open('/dev/null', 'a')
201
	pipe = subprocess.Popen(cmdline, shell = True, stdin = subprocess.PIPE, \
206
	pipe = subprocess.Popen(cmdline, shell = True, stdin = subprocess.PIPE, \
202
            stdout = subprocess.PIPE, stderr = devnull, close_fds = True)
207
            stdout = subprocess.PIPE, stderr = devnull, close_fds = True)
203
	outbuf = pipe.stdout.readlines()
208
	outbuf = [x.decode() for x in pipe.stdout.readlines()]
204
	exitval = pipe.wait()
209
	exitval = pipe.wait()
205
	if exitval == 0:    # No differences were found
210
	if exitval == 0:    # No differences were found
206
		retval = False
211
		retval = False
Lines 241-247 def makepatchname(path, patchdir = ''): Link Here
241
# Write a specified message to stderr.
246
# Write a specified message to stderr.
242
#
247
#
243
def write_msg(message):
248
def write_msg(message):
244
	if type(message) == types.StringType:
249
	if isStr(message):
245
		message = message,
250
		message = message,
246
	sys.stderr.writelines(message)
251
	sys.stderr.writelines(message)
247
252
Lines 267-273 def query_yn(message, default = False): Link Here
267
			return False
272
			return False
268
		elif reply == '' and default in (True, False):
273
		elif reply == '' and default in (True, False):
269
			return default
274
			return default
270
		print 'Wrong answer "%s", please try again' % reply
275
		print('Wrong answer "%s", please try again' % reply)
271
	return default
276
	return default
272
277
273
278
Lines 443-449 class PatchesCollection: Link Here
443
448
444
	def addpatchfile(self, path, wrksrc):
449
	def addpatchfile(self, path, wrksrc):
445
		path = os.path.abspath(path)
450
		path = os.path.abspath(path)
446
		if not self.patches.has_key(path):
451
		if path not in self.patches:
447
			self.addpatchobj(Patch(path, wrksrc))
452
			self.addpatchobj(Patch(path, wrksrc))
448
453
449
	def addpatchobj(self, patchobj):
454
	def addpatchobj(self, patchobj):
Lines 451-457 class PatchesCollection: Link Here
451
456
452
	def lookupbyname(self, path):
457
	def lookupbyname(self, path):
453
		path = os.path.abspath(path)
458
		path = os.path.abspath(path)
454
		if self.patches.has_key(path):
459
		if path in self.patches:
455
			return self.patches[path]
460
			return self.patches[path]
456
		return None
461
		return None
457
462
Lines 494-500 def truepath(path): Link Here
494
def main():
499
def main():
495
	try:
500
	try:
496
		opts, args = getopt.getopt(sys.argv[1:], 'afui')
501
		opts, args = getopt.getopt(sys.argv[1:], 'afui')
497
	except getopt.GetoptError, msg:
502
	except getopt.GetoptError as msg:
498
		usage(2, msg)
503
		usage(2, msg)
499
504
500
	automatic = False
505
	automatic = False
Lines 678-685 def update(args, automatic, force, ignoremtime): Link Here
678
if __name__ == '__main__':
683
if __name__ == '__main__':
679
	try:
684
	try:
680
		main()
685
		main()
681
	except (PatchError, ECmdError, MakeVarError, LocatePDirError), msg:
686
	except (PatchError, ECmdError, MakeVarError, LocatePDirError) as msg:
682
		sys.exit('ERROR: ' + str(msg))
687
		sys.exit('ERROR: ' + str(msg))
683
	except IOError, (code, msg):
688
	except IOError as ex:
689
		code, msg = ex
684
		sys.exit('ERROR: %s: %s' % (str(msg), os.strerror(code)))
690
		sys.exit('ERROR: %s: %s' % (str(msg), os.strerror(code)))
685
691

Return to bug 233776