From c122a88f64fa9cabb09c94b44f2963dd5ae6d385 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Thu, 3 Mar 2016 08:53:36 -0500 Subject: [PATCH] error handling for showing genresult --- chunkymap-regen.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/chunkymap-regen.py b/chunkymap-regen.py index aec6f77..7337776 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -68,18 +68,25 @@ def view_traceback(): def print_file(path, indent=""): try: - if os.path.isfile(path): - if indent is None: - indent = "" - ins = open(path, 'r') - line = True - while line: - line = ins.readline() - if line: - print(indent+line) - ins.close() + if path is not None: + if os.path.isfile(path): + line_count = 0 + if indent is None: + indent = "" + ins = open(path, 'r') + line = True + while line: + line = ins.readline() + line_count += 1 + if line: + print(indent+line) + ins.close() + if line_count==0: + print(indent+"print_file WARNING: "+str(line_count)+" line(s) in '"+path+"'") + else: + print (indent+"print_file: file does not exist") else: - print (indent+"print_file: missing path") + print (indent+"print_file: path is None") except: print(indent+"print_file: could not finish")