From 16d0f04d00aa04cc57fdb00ac793e49d875a5547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com> Date: Thu, 1 Apr 2010 13:13:58 +0000 Subject: [PATCH] - implement simple method to automatically install required list of Business Templates from repositories git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34245 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Tool/TemplateTool.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py index 3ccc096182..15a25e8009 100644 --- a/product/ERP5/Tool/TemplateTool.py +++ b/product/ERP5/Tool/TemplateTool.py @@ -992,4 +992,41 @@ class TemplateTool (BaseTool): return 0 + def _getBusinessTemplateUrlDict(self): + business_template_url_dict = {} + for bt in self.getRepositoryBusinessTemplateList(): + url, name = self.decodeRepositoryBusinessTemplateUid(bt.getUid()) + business_template_url_dict[name[:-4]] = { + 'url': '%s/%s' % (url, name), + 'revision': bt.getRevision() + } + return business_template_url_dict + + security.declareProtected(Permissions.ManagePortal, + 'installBusinessTemplatesFromRepositories' ) + def installBusinessTemplatesFromRepositories(self, template_list, + only_newer=True): + """Installs template_list from configured repositories by default only newest""" + # XXX-Luke: This method could replace + # TemplateTool_installRepositoryBusinessTemplateList while still being + # possible to reuse by external callers + opreation_log = [] + template_dict = self._getBusinessTemplateUrlDict() + for template_name in template_list: + if template_name in template_dict: + installed_bt = self.getInstalledBusinessTemplate(template_name) + if installed_bt is None or not only_newer or \ + installed_bt.getRevision() < template_dict[ + template_name]['revision']: + template_document = self.download(template_dict[template_name][ + 'url']) + template_document.install() + opreation_log.append('Installed %s with revision %s' % ( + template_document.getTitle(), template_document.getRevision())) + else: + opreation_log.append('Skipped %s' % template_name) + else: + opreation_log.append('Not found in repositories %s' % template_name) + return opreation_log + InitializeClass(TemplateTool) -- 2.30.9