From 0ad342c4ec5d281e74a049b37d63541607e54efc Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Thu, 17 Feb 2011 15:34:38 +0000
Subject: [PATCH] display a more useful message in case of missing
 dependencies.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43437 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py  | 13 ++++++++++---
 product/ERP5Type/tests/ERP5TypeTestCase.py |  8 +++-----
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index c754f51eb7..be9a26a30a 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -5230,9 +5230,17 @@ Business Template is a set of definitions, such as skins, portal types and categ
        are installed. Raise an exception with the list of
        missing dependencies if some are missing
       """
+      missing_dep_list = self.getMissingDependencyList()
+      if len(missing_dep_list) != 0:
+        raise BusinessTemplateMissingDependency, 'Impossible to install, please install the following dependencies before: %s'%repr(missing_dep_list)
+
+    def getMissingDependencyList(self):
+      """
+      Retuns a list of missing dependencies.
+      """
       missing_dep_list = []
       dependency_list = self.getDependencyList()
-      if len(dependency_list)!=0:
+      if len(dependency_list) > 0:
         for dependency_couple in dependency_list:
           dependency_couple_list = dependency_couple.strip().split(' ', 1)
           dependency = dependency_couple_list[0]
@@ -5250,8 +5258,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
                   or (version_restriction not in (None, '') and
                      (not self.portal_templates.compareVersionStrings(installed_bt.getVersion(), version_restriction)))):
             missing_dep_list.append((dependency, version_restriction or ''))
-      if len(missing_dep_list) != 0:
-        raise BusinessTemplateMissingDependency, 'Impossible to install, please install the following dependencies before: %s'%repr(missing_dep_list)
+      return [' '.join([y for y in x if y]) for x in missing_dep_list]
 
     def diffObjectAsHTML(self, REQUEST, **kw):
       """
diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py
index ee5f1c8bcb..e8e28a3650 100644
--- a/product/ERP5Type/tests/ERP5TypeTestCase.py
+++ b/product/ERP5Type/tests/ERP5TypeTestCase.py
@@ -74,7 +74,6 @@ from zLOG import LOG, DEBUG
 
 from Products.ERP5Type.tests.backportUnittest import SetupSiteError
 from Products.ERP5Type.tests.utils import DummyMailHostMixin, parseListeningAddress
-from Products.ERP5.Document.BusinessTemplate import BusinessTemplateMissingDependency
 
 # Quiet messages when installing products
 install_product_quiet = 1
@@ -897,10 +896,9 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
           ZopeTestCase._print('(imported in %.3fs) ' % (time.time() - start))
           # For unit test, we accept installing business templates with
           # missing a part of dependencies.
-          try:
-            bt.checkDependencies()
-          except BusinessTemplateMissingDependency:
-            ZopeTestCase._print('(some dependencies are missing) ')
+          missing_dep_list = bt.getMissingDependencyList()
+          if len(missing_dep_list) > 0:
+            ZopeTestCase._print('(missing dependencies : %r) ' % missing_dep_list)
         install_kw = None
         if get_install_kw:
           install_kw = {}
-- 
2.30.9