From d59ea54dd3cffa8b8c435460daf1e68df72b4c2b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 6 Nov 2014 18:44:42 +0100 Subject: [PATCH] add simple fatal function --- client/cli/bam.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/client/cli/bam.py b/client/cli/bam.py index 714aa27..728cb61 100755 --- a/client/cli/bam.py +++ b/client/cli/bam.py @@ -37,6 +37,14 @@ del os, sys, path # -------- +def fatal(msg): + import sys + sys.stderr.write("fatal: ") + sys.stderr.write(msg) + sys.stderr.write("\n") + sys.exit(1) + + class bam_config: # fake module __slots__ = () @@ -80,11 +88,7 @@ class bam_config: filepath = bam_config.find_basedir(cwd=cwd, suffix=id_) if abort is True: if filepath is None: - import sys - sys.stderr.write( - "fatal: Not a bam repository " - "(or any of the parent directories): .bam\n") - sys.exit(1) + fatal("Not a bam repository (or any of the parent directories): .bam") with open(filepath, 'r') as f: import json @@ -419,9 +423,7 @@ class bam_utils: r_json = r.json() items = r_json.get("items_list", None) if items is None: - import sys - sys.stderr.write("fatal: %s\n" % r_json.get("message", "")) - sys.exit(1) + fatal(r_json.get("message", "")) items.sort()