From 05c1a3d1600c25a5592d5572b0fd30792066e7ee Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 3 May 2018 07:12:12 +0200 Subject: [PATCH] print() is a function in Python 3 --- .../core/src/opencl/runtime/generator/common.py | 107 +++++++++++---------- .../core/src/opencl/runtime/generator/parser_cl.py | 5 +- .../opencl/runtime/generator/parser_clamdblas.py | 5 +- .../opencl/runtime/generator/parser_clamdfft.py | 5 +- modules/dnn/misc/quantize_face_detector.py | 5 +- modules/java/check-tests.py | 5 +- modules/ts/misc/perf_tests_timing.py | 5 +- modules/ts/misc/table_formatter.py | 3 +- modules/ts/misc/testlog_parser.py | 15 +-- samples/dnn/fast_neural_style.py | 3 +- samples/dnn/mobilenet_ssd_accuracy.py | 5 +- .../imgProc/match_template/match_template.py | 7 +- 12 files changed, 91 insertions(+), 79 deletions(-) diff --git a/modules/core/src/opencl/runtime/generator/common.py b/modules/core/src/opencl/runtime/generator/common.py index 99b4e86..73fe6b0 100644 --- a/modules/core/src/opencl/runtime/generator/common.py +++ b/modules/core/src/opencl/runtime/generator/common.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys, os, re # @@ -84,7 +85,7 @@ def readFunctionFilter(fns, fileName): try: f = open(fileName, "r") except: - print "ERROR: Can't open filter file: %s" % fileName + print("ERROR: Can't open filter file: %s" % fileName) return 0 count = 0 @@ -133,8 +134,8 @@ def outputToString(f): @outputToString def generateFilterNames(fns): for fn in fns: - print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) - print '#total %d' % len(fns) + print('%s%s' % ('' if 'enabled' in fn else '//', fn['name'])) + print('#total %d' % len(fns)) callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))') @@ -145,100 +146,100 @@ def getTypeWithParam(t, p): @outputToString def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - commentStr = '' if fn.has_key('enabled') else '//' + commentStr = '' if 'enabled' in fn else '//' decl_args = [] for (i, t) in enumerate(fn['params']): decl_args.append(getTypeWithParam(t, 'p%d' % (i+1))) decl_args_str = '(' + (', '.join(decl_args)) + ')' - print '%s%s%d(%s_%s, %s, %s)' % \ + print('%s%s%d(%s_%s, %s, %s)' % \ (commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], \ - ' '.join(fn['ret']), decl_args_str) - print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \ + ' '.join(fn['ret']), decl_args_str)) + print(commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \ ((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), ' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ - commentStr, enumprefix, fn['name'])) - print commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])) - print + commentStr, enumprefix, fn['name']))) + print(commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name']))) + print() @outputToString def generateStaticDefinitions(fns): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - commentStr = '' if fn.has_key('enabled') else '//' + commentStr = '' if 'enabled' in fn else '//' decl_args = [] for (i, t) in enumerate(fn['params']): decl_args.append(getTypeWithParam(t, 'p%d' % (i+1))) decl_args_str = '(' + (', '.join(decl_args)) + ')' - print commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \ + print(commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \ ((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), ' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ - fn['name'])) + fn['name']))) @outputToString def generateListOfDefinitions(fns, name='opencl_fn_list'): - print '// generated by %s' % os.path.basename(sys.argv[0]) - print 'static const struct DynamicFnEntry* %s[] = {' % (name) + print('// generated by %s' % os.path.basename(sys.argv[0])) + print('static const struct DynamicFnEntry* %s[] = {' % (name)) for fn in fns: - commentStr = '' if fn.has_key('enabled') else '//' - if fn.has_key('enabled'): - print ' &%s_definition,' % (fn['name']) + commentStr = '' if 'enabled' in fn else '//' + if 'enabled' in fn: + print(' &%s_definition,' % (fn['name'])) else: - print ' NULL/*&%s_definition*/,' % (fn['name']) + print(' NULL/*&%s_definition*/,' % (fn['name'])) first = False - print '};' + print('};') @outputToString def generateEnums(fns, prefix='OPENCL_FN'): - print '// generated by %s' % os.path.basename(sys.argv[0]) - print 'enum %s_ID {' % prefix + print('// generated by %s' % os.path.basename(sys.argv[0])) + print('enum %s_ID {' % prefix) for (i, fn) in enumerate(fns): - commentStr = '' if fn.has_key('enabled') else '//' - print commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i)) - print '};' + commentStr = '' if 'enabled' in fn else '//' + print(commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i))) + print('};') @outputToString def generateRemapOrigin(fns): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - print '#define %s %s_' % (fn['name'], fn['name']) + print('#define %s %s_' % (fn['name'], fn['name'])) @outputToString def generateRemapDynamic(fns): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - print '#undef %s' % (fn['name']) - commentStr = '' if fn.has_key('enabled') else '//' - print commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name'])) + print('#undef %s' % (fn['name'])) + commentStr = '' if 'enabled' in fn else '//' + print(commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name']))) @outputToString def generateFnDeclaration(fns): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - commentStr = '' if fn.has_key('enabled') else '//' - print commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']), - fn['name'], ', '.join(fn['params'] if not fn.has_key('params_full') else fn['params_full']))) + commentStr = '' if 'enabled' in fn else '//' + print(commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']), + fn['name'], ', '.join(fn['params'] if 'params_full' not in fn else fn['params_full'])))) @outputToString def generateTemplates(total, lprefix, switch_name, calling_convention=''): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for sz in range(total): template_params = ['ID', '_R', 'decl_args'] params = ['p%d' % (i + 1) for i in range(0, sz)] - print '#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)) - print ' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention) - print ' static _R %s ID##_switch_fn decl_args \\' % (calling_convention) - print ' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)) - print '' + print('#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params))) + print(' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention)) + print(' static _R %s ID##_switch_fn decl_args \\' % (calling_convention)) + print(' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params))) + print('') @outputToString def generateInlineWrappers(fns): - print '// generated by %s' % os.path.basename(sys.argv[0]) + print('// generated by %s' % os.path.basename(sys.argv[0])) for fn in fns: - commentStr = '' if fn.has_key('enabled') else '//' - print '#undef %s' % (fn['name']) - print commentStr + ('#define %s %s_fn' % (fn['name'], fn['name'])) + commentStr = '' if 'enabled' in fn else '//' + print('#undef %s' % (fn['name'])) + print(commentStr + ('#define %s %s_fn' % (fn['name'], fn['name']))) params = [] call_params = [] for i in range(0, len(fn['params'])): @@ -251,23 +252,23 @@ def generateInlineWrappers(fns): call_params.append('p%d' % (i)) if len(fn['ret']) == 1 and fn['ret'][0] == 'void': - print commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \ - % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))) + print(commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \ + % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params)))) else: - print commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \ - % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))) + print(commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \ + % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params)))) def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\n//'): f = open(inputFile, "r") if noteLine: - print noteLine + print(noteLine) for line in f: if line.startswith('@'): assert line[-1] == '\n' line = line[:-1] # remove '\n' assert line[-1] == '@' name = line[1:-1] - assert ctx.has_key(name), name + assert name in ctx, name line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '') sys.stdout.write(line) f.close() diff --git a/modules/core/src/opencl/runtime/generator/parser_cl.py b/modules/core/src/opencl/runtime/generator/parser_cl.py index 9c55563..1f50504 100644 --- a/modules/core/src/opencl/runtime/generator/parser_cl.py +++ b/modules/core/src/opencl/runtime/generator/parser_cl.py @@ -2,6 +2,7 @@ # usage: # cat opencl11/cl.h | $0 cl_runtime_opencl11 # cat opencl12/cl.h | $0 cl_runtime_opencl12 +from __future__ import print_function import sys, re; from common import remove_comments, getTokens, getParameters, postProcessParameters @@ -77,7 +78,7 @@ while True: name = parts[i]; i += 1; fn['name'] = name - print 'name=' + name + print('name=' + name) params = getParameters(i, parts) @@ -88,7 +89,7 @@ while True: f.close() -print 'Found %d functions' % len(fns) +print('Found %d functions' % len(fns)) postProcessParameters(fns) diff --git a/modules/core/src/opencl/runtime/generator/parser_clamdblas.py b/modules/core/src/opencl/runtime/generator/parser_clamdblas.py index 2b473a9..0303517 100644 --- a/modules/core/src/opencl/runtime/generator/parser_clamdblas.py +++ b/modules/core/src/opencl/runtime/generator/parser_clamdblas.py @@ -1,6 +1,7 @@ #!/bin/python # usage: # cat clAmdBlas.h | $0 +from __future__ import print_function import sys, re; from common import remove_comments, getTokens, getParameters, postProcessParameters @@ -69,7 +70,7 @@ while True: name = parts[i]; i += 1; fn['name'] = name - print 'name=' + name + print('name=' + name) params = getParameters(i, parts) @@ -80,7 +81,7 @@ while True: f.close() -print 'Found %d functions' % len(fns) +print('Found %d functions' % len(fns)) postProcessParameters(fns) diff --git a/modules/core/src/opencl/runtime/generator/parser_clamdfft.py b/modules/core/src/opencl/runtime/generator/parser_clamdfft.py index accc20b..e0229f1 100644 --- a/modules/core/src/opencl/runtime/generator/parser_clamdfft.py +++ b/modules/core/src/opencl/runtime/generator/parser_clamdfft.py @@ -1,6 +1,7 @@ #!/bin/python # usage: # cat clAmdFft.h | $0 +from __future__ import print_function import sys, re; from common import remove_comments, getTokens, getParameters, postProcessParameters @@ -63,7 +64,7 @@ while True: name = parts[i]; i += 1; fn['name'] = name - print 'name=' + name + print('name=' + name) params = getParameters(i, parts) @@ -77,7 +78,7 @@ while True: f.close() -print 'Found %d functions' % len(fns) +print('Found %d functions' % len(fns)) postProcessParameters(fns) diff --git a/modules/dnn/misc/quantize_face_detector.py b/modules/dnn/misc/quantize_face_detector.py index a9348c2..833b8ba 100644 --- a/modules/dnn/misc/quantize_face_detector.py +++ b/modules/dnn/misc/quantize_face_detector.py @@ -1,3 +1,4 @@ +from __future__ import print_function import argparse import cv2 as cv import tensorflow as tf @@ -199,8 +200,8 @@ with tf.Session() as sess: outDNN = cvNet.forward(out_nodes) outTF = sess.run([mbox_loc, mbox_conf_flatten], feed_dict={inp: inputData.transpose(0, 2, 3, 1)}) - print 'Max diff @ locations: %e' % np.max(np.abs(outDNN[0] - outTF[0])) - print 'Max diff @ confidence: %e' % np.max(np.abs(outDNN[1] - outTF[1])) + print('Max diff @ locations: %e' % np.max(np.abs(outDNN[0] - outTF[0]))) + print('Max diff @ confidence: %e' % np.max(np.abs(outDNN[1] - outTF[1]))) # Save a graph graph_def = sess.graph.as_graph_def() diff --git a/modules/java/check-tests.py b/modules/java/check-tests.py index 275c5ad..29a9c31 100755 --- a/modules/java/check-tests.py +++ b/modules/java/check-tests.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import sys, os, re classes_ignore_list = ( @@ -148,9 +149,9 @@ class JavaParser: if __name__ == '__main__': if len(sys.argv) < 2: - print "Usage:\n", \ + print("Usage:\n", \ os.path.basename(sys.argv[0]), \ - " [ ...]\n", "Not tested methods are loggedto stdout." + " [ ...]\n", "Not tested methods are loggedto stdout.") exit(0) parser = JavaParser() for x in sys.argv[1:]: diff --git a/modules/ts/misc/perf_tests_timing.py b/modules/ts/misc/perf_tests_timing.py index dd44f1a..e3e94f4 100644 --- a/modules/ts/misc/perf_tests_timing.py +++ b/modules/ts/misc/perf_tests_timing.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import testlog_parser, sys, os, xml, glob, re from table_formatter import * from optparse import OptionParser @@ -154,6 +155,6 @@ if __name__ == "__main__": htmlPrintFooter(sys.stdout) else: if not options.failedOnly: - print '\nOverall time: %.2f min\n' % overall_time + print('\nOverall time: %.2f min\n' % overall_time) tbl.consolePrintTable(sys.stdout) - print 2 * '\n' + print(2 * '\n') diff --git a/modules/ts/misc/table_formatter.py b/modules/ts/misc/table_formatter.py index caa1e86..ebbbfc8 100755 --- a/modules/ts/misc/table_formatter.py +++ b/modules/ts/misc/table_formatter.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import sys, re, os.path, cgi, stat, math from optparse import OptionParser from color import getColorizer, dummyColorizer @@ -723,7 +724,7 @@ def formatValue(val, metric, units = None): if __name__ == "__main__": if len(sys.argv) < 2: - print "Usage:\n", os.path.basename(sys.argv[0]), ".xml" + print("Usage:\n", os.path.basename(sys.argv[0]), ".xml") exit(0) parser = OptionParser() diff --git a/modules/ts/misc/testlog_parser.py b/modules/ts/misc/testlog_parser.py index dc6a418..f3d8546 100755 --- a/modules/ts/misc/testlog_parser.py +++ b/modules/ts/misc/testlog_parser.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import collections import re import os.path @@ -108,7 +109,7 @@ class TestInfo(object): def dump(self, units="ms"): - print "%s ->\t\033[1;31m%s\033[0m = \t%.2f%s" % (str(self), self.status, self.get("gmean", units), units) + print("%s ->\t\033[1;31m%s\033[0m = \t%.2f%s" % (str(self), self.status, self.get("gmean", units), units)) def getName(self): @@ -198,22 +199,22 @@ def parseLogFile(filename): if __name__ == "__main__": if len(sys.argv) < 2: - print "Usage:\n", os.path.basename(sys.argv[0]), ".xml" + print("Usage:\n", os.path.basename(sys.argv[0]), ".xml") exit(0) for arg in sys.argv[1:]: - print "Processing {}...".format(arg) + print("Processing {}...".format(arg)) run = parseLogFile(arg) - print "Properties:" + print("Properties:") for (prop_name, prop_value) in run.properties.items(): - print "\t{} = {}".format(prop_name, prop_value) + print("\t{} = {}".format(prop_name, prop_value)) - print "Tests:" + print("Tests:") for t in sorted(run.tests): t.dump() - print + print() diff --git a/samples/dnn/fast_neural_style.py b/samples/dnn/fast_neural_style.py index 945b255..5aac8f3 100644 --- a/samples/dnn/fast_neural_style.py +++ b/samples/dnn/fast_neural_style.py @@ -1,3 +1,4 @@ +from __future__ import print_function import cv2 as cv import numpy as np import argparse @@ -43,7 +44,7 @@ while cv.waitKey(1) < 0: t, _ = net.getPerfProfile() freq = cv.getTickFrequency() / 1000 - print t / freq, 'ms' + print(t / freq, 'ms') if args.median_filter: out = cv.medianBlur(out, args.median_filter) diff --git a/samples/dnn/mobilenet_ssd_accuracy.py b/samples/dnn/mobilenet_ssd_accuracy.py index 3e53c0b..7c937dd 100644 --- a/samples/dnn/mobilenet_ssd_accuracy.py +++ b/samples/dnn/mobilenet_ssd_accuracy.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Script to evaluate MobileNet-SSD object detection model trained in TensorFlow # using both TensorFlow and OpenCV. Example: # @@ -115,14 +116,14 @@ pylab.rcParams['figure.figsize'] = (10.0, 8.0) annType = ['segm','bbox','keypoints'] annType = annType[1] #specify type here prefix = 'person_keypoints' if annType=='keypoints' else 'instances' -print 'Running demo for *%s* results.'%(annType) +print('Running demo for *%s* results.'%(annType)) #initialize COCO ground truth api cocoGt=COCO(args.annotations) #initialize COCO detections api for resFile in ['tf_result.json', 'cv_result.json']: - print resFile + print(resFile) cocoDt=cocoGt.loadRes(resFile) cocoEval = COCOeval(cocoGt,cocoDt,annType) diff --git a/samples/python/tutorial_code/imgProc/match_template/match_template.py b/samples/python/tutorial_code/imgProc/match_template/match_template.py index bd288d3..25c6e3b 100644 --- a/samples/python/tutorial_code/imgProc/match_template/match_template.py +++ b/samples/python/tutorial_code/imgProc/match_template/match_template.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import cv2 as cv @@ -16,8 +17,8 @@ max_Trackbar = 5 def main(argv): if (len(sys.argv) < 3): - print 'Not enough parameters' - print 'Usage:\nmatch_template_demo.py []' + print('Not enough parameters') + print('Usage:\nmatch_template_demo.py []') return -1 ## [load_image] @@ -33,7 +34,7 @@ def main(argv): mask = cv.imread( sys.argv[3], cv.IMREAD_COLOR ) if ((img is None) or (templ is None) or (use_mask and (mask is None))): - print 'Can\'t read one of the images' + print('Can\'t read one of the images') return -1 ## [load_image] -- 2.7.4