Skip to content

Commit 7bd8706

Browse files
authored
Make it Python 3-compatible (#29)
1 parent d87b302 commit 7bd8706

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

tool/run_O2CodeChecker.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
3535
"""
3636

37+
from __future__ import print_function
3738
import argparse
3839
import json
3940
import multiprocessing
4041
import os
41-
import Queue
42+
try:
43+
import Queue
44+
except ImportError:
45+
import queue as Queue
4246
import re
4347
import shutil
4448
import subprocess
@@ -52,7 +56,7 @@ def find_compilation_database(path):
5256
result = './'
5357
while not os.path.isfile(os.path.join(result, path)):
5458
if os.path.realpath(result) == '/':
55-
print 'Error: could not find compilation database.'
59+
print('Error: could not find compilation database.')
5660
sys.exit(1)
5761
result += '../'
5862
return os.path.realpath(result)
@@ -158,9 +162,9 @@ def main():
158162
if args.checks:
159163
invocation.append('-checks=' + args.checks)
160164
invocation.append('-')
161-
print subprocess.check_output(invocation)
165+
print(subprocess.check_output(invocation))
162166
except:
163-
print >>sys.stderr, "Unable to run clang-tidy."
167+
print("Unable to run clang-tidy.")
164168
sys.exit(1)
165169

166170
# Load the database and extract all files.
@@ -198,13 +202,13 @@ def main():
198202
except KeyboardInterrupt:
199203
# This is a sad hack. Unfortunately subprocess goes
200204
# bonkers with ctrl-c and we start forking merrily.
201-
print '\nCtrl-C detected, goodbye.'
205+
print('\nCtrl-C detected, goodbye.')
202206
if args.fix:
203207
shutil.rmtree(tmpdir)
204208
os.kill(0, 9)
205209

206210
if args.fix:
207-
print 'Applying fixes ...'
211+
print('Applying fixes ...')
208212
apply_fixes(args, tmpdir)
209213

210214
if __name__ == '__main__':

utility/ThinCompilationsDatabase.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
# A python script with the goal
44
# to transform a (large) compilations database
@@ -9,13 +9,17 @@
99
#
1010
# First version: Sandro Wenzel (June 2017)
1111

12+
from __future__ import print_function
1213
import argparse
1314
import json
1415
import os
1516
import subprocess
1617
import re
1718
# these are for queue syncronized multi-threading
18-
import Queue
19+
try:
20+
import Queue
21+
except ImportError:
22+
import queue as Queue
1923
import threading
2024
import multiprocessing
2125
import time
@@ -45,7 +49,7 @@ def parseArgs():
4549
def verboseLog(string, level=0):
4650
global verbosity
4751
if verbosity > 0:
48-
print string
52+
print(string)
4953

5054
def getListOfChangedFiles(colonseparatedfilepaths):
5155
""" processes the argument '-use-files' and returns a python list of filenames """
@@ -128,8 +132,8 @@ def processItem(keepalive, changedheaderlist, queue, outqueue):
128132

129133
def reportProgress(keepalive, queue, q2):
130134
while len(keepalive)>0:
131-
print "input queue has size " + str(queue.qsize())
132-
print "output queue has size " + str(q2.qsize())
135+
print("input queue has size " + str(queue.qsize()))
136+
print("output queue has size " + str(q2.qsize()))
133137
time.sleep(1)
134138

135139
#custom function to remove duplicates and return a new list
@@ -173,11 +177,11 @@ def main():
173177
#setup the isInvalid (closure) function
174178
isInvalid=makeInvalidClosure(args)
175179

176-
#open the compilations database
180+
#open the compilations database
177181
try:
178182
file=open('compile_commands.json').read()
179183
except IOError:
180-
print "Problem opening the compilation database (file not found)"
184+
print("Problem opening the compilation database (file not found)")
181185
sys.exit(1)
182186

183187
#convert json to dict

0 commit comments

Comments
 (0)