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 # This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it # the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What ... You Want # and/or modify it under the terms of the WTFPL
# To Public License, Version 2, as published by Sam Hocevar. See # Public License, Version 2, as published by Sam Hocevar. See
# COPYING for more details. # COPYING for more details.
# Made by Jogge, modified by celeron55 # Made by Jogge, modified by celeron55
@ -135,16 +135,25 @@ usagetext = """minetestmapper.py [options]
--region <xmin>:<xmax>,<zmin>:<zmax> --region <xmin>:<xmax>,<zmin>:<zmax>
--geometry <xmin>:<zmin>+<width>+<height> --geometry <xmin>:<zmin>+<width>+<height>
--drawunderground --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(): def usage():
print(usagetext) print(usagetext)
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=", opts, args = getopt.getopt(sys.argv[1:],
"output=", "bgcolor=", "scalecolor=", "origincolor=", "hi:o:",
"playercolor=", "draworigin", "drawplayers", "drawscale", ["help", "input=", "output=",
"drawunderground", "geometry=", "region="]) "bgcolor=", "scalecolor=", "origincolor=",
"playercolor=", "draworigin", "drawplayers",
"drawscale", "drawunderground", "geometry=",
"region="])
except getopt.GetoptError as err: except getopt.GetoptError as err:
# print help information and exit: # print help information and exit:
print(str(err)) # will print something like "option -a not recognized" print(str(err)) # will print something like "option -a not recognized"
@ -196,6 +205,7 @@ for o, a in opts:
region_string = a region_string = a
else: else:
assert False, "unhandled option" assert False, "unhandled option"
nonchunky_xmin = -1500 nonchunky_xmin = -1500
nonchunky_xmax = 1500 nonchunky_xmax = 1500
nonchunky_zmin = -1500 nonchunky_zmin = -1500
@ -213,9 +223,9 @@ if geometry_string is not None:
this_width = int(width_string) this_width = int(width_string)
this_height = int(height_string) this_height = int(height_string)
nonchunky_xmin = x 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_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("#geometry:")
print("# x:" + str(x)) print("# x:" + str(x))
print("# z:" + str(z)) print("# z:" + str(z))
@ -227,11 +237,13 @@ if geometry_string is not None:
print(" zmin:" + str(nonchunky_zmin)) print(" zmin:" + str(nonchunky_zmin))
print(" zmax:" + str(nonchunky_zmax)) print(" zmax:" + str(nonchunky_zmax))
else: 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() usage()
sys.exit(2) sys.exit(2)
else: 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() usage()
sys.exit(2) sys.exit(2)
elif region_string is not None: elif region_string is not None:
@ -252,18 +264,18 @@ elif region_string is not None:
print(" zmin:" + str(nonchunky_zmin)) print(" zmin:" + str(nonchunky_zmin))
print(" zmax:" + str(nonchunky_zmax)) print(" zmax:" + str(nonchunky_zmax))
else: 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() usage()
sys.exit(2) sys.exit(2)
#answer=raw_input("press enter to continue")
sector_xmin = nonchunky_xmin / 16 sector_xmin = nonchunky_xmin / 16
sector_xmax = nonchunky_xmax / 16 sector_xmax = nonchunky_xmax / 16
sector_zmin = nonchunky_zmin / 16 sector_zmin = nonchunky_zmin / 16
sector_zmax = nonchunky_zmax / 16 sector_zmax = nonchunky_zmax / 16
if path is None: 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) sys.exit(1)
if path[-1:] != "/" and path[-1:] != "\\": if path[-1:] != "/" and path[-1:] != "\\":
@ -273,30 +285,40 @@ if path[-1:] != "/" and path[-1:] != "\\":
colors = {} colors = {}
colors_path = "colors.txt" colors_path = "colors.txt"
os_name="linux"
if (os.path.sep!="/"):
os_name="windows"
profile_path = None profile_path = None
if os_name=="windows": if 'USERPROFILE' in os.environ:
profile_path = os.environ['USERPROFILE'] profile_path = os.environ['USERPROFILE']
else: elif 'HOME' in os.environ:
profile_path = os.environ['HOME'] profile_path = os.environ['HOME']
mt_path = os.path.join( profile_path, "minetest") mt_path = None
mt_util_path = os.path.join( mt_path, "util") mt_util_path = None
abs_colors_path = os.path.join( mt_util_path, "colors.txt" ) 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 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 colors_path = abs_colors_path
if not os.path.isfile(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: try:
f = file(colors_path) f = file(colors_path)
except IOError: 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: for line in f:
values = string.split(line) values = string.split(line)
if len(values) < 4: if len(values) < 4:
@ -375,7 +397,7 @@ if os.path.exists(path + "sectors"):
zlist.append(z) zlist.append(z)
if len(xlist) == 0 or len(zlist) == 0: 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) sys.exit(1)
# Get rid of doubles # Get rid of doubles
@ -840,4 +862,3 @@ if unknown_node_ids:
for node_id in unknown_node_ids: for node_id in unknown_node_ids:
sys.stdout.write(" "+str(hex(node_id))) sys.stdout.write(" "+str(hex(node_id)))
sys.stdout.write(os.linesep) sys.stdout.write(os.linesep)

Loading…
Cancel
Save