Commit 5f38c5ce authored by Sebastien Robin's avatar Sebastien Robin Committed by Rafael Monnerat

improve dependency calculation and delete orphaned bt

- when upgradeSite is called, it will delete orphaned bt is we set
  delete_orphaned to true
- when there is provider calculation in the dependency list, look
  at both installed bt and to all the dependency tree
parent 920bbe5f
...@@ -1050,7 +1050,7 @@ class TemplateTool (BaseTool): ...@@ -1050,7 +1050,7 @@ class TemplateTool (BaseTool):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getRepositoryBusinessTemplateList' ) 'getRepositoryBusinessTemplateList' )
def getRepositoryBusinessTemplateList(self, update_only=False, def getRepositoryBusinessTemplateList(self, update_only=False,
template_list=None): template_list=None, **kw):
"""Get the list of Business Templates in repositories. """Get the list of Business Templates in repositories.
update_only: return only bt that needs to be updated update_only: return only bt that needs to be updated
...@@ -1240,39 +1240,42 @@ class TemplateTool (BaseTool): ...@@ -1240,39 +1240,42 @@ class TemplateTool (BaseTool):
template_title_list.remove(available_bt5.title) template_title_list.remove(available_bt5.title)
bt5 = self.decodeRepositoryBusinessTemplateUid(available_bt5.uid) bt5 = self.decodeRepositoryBusinessTemplateUid(available_bt5.uid)
bt5_set.add(bt5) bt5_set.add(bt5)
meta_dependency_set = set()
for dep_repository, dep_id in self.getDependencyList(bt5): for dep_repository, dep_id in self.getDependencyList(bt5):
if dep_repository != 'meta': if dep_repository != 'meta':
bt5_set.add((dep_repository, dep_id)) bt5_set.add((dep_repository, dep_id))
else: else:
provider_list = self.getProviderList(dep_id) meta_dependency_set.add((dep_repository, dep_id))
provider_installed = False for dep_repository, dep_id in meta_dependency_set:
provider_title = None provider_list = self.getProviderList(dep_id)
for provider in provider_list: provider_installed = False
if provider in [i[1].replace(".bt5", "") for i in bt5_set] or \ provider_title = None
provider in installed_bt5_title_list or \ for provider in provider_list:
provider in template_title_list: if provider in [i[1].replace(".bt5", "") for i in bt5_set] or \
provider_title = provider provider in installed_bt5_title_list or \
for candidate in available_bt5_list: provider in template_title_list:
if candidate.title == provider: provider_title = provider
bt5_set.add(\
self.decodeRepositoryBusinessTemplateUid(
candidate.uid))
break
break
if provider_title is None and len(provider_list) == 1:
provider_title = provider_list[0]
LOG('resolveBT, provider_title', 0, provider_title)
if provider_title:
for candidate in available_bt5_list: for candidate in available_bt5_list:
if candidate.title == provider_title: if candidate.title == provider:
bt5_set.add(\ bt5_set.add(\
self.decodeRepositoryBusinessTemplateUid( self.decodeRepositoryBusinessTemplateUid(
candidate.uid)) candidate.uid))
break break
else: break
raise BusinessTemplateMissingDependency,\ if provider_title is None and len(provider_list) == 1:
"Unable to resolve dependencies for %s, options are %s" \ provider_title = provider_list[0]
% (dep_id, provider_list) LOG('resolveBT, provider_title', 0, provider_title)
if provider_title:
for candidate in available_bt5_list:
if candidate.title == provider_title:
bt5_set.add(\
self.decodeRepositoryBusinessTemplateUid(
candidate.uid))
break
else:
raise BusinessTemplateMissingDependency,\
"Unable to resolve dependencies for %s, options are %s" \
% (dep_id, provider_list)
if len(template_title_list) > 0: if len(template_title_list) > 0:
raise BusinessTemplateUnknownError, 'The Business Template %s could not be found on repositories %s' % \ raise BusinessTemplateUnknownError, 'The Business Template %s could not be found on repositories %s' % \
...@@ -1475,7 +1478,9 @@ class TemplateTool (BaseTool): ...@@ -1475,7 +1478,9 @@ class TemplateTool (BaseTool):
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'upgradeSite') 'upgradeSite')
def upgradeSite(self, bt5_list, deprecated_after_script_dict=None, def upgradeSite(self, bt5_list, deprecated_after_script_dict=None,
deprecated_reinstall_set=None, dry_run=False): deprecated_reinstall_set=None, dry_run=False,
delete_orphaned=False,
keep_bt5_id_set=None):
""" """
Upgrade many business templates at a time. bt5_list should Upgrade many business templates at a time. bt5_list should
contains only final business templates, then all dependencies contains only final business templates, then all dependencies
...@@ -1483,10 +1488,9 @@ class TemplateTool (BaseTool): ...@@ -1483,10 +1488,9 @@ class TemplateTool (BaseTool):
old business templates will be updated, and orphelin business old business templates will be updated, and orphelin business
templates will be deleted templates will be deleted
deprecated_after_script_dict: this parameter needs to be removed keep_bt5_id_set: business template that should not be deleted.
by setting it at business template level. This is useful if we want to keep an old business
It list script to run when, like template without updating it and without removing it
{"foo": ('script1','script2')}
deprecated_reinstall_set: this parameter needs to be removed deprecated_reinstall_set: this parameter needs to be removed
by setting it at business template level. by setting it at business template level.
...@@ -1497,7 +1501,6 @@ class TemplateTool (BaseTool): ...@@ -1497,7 +1501,6 @@ class TemplateTool (BaseTool):
self.updateRepositoryBusinessTemplateList(self.getRepositoryList()) self.updateRepositoryBusinessTemplateList(self.getRepositoryList())
# do upgrade # do upgrade
message_list = [] message_list = []
deprecated_after_script_dict = deprecated_after_script_dict or {}
deprecated_reinstall_set = deprecated_reinstall_set or set() deprecated_reinstall_set = deprecated_reinstall_set or set()
def append(message): def append(message):
message_list.append(message) message_list.append(message)
...@@ -1516,15 +1519,24 @@ class TemplateTool (BaseTool): ...@@ -1516,15 +1519,24 @@ class TemplateTool (BaseTool):
if not(dry_run): if not(dry_run):
bt5_url = "%s/%s" % (bt5.repository, bt5.title) bt5_url = "%s/%s" % (bt5.repository, bt5.title)
self.updateBusinessTemplateFromUrl(bt5_url) self.updateBusinessTemplateFromUrl(bt5_url)
for after_script in deprecated_after_script_dict.get(bt5.title, []): if delete_orphaned:
append("After business template %s call %s" % \ if keep_bt5_id_set is None:
(bt5.title, after_script)) keep_bt5_id_set = set()
script = getattr(self, after_script, None) to_remove_bt5_list = [x for x in self.getInstalledBusinessTemplateList()
if script is None: if x.title not in dependency_list]
raise ValueError, "Unable to find after script %r of bt %s" % \ sorted_to_remove_bt5_id_list = self.sortDownloadedBusinessTemplateList(
(script, bt5.title) [x.id for x in to_remove_bt5_list])
sorted_to_remove_bt5_id_list.reverse()
to_remove_bt5_list.sort(
key=lambda x: sorted_to_remove_bt5_id_list.index(x.id))
for bt in to_remove_bt5_list:
if bt.title in keep_bt5_id_set:
continue
append("Uninstall business template %s" % bt.title)
if not(dry_run): if not(dry_run):
script() # XXX Here is missing parameters to really remove stuff
bt.uninstall()
return message_list return message_list
InitializeClass(TemplateTool) InitializeClass(TemplateTool)
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