From 81d6fa384df0c3bb99f749e126fe341bdd1639e0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 25 Jul 2015 14:00:14 +0300 Subject: [PATCH] Fix suffix errors --- slpkg/graph.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/slpkg/graph.py b/slpkg/graph.py index 2a28c5cf..e6ac63e5 100644 --- a/slpkg/graph.py +++ b/slpkg/graph.py @@ -40,10 +40,7 @@ def graph_deps(deps_dict, image): "svgz", "tif", "tiff", "tk", "vml", "vmlz", "vrml", "wbmp", "x11", "xdot", "xdot1.2", "xdot1.4", "xlib" ] - if image.split(".")[1] not in file_format: - print("Format: {0} not recognized. Use one of: {1}".format( - image.split(".")[1], " ".join(file_format))) - raise SystemExit() + format_error(image, file_format) try: G = pgv.AGraph(deps_dict) G.layout(prog="fdp") @@ -53,3 +50,16 @@ def graph_deps(deps_dict, image): if os.path.isfile(image): print("Graph file '{0}' created".format(image)) raise SystemExit() + + +def format_error(image, file_format): + """Check for file format and type + """ + try: + if image.split(".")[1] not in file_format: + print("Format: {0} not recognized. Use one of: {1}".format( + image.split(".")[1], " ".join(file_format))) + raise SystemExit() + except IndexError: + print("slpkg: error: File image suffix missing") + raise SystemExit()