From 2278a73752969f87e1c549b94beddc64af4e6d75 Mon Sep 17 00:00:00 2001 From: DeWitt Clinton Date: Tue, 29 Aug 2006 09:43:03 -0700 Subject: [PATCH 1/3] Clarify which module was not imported when a failure occurs. --- planet/shell/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/planet/shell/__init__.py b/planet/shell/__init__.py index ba8ea78..6ee2e94 100644 --- a/planet/shell/__init__.py +++ b/planet/shell/__init__.py @@ -13,9 +13,10 @@ def run(template_file, doc): base,ext = os.path.splitext(os.path.basename(template_resolved)) try: - module = __import__('planet/shell/' + ext[1:]) + module_path = os.path.join('planet', 'shell', ext[1:]) + module = __import__(module_path) except: - return log.error("Skipping template %s", template_resolved) + return log.error("Skipping template %s", module_path) log.info("Processing template %s", template_resolved) output_dir = planet.config.output_dir() From a31555899e4b52b2407b4b57b3cad9ace9ae3533 Mon Sep 17 00:00:00 2001 From: DeWitt Clinton Date: Tue, 29 Aug 2006 10:40:36 -0700 Subject: [PATCH 2/3] Corrected the message used when skipping a template due to failure to load the template module. --- planet/shell/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planet/shell/__init__.py b/planet/shell/__init__.py index 6ee2e94..47d8eae 100644 --- a/planet/shell/__init__.py +++ b/planet/shell/__init__.py @@ -16,9 +16,9 @@ def run(template_file, doc): module_path = os.path.join('planet', 'shell', ext[1:]) module = __import__(module_path) except: - return log.error("Skipping template %s", module_path) + return log.error("Skipping template '%s' after failing to load '%s'", template_resolved, module_path) log.info("Processing template %s", template_resolved) output_dir = planet.config.output_dir() output_file = os.path.join(output_dir, base) - module.run(template_resolved, doc, output_file) + template.run(template_resolved, doc, output_file) From 9af5a6e001a3ff23f00b6b6b7af8252426a33293 Mon Sep 17 00:00:00 2001 From: DeWitt Clinton Date: Tue, 29 Aug 2006 11:41:00 -0700 Subject: [PATCH 3/3] Renamed local variables to better represent intent. --- planet/shell/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/planet/shell/__init__.py b/planet/shell/__init__.py index 47d8eae..0847417 100644 --- a/planet/shell/__init__.py +++ b/planet/shell/__init__.py @@ -13,12 +13,14 @@ def run(template_file, doc): base,ext = os.path.splitext(os.path.basename(template_resolved)) try: - module_path = os.path.join('planet', 'shell', ext[1:]) - module = __import__(module_path) - except: - return log.error("Skipping template '%s' after failing to load '%s'", template_resolved, module_path) + template_module_name = os.path.join('planet', 'shell', ext[1:]) + template_module = __import__(template_module_name) + except ImportError, inst: + return log.error("Skipping template '%s' after failing to load '%s': %s", template_resolved, template_module_name, inst) + except Exception, inst: + return log.error("Unknown exception: %s", inst) - log.info("Processing template %s", template_resolved) + log.info("Processing template %s from %s", template_resolved, template_module_name) output_dir = planet.config.output_dir() output_file = os.path.join(output_dir, base) - template.run(template_resolved, doc, output_file) + template_module.run(template_resolved, doc, output_file)