Browse Source

improved environment detection

and PEP8 and wording of "does not exist" message
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
392e5bc9a9
  1. 77
      minetestmapper-expertmm.py

77
minetestmapper-expertmm.py

@ -3,8 +3,8 @@
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What ... You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# and/or modify it under the terms of the WTFPL
# Public License, Version 2, as published by Sam Hocevar. See
# COPYING for more details.
# Made by Jogge, modified by celeron55
@ -135,16 +135,25 @@ usagetext = """minetestmapper.py [options]
--region <xmin>:<xmax>,<zmin>:<zmax>
--geometry <xmin>:<zmin>+<width>+<height>
--drawunderground
Color format: '#000000'"""
Color format: '#000000'
NOTE: colors.txt must be in same directory as
this script or in the current working
directory (or util directory if installed).
"""
def usage():
print(usagetext)
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=",
"output=", "bgcolor=", "scalecolor=", "origincolor=",
"playercolor=", "draworigin", "drawplayers", "drawscale",
"drawunderground", "geometry=", "region="])
opts, args = getopt.getopt(sys.argv[1:],
"hi:o:",
["help", "input=", "output=",
"bgcolor=", "scalecolor=", "origincolor=",
"playercolor=", "draworigin", "drawplayers",
"drawscale", "drawunderground", "geometry=",
"region="])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
@ -196,6 +205,7 @@ for o, a in opts:
region_string = a
else:
assert False, "unhandled option"
nonchunky_xmin = -1500
nonchunky_xmax = 1500
nonchunky_zmin = -1500
@ -213,9 +223,9 @@ if geometry_string is not None:
this_width = int(width_string)
this_height = int(height_string)
nonchunky_xmin = x
nonchunky_xmax = nonchunky_xmin + this_width - 1 # -1 since max is inclusive rect
nonchunky_xmax = nonchunky_xmin + this_width - 1 # inclusive rect
nonchunky_zmin = z
nonchunky_zmax = nonchunky_zmin + this_height - 1 # -1 since max is inclusive rect
nonchunky_zmax = nonchunky_zmin + this_height - 1 # inclusive rect
print("#geometry:")
print("# x:" + str(x))
print("# z:" + str(z))
@ -227,11 +237,13 @@ if geometry_string is not None:
print(" zmin:" + str(nonchunky_zmin))
print(" zmax:" + str(nonchunky_zmax))
else:
print("ERROR: (Missing coordinates in '"+geometry_string+"' for geometry) Geometry should be in the form: x:z+width+height")
print("ERROR: Missing coordinates in '" + geometry_string +
"' for geometry (must be in the form: x:z+width+height)")
usage()
sys.exit(2)
else:
print("ERROR: (Incorrect value '"+geometry_string+"' for geometry) Geometry should be in the form: x:z+width+height")
print("ERROR: Incorrect value '" + geometry_string +
"' for geometry (must be in the form: x:z+width+height)")
usage()
sys.exit(2)
elif region_string is not None:
@ -252,18 +264,18 @@ elif region_string is not None:
print(" zmin:" + str(nonchunky_zmin))
print(" zmax:" + str(nonchunky_zmax))
else:
print("ERROR: (Incorrect value '"+region_string+"' for region) Region should be in the form: xmin:xmax,zmin:zmax")
print("ERROR: Incorrect value '" + region_string +
"' for region (must be in the form: xmin:xmax,zmin:zmax)")
usage()
sys.exit(2)
#answer=raw_input("press enter to continue")
sector_xmin = nonchunky_xmin / 16
sector_xmax = nonchunky_xmax / 16
sector_zmin = nonchunky_zmin / 16
sector_zmax = nonchunky_zmax / 16
if path is None:
print("Please select world path (eg. -i ../worlds/yourworld) (or use --help)")
print("Please select world path (-i ../worlds/yourworld) (or use --help)")
sys.exit(1)
if path[-1:] != "/" and path[-1:] != "\\":
@ -273,30 +285,40 @@ if path[-1:] != "/" and path[-1:] != "\\":
colors = {}
colors_path = "colors.txt"
os_name="linux"
if (os.path.sep!="/"):
os_name="windows"
profile_path = None
if os_name=="windows":
if 'USERPROFILE' in os.environ:
profile_path = os.environ['USERPROFILE']
else:
elif 'HOME' in os.environ:
profile_path = os.environ['HOME']
mt_path = os.path.join( profile_path, "minetest")
mt_util_path = os.path.join( mt_path, "util")
abs_colors_path = os.path.join( mt_util_path, "colors.txt" )
mt_path = None
mt_util_path = None
abs_colors_path = None
if not os.path.isfile(colors_path):
colors_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"colors.txt")
if not os.path.isfile(colors_path):
if profile_path is not None:
try_path = os.path.join(profile_path, "minetest")
if os.path.isdir(try_path):
mt_path = try_path
mt_util_path = os.path.join(mt_path, "util")
abs_colors_path = os.path.join(mt_util_path, "colors.txt")
if os.path.isfile(abs_colors_path):
colors_path = abs_colors_path
if not os.path.isfile(colors_path):
print("WARNING: could not find colors.txt is current path or '"+colors_path+"'")
print("ERROR: could not find colors.txt")
usage()
sys.exit(1)
try:
f = file(colors_path)
except IOError:
f = file(os.path.join(os.path.dirname(__file__), "colors.txt"))
f = file(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"colors.txt"))
for line in f:
values = string.split(line)
if len(values) < 4:
@ -375,7 +397,7 @@ if os.path.exists(path + "sectors"):
zlist.append(z)
if len(xlist) == 0 or len(zlist) == 0:
print("At this location data does not exist.")
print("Data does not exist at this location.")
sys.exit(1)
# Get rid of doubles
@ -840,4 +862,3 @@ if unknown_node_ids:
for node_id in unknown_node_ids:
sys.stdout.write(" "+str(hex(node_id)))
sys.stdout.write(os.linesep)

Loading…
Cancel
Save