--- tools/clang-format/clang-format-diff.py | 4 +-- tools/clang-format/clang-format.py | 6 ++--- tools/clang-format/git-clang-format | 42 ++++++++++++++++-------------- tools/scan-build/bin/set-xcode-analyzer | 24 ++++++++--------- tools/scan-view/bin/scan-view | 11 ++++---- tools/scan-view/share/Reporter.py | 6 ++--- tools/scan-view/share/ScanView.py | 46 ++++++++++++++++----------------- tools/scan-view/share/startfile.py | 2 +- 8 files changed, 72 insertions(+), 69 deletions(-)
diff --git a/tools/clang-format/clang-format-diff.py b/tools/clang-format/clang-format-diff.py index 5e728f5..8bf5ce0 100755 --- a/tools/clang-format/clang-format-diff.py +++ b/tools/clang-format/clang-format-diff.py @@ -89,9 +89,9 @@ def main(): ['-lines', str(start_line) + ':' + str(end_line)]) # Reformat files containing changes in place. - for filename, lines in lines_by_file.iteritems(): + for filename, lines in lines_by_file.items(): if args.i and args.verbose: - print 'Formatting', filename + print('Formatting %s' % filename) command = [args.binary, filename] if args.i: command.append('-i') diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py index 5cb41fc..68a6a32 100644 --- a/tools/clang-format/clang-format.py +++ b/tools/clang-format/clang-format.py @@ -61,7 +61,7 @@ def main(): # Determine the cursor position. cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2 if cursor < 0: - print 'Couldn\'t determine cursor position. Is your file empty?' + print('Couldn\'t determine cursor position. Is your file empty?') return # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format. @@ -86,7 +86,7 @@ def main(): # If successful, replace buffer contents. if stderr: - print stderr + print(stderr) if not stdout: print ('No output from clang-format (crashed?).\n' + @@ -100,7 +100,7 @@ def main(): if op[0] is not 'equal': vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]] if output.get('IncompleteFormat'): - print 'clang-format: incomplete (syntax errors)' + print('clang-format: incomplete (syntax errors)') vim.command('goto %d' % (output['Cursor'] + 1)) main() diff --git a/tools/clang-format/git-clang-format b/tools/clang-format/git-clang-format index 0c45762..99a6fe6 100755 --- a/tools/clang-format/git-clang-format +++ b/tools/clang-format/git-clang-format @@ -23,6 +23,8 @@ git clang-format -h Requires Python 2.7 """ +from __future__ import print_function + import argparse import collections import contextlib @@ -128,15 +130,15 @@ def main(): if opts.verbose >= 1: ignored_files.difference_update(changed_lines) if ignored_files: - print 'Ignoring changes in the following files (wrong extension):' + print('Ignoring changes in the following files (wrong extension):') for filename in ignored_files: - print ' ', filename + print(' ', filename) if changed_lines: - print 'Running clang-format on the following files:' + print('Running clang-format on the following files:') for filename in changed_lines: - print ' ', filename + print(' ', filename) if not changed_lines: - print 'no modified files to format' + print('no modified files to format') return # The computed diff outputs absolute paths, so we must cd before accessing # those files. @@ -146,20 +148,20 @@ def main(): binary=opts.binary, style=opts.style) if opts.verbose >= 1: - print 'old tree:', old_tree - print 'new tree:', new_tree + print('old tree:', old_tree) + print('new tree:', new_tree) if old_tree == new_tree: if opts.verbose >= 0: - print 'clang-format did not modify any files' + print('clang-format did not modify any files') elif opts.diff: print_diff(old_tree, new_tree) else: changed_files = apply_changes(old_tree, new_tree, force=opts.force, patch_mode=opts.patch) if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1: - print 'changed files:' + print('changed files:') for filename in changed_files: - print ' ', filename + print(' ', filename) def load_git_config(non_string_options=None): @@ -323,7 +325,7 @@ def run_clang_format_and_save_to_tree(changed_lines, binary='clang-format', Returns the object ID (SHA-1) of the created tree.""" def index_info_generator(): - for filename, line_ranges in changed_lines.iteritems(): + for filename, line_ranges in changed_lines.items(): mode = oct(os.stat(filename).st_mode) blob_id = clang_format_to_blob(filename, line_ranges, binary=binary, style=style) @@ -431,10 +433,10 @@ def apply_changes(old_tree, new_tree, force=False, patch_mode=False): if not force: unstaged_files = run('git', 'diff-files', '--name-status', *changed_files) if unstaged_files: - print >>sys.stderr, ('The following files would be modified but ' - 'have unstaged changes:') - print >>sys.stderr, unstaged_files - print >>sys.stderr, 'Please commit, stage, or stash them first.' + print('The following files would be modified but have unstaged changes:', + file=sys.stderr) + print(unstaged_files, file=sys.stderr) + print('Please commit, stage, or stash them first.', file=sys.stderr) sys.exit(2) if patch_mode: # In patch mode, we could just as well create an index from the new tree @@ -464,20 +466,20 @@ def run(*args, **kwargs): if p.returncode == 0: if stderr: if verbose: - print >>sys.stderr, '`%s` printed to stderr:' % ' '.join(args) - print >>sys.stderr, stderr.rstrip() + print('`%s` printed to stderr:' % ' '.join(args), file=sys.stderr) + print(stderr.rstrip(), file=sys.stderr) if strip: stdout = stdout.rstrip('\r\n') return stdout if verbose: - print >>sys.stderr, '`%s` returned %s' % (' '.join(args), p.returncode) + print('`%s` returned %s' % (' '.join(args), p.returncode), file=sys.stderr) if stderr: - print >>sys.stderr, stderr.rstrip() + print(stderr.rstrip(), file=sys.stderr) sys.exit(2) def die(message): - print >>sys.stderr, 'error:', message + print('error:', message, file=sys.stderr) sys.exit(2) diff --git a/tools/scan-build/bin/set-xcode-analyzer b/tools/scan-build/bin/set-xcode-analyzer index 8e67482..444af63 100755 --- a/tools/scan-build/bin/set-xcode-analyzer +++ b/tools/scan-build/bin/set-xcode-analyzer @@ -6,7 +6,7 @@ import sys if sys.version_info < (2, 7): - print "set-xcode-analyzer requires Python 2.7 or later" + print("set-xcode-analyzer requires Python 2.7 or later") sys.exit(1) import os @@ -18,7 +18,7 @@ import stat from AppKit import * def FindClangSpecs(path): - print "(+) Searching for xcspec file in: ", path + print("(+) Searching for xcspec file in: %s" % path) for root, dirs, files in os.walk(path): for f in files: if f.endswith(".xcspec") and f.startswith("Clang LLVM"): @@ -49,14 +49,14 @@ def ModifySpec(path, isBuiltinAnalyzer, pathToChecker): foundAnalyzer = False t.write(line) t.close() - print "(+) processing:", path + print("(+) processing: %s" % path) try: shutil.copy(t.name, path) os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) - except IOError, why: - print " (-) Cannot update file:", why, "\n" - except OSError, why: - print " (-) Cannot update file:", why, "\n" + except IOError as why: + print(" (-) Cannot update file: %s\n" % why) + except OSError as why: + print(" (-) Cannot update file: %s\n" % why) os.unlink(t.name) def main(): @@ -75,7 +75,7 @@ def main(): # determine if Xcode is running for x in NSWorkspace.sharedWorkspace().runningApplications(): if x.localizedName().find("Xcode") >= 0: - print "(-) You must quit Xcode first before modifying its configuration files." + print("(-) You must quit Xcode first before modifying its configuration files.") sys.exit(1) isBuiltinAnalyzer = False @@ -83,12 +83,12 @@ def main(): # Expand tildes. path = os.path.expanduser(options.path) if not path.endswith("clang"): - print "(+) Using Clang bundled with checker build:", path + print("(+) Using Clang bundled with checker build: %s" % path) path = os.path.join(path, "bin", "clang"); else: - print "(+) Using Clang located at:", path + print("(+) Using Clang located at: %s" % path) else: - print "(+) Using the Clang bundled with Xcode" + print("(+) Using the Clang bundled with Xcode") path = options.default isBuiltinAnalyzer = True @@ -108,7 +108,7 @@ def main(): ModifySpec(x, isBuiltinAnalyzer, path) if foundSpec == False: - print "(-) No compiler configuration file was found. Xcode's analyzer has not been updated." + print("(-) No compiler configuration file was found. Xcode's analyzer has not been updated.") if __name__ == '__main__': main() diff --git a/tools/scan-view/bin/scan-view b/tools/scan-view/bin/scan-view index 1b6e8ba..b05925d 100755 --- a/tools/scan-view/bin/scan-view +++ b/tools/scan-view/bin/scan-view @@ -3,6 +3,8 @@ """The clang static analyzer results viewer. """ +from __future__ import print_function + import sys import imp import os @@ -52,10 +54,10 @@ def start_browser(port, options): sys.stderr.flush() time.sleep(kSleepTimeout) else: - print >> sys.stderr, 'WARNING: Unable to detect that server started.' + print('WARNING: Unable to detect that server started.', file=sys.stderr) if options.debug: - print >> sys.stderr, '%s: Starting webbrowser...' % sys.argv[0] + print('%s: Starting webbrowser...' % sys.argv[0], file=sys.stderr) webbrowser.open(url) @@ -69,9 +71,8 @@ def run(port, options, root): import ScanView try: - print 'Starting scan-view at: http://%s:%d' % (options.host, - port) - print ' Use Ctrl-C to exit.' + print('Starting scan-view at: http://%s:%d' % (options.host, port)) + print(' Use Ctrl-C to exit.') httpd = ScanView.create_server((options.host, port), options, root) httpd.serve_forever() diff --git a/tools/scan-view/share/Reporter.py b/tools/scan-view/share/Reporter.py index 294e05b..ff9ac02 100644 --- a/tools/scan-view/share/Reporter.py +++ b/tools/scan-view/share/Reporter.py @@ -77,7 +77,7 @@ class EmailReporter: return 'Email' def getParameters(self): - return map(lambda x:TextParameter(x),['To', 'From', 'SMTP Server', 'SMTP Port']) + return [TextParameter(x) for x in ['To', 'From', 'SMTP Server', 'SMTP Port']] # Lifted from python email module examples. def attachFile(self, outer, path): @@ -145,7 +145,7 @@ class BugzillaReporter: return 'Bugzilla' def getParameters(self): - return map(lambda x:TextParameter(x),['URL','Product']) + return [TextParameter(x) for x in ['URL', 'Product']] def fileReport(self, report, parameters): raise NotImplementedError @@ -208,7 +208,7 @@ class RadarReporter: script = os.path.join(os.path.dirname(__file__),'../share/scan-view/FileRadar.scpt') args = ['osascript', script, component, componentVersion, classification, personID, report.title, - report.description, diagnosis, config] + map(os.path.abspath, report.files) + report.description, diagnosis, config] + list(map(os.path.abspath, report.files)) # print >>sys.stderr, args try: p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/tools/scan-view/share/ScanView.py b/tools/scan-view/share/ScanView.py index 7dc0351..c2c9322 100644 --- a/tools/scan-view/share/ScanView.py +++ b/tools/scan-view/share/ScanView.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import BaseHTTPServer import SimpleHTTPServer import os @@ -96,20 +98,20 @@ class ReporterThread(threading.Thread): result = None try: if self.server.options.debug: - print >>sys.stderr, "%s: SERVER: submitting bug."%(sys.argv[0],) + print("%s: SERVER: submitting bug." % (sys.argv[0],), file=sys.stderr) self.status = self.reporter.fileReport(self.report, self.parameters) self.success = True time.sleep(3) if self.server.options.debug: - print >>sys.stderr, "%s: SERVER: submission complete."%(sys.argv[0],) - except Reporter.ReportFailure,e: + print("%s: SERVER: submission complete." % (sys.argv[0],), file=sys.stderr) + except Reporter.ReportFailure as e: self.status = e.value - except Exception,e: + except Exception as e: s = StringIO.StringIO() import traceback - print >>s,'<b>Unhandled Exception</b><br><pre>' + print('<b>Unhandled Exception</b><br><pre>', file=s) traceback.print_exc(e,file=s) - print >>s,'</pre>' + print('</pre>', file=s) self.status = s.getvalue() class ScanViewServer(BaseHTTPServer.HTTPServer): @@ -155,16 +157,16 @@ class ScanViewServer(BaseHTTPServer.HTTPServer): def halt(self): self.halted = True if self.options.debug: - print >>sys.stderr, "%s: SERVER: halting." % (sys.argv[0],) + print("%s: SERVER: halting." % (sys.argv[0],), file=sys.stderr) def serve_forever(self): while not self.halted: if self.options.debug > 1: - print >>sys.stderr, "%s: SERVER: waiting..." % (sys.argv[0],) + print("%s: SERVER: waiting..." % (sys.argv[0],), file=sys.stderr) try: self.handle_request() - except OSError,e: - print 'OSError',e.errno + except OSError as e: + print('OSError', e.errno) def finish_request(self, request, client_address): if self.options.autoReload: @@ -177,7 +179,7 @@ class ScanViewServer(BaseHTTPServer.HTTPServer): info = sys.exc_info() if info and isinstance(info[1], socket.error): if self.options.debug > 1: - print >>sys.stderr, "%s: SERVER: ignored socket error." % (sys.argv[0],) + print("%s: SERVER: ignored socket error." % (sys.argv[0],), file=sys.stderr) return BaseHTTPServer.HTTPServer.handle_error(self, request, client_address) @@ -207,13 +209,13 @@ class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_HEAD(self): try: SimpleHTTPServer.SimpleHTTPRequestHandler.do_HEAD(self) - except Exception,e: + except Exception as e: self.handle_exception(e) def do_GET(self): try: SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) - except Exception,e: + except Exception as e: self.handle_exception(e) def do_POST(self): @@ -230,7 +232,7 @@ class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): if f: self.copyfile(f, self.wfile) f.close() - except Exception,e: + except Exception as e: self.handle_exception(e) def log_message(self, format, *args): @@ -264,7 +266,7 @@ class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def handle_exception(self, exc): import traceback s = StringIO.StringIO() - print >>s, "INTERNAL ERROR\n" + print("INTERNAL ERROR\n", file=s) traceback.print_exc(exc, s) f = self.send_string(s.getvalue(), 'text/plain') if f: @@ -410,8 +412,7 @@ Submit</h3> import startfile if self.server.options.debug: - print >>sys.stderr, '%s: SERVER: opening "%s"'%(sys.argv[0], - file) + print('%s: SERVER: opening "%s"' % (sys.argv[0], file), file=sys.stderr) status = startfile.open(file) if status: @@ -428,7 +429,7 @@ Submit</h3> data = self.load_crashes() # Don't allow empty reports. if not data: - raise ValueError, 'No crashes detected!' + raise ValueError('No crashes detected!') c = Context() c.title = 'clang static analyzer failures' @@ -472,7 +473,7 @@ STDERR Summary # Check that this is a valid report. path = posixpath.join(self.server.root, 'report-%s.html' % report) if not posixpath.exists(path): - raise ValueError, 'Invalid report ID' + raise ValueError('Invalid report ID') keys = self.load_report(report) c = Context() c.title = keys.get('DESC','clang error (unrecognized') @@ -501,7 +502,7 @@ Line: %s # report is None is used for crashes try: c = self.get_report_context(report) - except ValueError, e: + except ValueError as e: return self.send_error(400, e.message) title = c.title @@ -544,7 +545,7 @@ Line: %s """%(r.getName(),display,r.getName(),options)) reporterSelections = '\n'.join(reporterSelections) reporterOptionsDivs = '\n'.join(reporterOptions) - reportersArray = '[%s]'%(','.join([`r.getName()` for r in self.server.reporters])) + reportersArray = '[%s]'%(','.join([repr(r.getName()) for r in self.server.reporters])) if c.files: fieldSize = min(5, len(c.files)) @@ -690,8 +691,7 @@ File Bug</h3> path = posixpath.join(self.server.root, relpath) if self.server.options.debug > 1: - print >>sys.stderr, '%s: SERVER: sending path "%s"'%(sys.argv[0], - path) + print('%s: SERVER: sending path "%s"' % (sys.argv[0], path), file=sys.stderr) return self.send_path(path) def send_404(self): diff --git a/tools/scan-view/share/startfile.py b/tools/scan-view/share/startfile.py index e8fbe2d..9801e00 100644 --- a/tools/scan-view/share/startfile.py +++ b/tools/scan-view/share/startfile.py @@ -186,7 +186,7 @@ else: return _controllers[controller_name].open except KeyError: - if _controllers.has_key('xdg-open'): + if 'xdg-open' in _controllers: return _controllers['xdg-open'].open else: return webbrowser.open
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits