Skip to content

Commit

Permalink
add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
willeccles committed Oct 29, 2021
1 parent 818580a commit 2fefba6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions genvsmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def Vprint(*objects, sep=' ', end='\n'):
def Eprint(*objects, sep=' ', end='\n'):
print(*objects, sep=sep, end=end, file=sys.stderr, flush=True)

def Warn(msg: str):
print("warning:", msg, file=sys.stderr, flush=True)

def Die(*objects, code=1):
Eprint("error:", *objects)
exit(code)
Expand All @@ -77,10 +80,10 @@ def Die(*objects, code=1):
exit(1)
else:
if args.gen_src and os.path.exists(outsrcfile):
print(f"note: {outsrcfile} exists and will be overwritten (-f)")
print(f"{outsrcfile} exists and will be overwritten (-f)")

if args.gen_header and os.path.exists(outheaderfile):
print(f"note: {outheaderfile} exists and will be overwritten (-f)")
print(f"{outheaderfile} exists and will be overwritten (-f)")
else:
Vprint("output will be written to stdout")

Expand Down Expand Up @@ -180,23 +183,27 @@ def ParseChannels(channels, desc=False, types=False) -> dict:

if desc and "description" in channel:
description = str(channel["description"])
elif not desc and "description" in channel:
Warn(f"{channel['name']}: ignoring description field")

if types and "type" in channel:
if channel["type"] == "i32":
datatype = "int32_t"
elif channel["type"] == "double":
datatype = "double"
else:
Die(f"'{channel['name']}': unknown type: {channel['name']}")
Die(f"{channel['name']}: unknown type: {channel['type']}")
elif not types and "type" in channel:
Warn(f"{channel['name']}: ignoring type field")

if "dimX" in channel:
dimX = int(channel["dimX"])
if "dimY" in channel:
dimY = int(channel["dimY"])
if dimX < 1:
Die(f"'{channel['name']}': dimX cannot be less than 1")
Die(f"{channel['name']}: dimX cannot be less than 1")
if dimY < 1:
Die(f"'{channel['name']}': dimY cannot be less than 1")
Die(f"{channel['name']}: dimY cannot be less than 1")
elif isinstance(channel, str):
(cat, name) = GetCategoryAndName(channel)

Expand Down

0 comments on commit 2fefba6

Please sign in to comment.