Skip to content

Commit

Permalink
Make compose.py's exit code 1 if error logged
Browse files Browse the repository at this point in the history
This is a bit of a hack, but usage of a global seems to be the minimally
invasive way to do this. Also categorized the messages into Info,
Warning, and Error types.
  • Loading branch information
ifreund authored and kevingranade committed May 8, 2020
1 parent 0a9a8c0 commit 77b1f5f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tools/gfx_tools/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import os
import subprocess
import sys

try:
import pyvips
Expand Down Expand Up @@ -40,6 +41,8 @@
]
}

error_logged = False

# stupid stinking Python 2 versus Python 3 syntax
def write_to_json(pathname, data):
with open(pathname, "w") as fp:
Expand Down Expand Up @@ -76,8 +79,8 @@ def __init__(self, tileset_dirname):
try:
os.stat(self.tileset_pathname)
except KeyError:
print("cannot find a directory {}".format(self.tileset_pathname))
exit -1
print("Error: cannot find a directory {}".format(self.tileset_pathname))
sys.exit(1)

self.processed_ids = []
tileset_info_path = self.tileset_pathname + "/tile_info.json"
Expand All @@ -98,8 +101,10 @@ def convert_a_pngname_to_pngnum(self, sprite_id, entry):
self.referenced_pngnames.append(sprite_id)
return True
else:
print("sprite id '{}' has no matching PNG file. ".format(sprite_id) +
print("Error: sprite id '{}' has no matching PNG file. ".format(sprite_id) +
"It will not be added to tile_config.json")
global error_logged
error_logged = True
return False

def convert_pngname_to_pngnum(self, index):
Expand Down Expand Up @@ -141,7 +146,7 @@ def convert_tile_entry(self, tile_entry, prefix, is_filler):
for an_id in tile_id:
full_id = prefix + an_id
if full_id in self.processed_ids:
print("skipping filler for {}".format(full_id))
print("Info: skipping filler for {}".format(full_id))
return None
fg_id = tile_entry.get("fg")
if fg_id:
Expand All @@ -156,7 +161,9 @@ def convert_tile_entry(self, tile_entry, prefix, is_filler):
try:
del tile_entry["bg"]
except Exception:
print("Cannot find bg for tile with id {}".format(tile_id))
print("Error: Cannot find bg for tile with id {}".format(tile_id))
global error_logged
error_logged = True

add_tile_entrys = tile_entry.get("additional_tiles", [])
for add_tile_entry in add_tile_entrys:
Expand All @@ -173,7 +180,7 @@ def convert_tile_entry(self, tile_entry, prefix, is_filler):
def verify(self):
for pngname, pngnum in self.pngname_to_pngnum.items():
if pngnum and pngname not in self.referenced_pngnames:
print("image filename '{}' index '{}'".format(pngname, pngnum) +
print("Warning: image filename '{}' index '{}'".format(pngname, pngnum) +
" was not used in any tile_config.json entries")


Expand Down Expand Up @@ -242,11 +249,13 @@ def merge_row(self, refs):
pass

if vips_image.width != self.width or vips_image.height != self.height:
size_msg = "{} is {}x{}, sheet sprites are {}x{}."
size_msg = "Error: {} is {}x{}, sheet sprites are {}x{}."
print(size_msg.format(png_pathname, vips_image.width, vips_image.height,
self.width, self.height))
print("\tsprites in the {} tilesheet may be resized.".format(self.ts_name))
print("\tAll sprites in a tilesheet directory should have the same dimensions.")
global error_logged
error_logged = True
in_list.append(vips_image)
for i in range(0, spacer):
in_list.append(self.null_image)
Expand Down Expand Up @@ -311,7 +320,7 @@ def finalize_merges(self, merge_pngs):
ts_data = TilesheetData(subdir_index, refs)
if not ts_data.filler and not ts_data.fallback:
ts_data.set_first_index(refs)
print("parsing tilesheet {}".format(ts_data.ts_name))
print("Info: parsing tilesheet {}".format(ts_data.ts_name))
tmp_merged_pngs = ts_data.walk_dirs(refs)

ts_data.finalize_merges(tmp_merged_pngs)
Expand All @@ -323,7 +332,7 @@ def finalize_merges(self, merge_pngs):
ts_data = TilesheetData(subdir_index, refs)
if ts_data.filler:
ts_data.set_first_index(refs)
print("parsing filler tilesheet {}".format(ts_data.ts_name))
print("Info: parsing filler tilesheet {}".format(ts_data.ts_name))
ts_data.first_index = refs.pngnum
tmp_merged_pngs = ts_data.walk_dirs(refs)

Expand All @@ -336,7 +345,7 @@ def finalize_merges(self, merge_pngs):
ts_data = TilesheetData(subdir_index, refs)
if ts_data.fallback:
ts_data.set_first_index(refs)
print("parsing fallback tilesheet {}".format(ts_data.ts_name))
print("Info: parsing fallback tilesheet {}".format(ts_data.ts_name))
all_ts_data.append(ts_data)

#print("pngname to pngnum {}".format(json.dumps(refs.pngname_to_pngnum, indent=2)))
Expand Down Expand Up @@ -380,3 +389,6 @@ def finalize_merges(self, merge_pngs):
write_to_json(tileset_confpath, conf_data)

refs.verify()

if error_logged:
sys.exit(1)

0 comments on commit 77b1f5f

Please sign in to comment.