Commit d06e997a authored by Sebastien Robin's avatar Sebastien Robin

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 bf9cadf7
...@@ -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,10 +1240,13 @@ class TemplateTool (BaseTool): ...@@ -1240,10 +1240,13 @@ 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:
meta_dependency_set.add((dep_repository, dep_id))
for dep_repository, dep_id in meta_dependency_set:
provider_list = self.getProviderList(dep_id) provider_list = self.getProviderList(dep_id)
provider_installed = False provider_installed = False
provider_title = None provider_title = None
...@@ -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