2to3 last remnants of Python 2 syntax
This commit is contained in:
parent
538eb20264
commit
f19bd188c2
3 changed files with 26 additions and 26 deletions
|
@ -3,8 +3,8 @@ import random
|
||||||
|
|
||||||
im = mapnik.Image(256,256)
|
im = mapnik.Image(256,256)
|
||||||
|
|
||||||
for x in xrange(0,im.width()):
|
for x in range(im.width()):
|
||||||
for y in xrange(0,im.height()):
|
for y in range(im.height()):
|
||||||
r = int(random.random() * 255)
|
r = int(random.random() * 255)
|
||||||
g = random.random() * 255
|
g = random.random() * 255
|
||||||
b = random.random() * 255
|
b = random.random() * 255
|
||||||
|
|
|
@ -50,10 +50,10 @@ parser.add_option("-d", "--deadline",
|
||||||
|
|
||||||
def check_deadline(now):
|
def check_deadline(now):
|
||||||
if options.deadline > 0 and options.deadline < now:
|
if options.deadline > 0 and options.deadline < now:
|
||||||
print "\n\n*** travis-cmd-wrapper: deadline reached, shutting down ***\n\n"
|
print("\n\n*** travis-cmd-wrapper: deadline reached, shutting down ***\n\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print "deadline not reached: %s > %s" % (options.deadline,now)
|
print("deadline not reached: %s > %s" % (options.deadline,now))
|
||||||
|
|
||||||
# Set up status alarm. When we have a deadline, we need to check more often
|
# Set up status alarm. When we have a deadline, we need to check more often
|
||||||
# and/or sooner. Sending a SIGALRM manually will also trigger a status report
|
# and/or sooner. Sending a SIGALRM manually will also trigger a status report
|
||||||
|
@ -95,7 +95,7 @@ try:
|
||||||
line = cmd.stdout.readline()
|
line = cmd.stdout.readline()
|
||||||
sys.stdout.write(line)
|
sys.stdout.write(line)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
except IOError, ex:
|
except IOError as ex:
|
||||||
if ex.errno != errno.EINTR:
|
if ex.errno != errno.EINTR:
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -22,7 +22,7 @@ ShapeType = { 0 : "NullShape",
|
||||||
|
|
||||||
def test_record(_type, record) :
|
def test_record(_type, record) :
|
||||||
if _type == 0:
|
if _type == 0:
|
||||||
print "NULL shape"
|
print("NULL shape")
|
||||||
elif _type == 11: #PointZ
|
elif _type == 11: #PointZ
|
||||||
test_pointz(record)
|
test_pointz(record)
|
||||||
elif _type == 5:
|
elif _type == 5:
|
||||||
|
@ -31,35 +31,35 @@ def test_record(_type, record) :
|
||||||
def test_pointz(record):
|
def test_pointz(record):
|
||||||
_type, = struct.unpack("<i", record[0:4])
|
_type, = struct.unpack("<i", record[0:4])
|
||||||
if _type == 0:
|
if _type == 0:
|
||||||
print "NULL shape"
|
print("NULL shape")
|
||||||
return
|
return
|
||||||
if len(record) != 36 :
|
if len(record) != 36 :
|
||||||
print>>sys.stderr,"BAD SHAPE FILE: expected 36 bytes got",len(record)
|
print("BAD SHAPE FILE: expected 36 bytes got", len(record), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
x,y,z,m = struct.unpack("<dddd",record[4:36])
|
x,y,z,m = struct.unpack("<dddd",record[4:36])
|
||||||
if _type != 11:
|
if _type != 11:
|
||||||
print>>sys.stderr,"BAD SHAPE FILE: expected PointZ or NullShape got",_type
|
print("BAD SHAPE FILE: expected PointZ or NullShape got", _type, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def test_polygon(record):
|
def test_polygon(record):
|
||||||
_type, = struct.unpack("<i", record[0:4])
|
_type, = struct.unpack("<i", record[0:4])
|
||||||
if _type == 0:
|
if _type == 0:
|
||||||
print "NULL shape"
|
print("NULL shape")
|
||||||
return
|
return
|
||||||
x0, y0, x1, y0, num_parts, num_points = struct.unpack("<ddddii", record[4:44])
|
x0, y0, x1, y0, num_parts, num_points = struct.unpack("<ddddii", record[4:44])
|
||||||
if _type != 5:
|
if _type != 5:
|
||||||
print>>sys.stderr, "BAD SHAPE FILE: expected Polygon or NullShape got", _type
|
print("BAD SHAPE FILE: expected Polygon or NullShape got", _type, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
length = len(record)
|
length = len(record)
|
||||||
rec_length = 44 + num_parts * 4 + num_points * 16
|
rec_length = 44 + num_parts * 4 + num_points * 16
|
||||||
if rec_length <> length:
|
if rec_length != length:
|
||||||
print>>sys.stderr, "BAD SHAPE FILE: expected", rec_length, "got", length
|
print("BAD SHAPE FILE: expected", rec_length, "got", length, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__" :
|
if __name__ == "__main__" :
|
||||||
|
|
||||||
if len(sys.argv) !=2:
|
if len(sys.argv) !=2:
|
||||||
print>>sys.stderr, "Usage:",sys.argv[0],"<shapefile>"
|
print("Usage:",sys.argv[0],"<shapefile>", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
shx_filename = sys.argv[1][:-3]+"shx"
|
shx_filename = sys.argv[1][:-3]+"shx"
|
||||||
|
@ -80,15 +80,15 @@ if __name__ == "__main__" :
|
||||||
version,_type,lox,loy,hix,hiy,_,_,_,_ = header[1].unpack_from(shp.read(72))
|
version,_type,lox,loy,hix,hiy,_,_,_,_ = header[1].unpack_from(shp.read(72))
|
||||||
|
|
||||||
shp_bbox = [lox,loy,hix,hiy]
|
shp_bbox = [lox,loy,hix,hiy]
|
||||||
if shx_bbox <> shp_bbox :
|
if shx_bbox != shp_bbox :
|
||||||
print "BAD SHAPE FILE: bounding box mismatch in *.shp and *.shx", shp_bbox, shx_bbox
|
print("BAD SHAPE FILE: bounding box mismatch in *.shp and *.shx", shp_bbox, shx_bbox)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print "SHX FILE_LENGTH=",shx_file_length,"bytes"
|
print("SHX FILE_LENGTH=",shx_file_length,"bytes")
|
||||||
print "SHP FILE_LENGTH=",shp_file_length,"bytes"
|
print("SHP FILE_LENGTH=",shp_file_length,"bytes")
|
||||||
|
|
||||||
print "TYPE", ShapeType[_type]
|
print("TYPE", ShapeType[_type])
|
||||||
print "BBOX(",lox,loy,hix,hiy,")"
|
print("BBOX(",lox,loy,hix,hiy,")")
|
||||||
record_header = struct.Struct(">II")
|
record_header = struct.Struct(">II")
|
||||||
record = struct.Struct(">II")
|
record = struct.Struct(">II")
|
||||||
calc_total_size = 50
|
calc_total_size = 50
|
||||||
|
@ -97,19 +97,19 @@ if __name__ == "__main__" :
|
||||||
offset,shx_content_length = record.unpack_from(shx.read(8))
|
offset,shx_content_length = record.unpack_from(shx.read(8))
|
||||||
shp.seek(offset*2, os.SEEK_SET)
|
shp.seek(offset*2, os.SEEK_SET)
|
||||||
record_number,content_length = record_header.unpack_from(shp.read(8))
|
record_number,content_length = record_header.unpack_from(shp.read(8))
|
||||||
if shx_content_length <> content_length:
|
if shx_content_length != content_length:
|
||||||
print "BAD SHAPE FILE: content_lenght mismatch in SHP and SHX",shx_content_length,content_length
|
print("BAD SHAPE FILE: content_lenght mismatch in SHP and SHX",shx_content_length,content_length)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
##
|
##
|
||||||
test_record(_type, shp.read(2*content_length))
|
test_record(_type, shp.read(2*content_length))
|
||||||
calc_total_size +=(4 + content_length)
|
calc_total_size +=(4 + content_length)
|
||||||
count+=1
|
count+=1
|
||||||
|
|
||||||
print "SHAPES COUNT=",count
|
print("SHAPES COUNT=",count)
|
||||||
delta = shp_file_length-calc_total_size
|
delta = shp_file_length-calc_total_size
|
||||||
if delta > 0 :
|
if delta > 0 :
|
||||||
print "BAD SHAPE FILE: extra ", 2*delta,"bytes"
|
print("BAD SHAPE FILE: extra ", 2*delta,"bytes")
|
||||||
elif delta < 0:
|
elif delta < 0:
|
||||||
print "BAD SHAPE FILE: missing ", 2*delta,"bytes"
|
print("BAD SHAPE FILE: missing ", 2*delta,"bytes")
|
||||||
else:
|
else:
|
||||||
print "SHAPE FILE LOOKS GOOD!"
|
print("SHAPE FILE LOOKS GOOD!")
|
||||||
|
|
Loading…
Reference in a new issue