[Erp5-report] r43170 kazuhiko - /erp5/trunk/products/ERP5/Tool/TemplateTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 8 13:24:21 CET 2011


Author: kazuhiko
Date: Tue Feb  8 13:24:21 2011
New Revision: 43170

URL: http://svn.erp5.org?rev=43170&view=rev
Log:
introduce sortDownloadedBusinessTemplateList() that will useful to make erp5_upgrader more automatic.

Modified:
    erp5/trunk/products/ERP5/Tool/TemplateTool.py

Modified: erp5/trunk/products/ERP5/Tool/TemplateTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/TemplateTool.py?rev=43170&r1=43169&r2=43170&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Tool/TemplateTool.py [utf8] Tue Feb  8 13:24:21 2011
@@ -994,6 +994,36 @@ class TemplateTool (BaseTool):
                         in sorted_bt_list]
       return sorted_bt_list
 
+    security.declareProtected(Permissions.AccessContentsInformation,
+                              'sortDownloadedBusinessTemplateList')
+    def sortDownloadedBusinessTemplateList(self, id_list):
+      """
+      Sort a list of already downloaded business templates according to
+      dependencies
+
+      id_list : list of business template's id in portal_templates.
+      """
+      def isDepend(a, b):
+        # return True if a depends on b.
+        dependency_list = [x.split(' ')[0] for x in a.getDependencyList()]
+        provision_list = list(b.getProvisionList()) + [b.getTitle()]
+        for i in provision_list:
+          if i in dependency_list:
+            return True
+          return False
+
+      sorted_bt_list = []
+      for bt_id in id_list:
+        bt = self._getOb(bt_id)
+        for j in range(len(sorted_bt_list)):
+          if isDepend(sorted_bt_list[j], bt):
+            sorted_bt_list.insert(j, bt)
+            break
+        else:
+           sorted_bt_list.append(bt)
+      sorted_bt_list = [bt.getId() for bt in sorted_bt_list]
+      return sorted_bt_list
+
     security.declareProtected( Permissions.AccessContentsInformation,
                                'getRepositoryBusinessTemplateList' )
     def getRepositoryBusinessTemplateList(self, update_only=False, **kw):



More information about the Erp5-report mailing list