Migration Python2 towards Python3 (#4232)
The modified code stays compatible with Python2.
This commit is contained in:
@@ -87,9 +87,9 @@ for file in filenames:
|
||||
try:
|
||||
doc = xml.dom.minidom.parse(file)
|
||||
except Exception as ex:
|
||||
print "============================================"
|
||||
print "/!\\ Expat doesn't like ", file, "! Error=", type(ex), " (", ex.args, ")"
|
||||
print "============================================"
|
||||
print("============================================")
|
||||
print("/!\\ Expat doesn't like ", file, "! Error=", type(ex), " (", ex.args, ")")
|
||||
print("============================================")
|
||||
|
||||
traverse(file, doc, isChallenge, isGP, isKart, isTrack, isAchievements)
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage: getpo_authors.py PATH_TO_PO_FILE"
|
||||
print("Usage: getpo_authors.py PATH_TO_PO_FILE")
|
||||
sys.exit(-1)
|
||||
|
||||
for filename in sys.argv[1:]:
|
||||
print("Processing file %s" % filename)
|
||||
f = open(filename, "r")
|
||||
if not f:
|
||||
print "Can not find", filename
|
||||
print("Can not find", filename)
|
||||
exit
|
||||
lines = f.readlines()
|
||||
|
||||
|
||||
@@ -39,14 +39,14 @@ def getTexturesFromB3D(filename, textures):
|
||||
f = open(filename, "r")
|
||||
s = f.read(4)
|
||||
if s!="BB3D":
|
||||
print filename,"is not a valid b3d file"
|
||||
print(filename,"is not a valid b3d file")
|
||||
f.close()
|
||||
return
|
||||
start_texs = 12
|
||||
f.seek(start_texs)
|
||||
s = f.read(4)
|
||||
if s!="TEXS":
|
||||
print "Can not handle '%s' b3d file - ignored."%filename
|
||||
print("Can not handle '%s' b3d file - ignored."%filename)
|
||||
f.close()
|
||||
return
|
||||
n = struct.unpack("<i", f.read(4))[0] # Read end of section
|
||||
@@ -102,9 +102,9 @@ def findKartData(dir, textures, b3dfiles):
|
||||
else:
|
||||
f = open(dir+"scene.xml", "r")
|
||||
if not f: return
|
||||
print "WARNING"
|
||||
print("WARNING")
|
||||
if 1:
|
||||
print "WARNING - kart.xml not done yet"
|
||||
print("WARNING - kart.xml not done yet")
|
||||
f = open(dir+"kart.xml", "r")
|
||||
if not f: return
|
||||
r_screenshot = re.compile("^ *screenshot *= \"(.*)\" *$")
|
||||
@@ -134,7 +134,7 @@ def checkDir(dir, shared_textures):
|
||||
if i[-4:]==".b3d":
|
||||
b3d_files_in_dir[i] = 1
|
||||
elif i[-5:]==".b3dz":
|
||||
print "Can't handle file '%s'."%i
|
||||
print("Can't handle file '%s'."%i)
|
||||
|
||||
# Find all textures listed in materials.xml
|
||||
# -----------------------------------------
|
||||
@@ -151,13 +151,13 @@ def checkDir(dir, shared_textures):
|
||||
# ===========================================
|
||||
for i in used_b3d_files.keys():
|
||||
if not b3d_files_in_dir.get(i):
|
||||
print "File '%s' is missing."%(dir+i)
|
||||
print("File '%s' is missing."%(dir+i))
|
||||
|
||||
# 2) Check if there are any unnecessary b3d files
|
||||
# ===============================================
|
||||
for i in b3d_files_in_dir:
|
||||
if not used_b3d_files.get(i):
|
||||
print "File '%s' is not used."%i
|
||||
print("File '%s' is not used."%i)
|
||||
continue
|
||||
del used_b3d_files[i]
|
||||
# Load all textures used in this b3d file
|
||||
@@ -168,14 +168,14 @@ def checkDir(dir, shared_textures):
|
||||
for i in used_textures:
|
||||
if not existing_textures.get(i)==1:
|
||||
if not shared_textures.get(i):
|
||||
print "Cannot find texture '%s'."%i
|
||||
print("Cannot find texture '%s'."%i)
|
||||
continue
|
||||
else:
|
||||
del existing_textures[i]
|
||||
|
||||
|
||||
for i in existing_textures:
|
||||
print "Texture '%s' is not used anywhere."%(dir+i)
|
||||
print("Texture '%s' is not used anywhere."%(dir+i))
|
||||
|
||||
# Now check that all entries in materials.xml are indeed used and exist
|
||||
|
||||
|
||||
@@ -4,21 +4,21 @@ import math
|
||||
import sys
|
||||
|
||||
def usage():
|
||||
print "Usage:"
|
||||
print "compute_client_error.py -f time,x1[,x2,x3....] server-data client-data"
|
||||
print "The files are expected to contain space separated fields. The"
|
||||
print "-f options specifies first the column in which the world time"
|
||||
print "is, followed by the list of columns to be compared."
|
||||
print "It computes for each data point in the client file the closest"
|
||||
print "the two data points with the closest time stamp in the server"
|
||||
print "and then interpolates the server position based on the client"
|
||||
print "time between these positions. The difference between the"
|
||||
print "intepolated position"
|
||||
print
|
||||
print "Example:"
|
||||
print "compute_client_error.py-multi -f 6,16,17,18 debug.server debug.client"
|
||||
print " to compute the differences between client and server for the"
|
||||
print " fields 16,17,18 (which atm is the velocity)"
|
||||
print("Usage:")
|
||||
print("compute_client_error.py -f time,x1[,x2,x3....] server-data client-data")
|
||||
print("The files are expected to contain space separated fields. The")
|
||||
print("-f options specifies first the column in which the world time")
|
||||
print("is, followed by the list of columns to be compared.")
|
||||
print("It computes for each data point in the client file the closest")
|
||||
print("the two data points with the closest time stamp in the server")
|
||||
print("and then interpolates the server position based on the client")
|
||||
print("time between these positions. The difference between the")
|
||||
print("intepolated position")
|
||||
print()
|
||||
print("Example:")
|
||||
print("compute_client_error.py-multi -f 6,16,17,18 debug.server debug.client")
|
||||
print(" to compute the differences between client and server for the")
|
||||
print(" fields 16,17,18 (which atm is the velocity)")
|
||||
sys.exit()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -69,14 +69,14 @@ def computeDifferences(server, client):
|
||||
interp.append(x_i)
|
||||
error = error + (x[i]-x_i)**2
|
||||
error = math.sqrt(error)
|
||||
print time, error
|
||||
print(time, error)
|
||||
if (error < min): min=error
|
||||
if (error > max): max=error
|
||||
count += 1
|
||||
sum += error
|
||||
|
||||
print "sum %f count %d min %f average %f max %f" \
|
||||
% (sum, count, min, sum/count, max)
|
||||
print("sum %f count %d min %f average %f max %f" \
|
||||
% (sum, count, min, sum/count, max))
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if __name__=="__main__":
|
||||
|
||||
Reference in New Issue
Block a user