Commit b3e4561c authored by Julien Muchembled's avatar Julien Muchembled

Simplify code in TemplateTool.updateBusinessTemplateFromUrl

parent 79a2aaf5
...@@ -1291,30 +1291,23 @@ class TemplateTool (BaseTool): ...@@ -1291,30 +1291,23 @@ class TemplateTool (BaseTool):
log("Installing %s ..." % download_url) log("Installing %s ..." % download_url)
imported_bt5 = self.download(url = download_url, id = id) imported_bt5 = self.download(url = download_url, id = id)
bt_title = imported_bt5.getTitle() bt_title = imported_bt5.getTitle()
BusinessTemplate_getModifiedObject = \
aq_base(getattr(self, 'BusinessTemplate_getModifiedObject'))
if not reinstall: if not reinstall:
listbox_object_list = BusinessTemplate_getModifiedObject.__of__(imported_bt5)()
install_kw = {}
previous_bt5 = self.getInstalledBusinessTemplate(bt_title) previous_bt5 = self.getInstalledBusinessTemplate(bt_title)
if previous_bt5 is not None: if previous_bt5 is not None:
try: try:
imported_revision = int(imported_bt5.getRevision()) imported_revision = int(imported_bt5.getRevision())
except ValueError:
imported_revision = None
try:
previous_revision = int(previous_bt5.getRevision()) previous_revision = int(previous_bt5.getRevision())
except ValueError: if imported_revision <= previous_revision:
previous_revision = None log("%s is already installed with revision %i, which is same or "
if imported_revision is not None and imported_revision is not None \ "newer revision than new revision %i." % (bt_title,
and (imported_revision <= previous_revision): previous_revision, imported_revision))
log("%s is already installed with revision %r, which is same or "
"newer revision then new revision %r." % (bt_title,
previous_bt5.getRevision(), imported_bt5.getRevision()))
return imported_bt5 return imported_bt5
except ValueError:
pass
for listbox_line in listbox_object_list: install_kw = {}
for listbox_line in imported_bt5.BusinessTemplate_getModifiedObject():
item = listbox_line.object_id item = listbox_line.object_id
state = listbox_line.object_state state = listbox_line.object_state
if state.startswith('Removed'): if state.startswith('Removed'):
...@@ -1326,27 +1319,17 @@ class TemplateTool (BaseTool): ...@@ -1326,27 +1319,17 @@ class TemplateTool (BaseTool):
maybe_moved and ' (moved to %s ?)' % maybe_moved)) maybe_moved and ' (moved to %s ?)' % maybe_moved))
else: else:
installed_dict[item] = bt_title installed_dict[item] = bt_title
# Calculate keep logic, by following the default
keep = False
in_force_keep_list = True
if state in ('Modified but should be kept',
'Removed but should be kept') and item not in force_keep_list:
# For actions which suggest that item shall be kept and item is not # For actions which suggest that item shall be kept and item is not
# explicitely forced, keep the default -- do nothing # explicitely forced, keep the default -- do nothing
keep = True in_force_keep_list = item in force_keep_list or state not in (
in_force_keep_list = False 'Modified but should be kept', 'Removed but should be kept')
in_keep_original_list = False
if item in keep_original_list:
# If item is forced to be untouched, do not touch it # If item is forced to be untouched, do not touch it
keep = True if item in keep_original_list or not in_force_keep_list:
in_keep_original_list = True if in_force_keep_list:
log('Item %r is in force_keep_list and keep_original_list,'
if in_force_keep_list and in_keep_original_list: ' as keep_original_list has precedence item is NOT MODIFIED'
log('Item %r is in force_keep_list and keep_original_list, as ' % item)
'keep_original_list has precedence item is NOT MODIFIED' % item)
if keep == True:
install_kw[item] = 'nothing' install_kw[item] = 'nothing'
else: else:
install_kw[item] = listbox_line.choice_item_list[0][1] install_kw[item] = listbox_line.choice_item_list[0][1]
......
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