improved usage output regarding colors.txt

and improved logic of colors.txt detection
This commit is contained in:
Jacob Gustafson 2016-05-01 22:51:06 -04:00
parent 8e1f581ef1
commit 67713ef5f1
1 changed files with 21 additions and 15 deletions

View File

@ -135,7 +135,12 @@ 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)
@ -282,28 +287,29 @@ elif 'HOME' in os.environ:
mt_path = None
mt_util_path = None
abs_colors_path = None
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 not os.path.isfile(colors_path):
colors_path = abs_colors_path
colors_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "colors.txt")
if colors_path is None or not os.path.isfile(colors_path):
print("ERROR: could not find colors.txt is current path")
if colors_path is not None:
print(" nor '"+colors_path+"'.")
else:
print(" and minetest util path could not be detected.")
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("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: