From f8bc63625af77b8857f3aca0db519f6f3422e3e5 Mon Sep 17 00:00:00 2001 From: Huang Hao Date: Wed, 6 Mar 2013 14:05:20 +0800 Subject: [PATCH] Refactor get_mic_binpath() to avoid catch all exceptions. Catch the specific exceptions it cares about, and reduce "try" block to minimal, otherwise some other errors will be hidden. Change-Id: Icbef03eef1591ba44466d5634943db5b8c86bdc4 --- mic/rt_util.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mic/rt_util.py b/mic/rt_util.py index e2d62e5..334d757 100644 --- a/mic/rt_util.py +++ b/mic/rt_util.py @@ -121,24 +121,24 @@ def get_bindmounts(cropts): def get_mic_binpath(): fp = None try: - # depends on 'setuptools' - import pkg_resources + import pkg_resources # depends on 'setuptools' + except ImportError: + pass + else: dist = pkg_resources.get_distribution('mic') # the real script is under EGG_INFO/scripts if dist.has_metadata('scripts/mic'): fp = os.path.join(dist.egg_info, "scripts/mic") - except: - pass + if fp: + return fp + # not found script if 'flat' egg installed try: - # not found script if 'flat' egg installed - if not fp: - fp = find_binary_path('mic') - except: + return find_binary_path('mic') + except errors.CreatorError: raise errors.BootstrapError("Can't find mic binary in host OS") - return fp def get_mic_modpath(): try: -- 2.34.1