Commit 80edb1d2 authored by Rafael Monnerat's avatar Rafael Monnerat

Refactor installBusinessTemplateListFromRepository to resolve dependencies and use activities

This method was refactored to:
 - automatically resolve and install business templates dependencies if requested.
 - Make possible use activities and prevent long transactions.
parent 10f77173
...@@ -1226,12 +1226,13 @@ class TemplateTool (BaseTool): ...@@ -1226,12 +1226,13 @@ class TemplateTool (BaseTool):
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'installBusinessTemplatesFromRepositories') 'installBusinessTemplatesFromRepositories')
def installBusinessTemplatesFromRepositories(self, template_list, def installBusinessTemplatesFromRepositories(self, template_list,
only_newer=True, update_catalog=_MARKER): only_newer=True, update_catalog=_MARKER, activate=False,
install_dependency=False):
"""Deprecated. """Deprecated.
""" """
DeprecationWarning('getInstalledBusinessTemplatesList is deprecated; Use getInstalledBusinessTemplateList instead.', DeprecationWarning) DeprecationWarning('getInstalledBusinessTemplatesList is deprecated; Use getInstalledBusinessTemplateList instead.', DeprecationWarning)
return self.installBusinessTemplateListFromRepository(template_list, return self.installBusinessTemplateListFromRepository(template_list,
only_newer, update_catalog, activate=False) only_newer, update_catalog, activate, install_dependency)
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'resolveBusinessTemplateListDependency') 'resolveBusinessTemplateListDependency')
...@@ -1287,32 +1288,44 @@ class TemplateTool (BaseTool): ...@@ -1287,32 +1288,44 @@ class TemplateTool (BaseTool):
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'installBusinessTemplateListFromRepository') 'installBusinessTemplateListFromRepository')
def installBusinessTemplateListFromRepository(self, template_list, def installBusinessTemplateListFromRepository(self, template_list,
only_newer=True, update_catalog=_MARKER, activate=False): only_newer=True, update_catalog=_MARKER, activate=False,
install_dependency=False):
"""Installs template_list from configured repositories by default only newest""" """Installs template_list from configured repositories by default only newest"""
# XXX-Luke: This method could replace # XXX-Luke: This method could replace
# TemplateTool_installRepositoryBusinessTemplateList while still being # TemplateTool_installRepositoryBusinessTemplateList while still being
# possible to reuse by external callers # possible to reuse by external callers
opreation_log = []
template_dict = self._getBusinessTemplateUrlDict(only_newer) operation_log = []
for template_name in template_list: resolved_template_list = self.resolveBusinessTemplateListDependency(
if template_name in template_dict: template_list, newest_only=only_newer)
installed_bt = self.getInstalledBusinessTemplate(template_name)
if installed_bt is None or not only_newer or \ if not install_dependency:
installed_bt.getRevision() < template_dict[ missing_dependency_list = [i[1] for i in resolved_template_list
template_name]['revision']: if i[1].replace(".bt5", "") not in template_list]
template_document = self.download(template_dict[template_name][ if len(missing_dependency_list) > 0:
'url']) raise BusinessTemplateMissingDependency,\
if update_catalog is _MARKER: "Impossible to install, please install the following dependencies before: %s" \
template_document.install() % missing_dependency_list
else:
template_document.install(update_catalog=update_catalog) activate_kw = dict(activity="SQLQueue", tag="start_%s" % (time.time()))
opreation_log.append('Installed %s with revision %s' % ( for repository, bt_id in resolved_template_list:
template_document.getTitle(), template_document.getRevision())) bt_url = '%s/%s' % (repository, bt_id)
else: param_dict = dict(download_url=bt_url, only_newer=only_newer)
opreation_log.append('Skipped %s' % template_name) if update_catalog is not _MARKER:
param_dict["update_catalog"] = update_catalog
if activate:
self.activate(**activate_kw).\
updateBusinessTemplateFromUrl(**param_dict)
activate_kw["after_tag"] = activate_kw["tag"]
activate_kw["tag"] = bt_id
operation_log.append('Installed %s using activities' % (bt_id))
else: else:
opreation_log.append('Not found in repositories %s' % template_name) document = self.updateBusinessTemplateFromUrl(**param_dict)
return opreation_log operation_log.append('Installed %s with revision %s' % (
document.getTitle(), document.getRevision()))
return operation_log
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'updateBusinessTemplateFromUrl') 'updateBusinessTemplateFromUrl')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment