Commit ab33c4a0 authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Remove useless functions based on old format of Business Manager

parent 06ac4c84
...@@ -2273,186 +2273,6 @@ class TemplateTool (BaseTool): ...@@ -2273,186 +2273,6 @@ class TemplateTool (BaseTool):
return error_list return error_list
security.declareProtected(Permissions.ManagePortal,
'createNewInstallationState')
def createNewInstallationState(self, bm_list, old_installation_state):
"""
Combines multiple BM to form single BM which would be the new
installtion state
"""
new_bm_list = bm_list[:]
# Create a list of path and hashes to be used for comparison
path_list = []
sha_list = []
forbidden_bm_title_list = ['Installation State',]
for bm in new_bm_list:
forbidden_bm_title_list.append(bm.title)
for item in bm.path_item_list:
path_list.append(item.path)
sha_list.append(item.sha)
installed_bm_list = [l for l
in self.getInstalledBusinessManagerList()
if l.title not in forbidden_bm_title_list]
new_bm_list.extend(installed_bm_list)
# Summation should also consider arithmetic on the Business Item(s)
# having same path and layer and combine them.
combinedBM = self.newContent(portal_type='Business Manager',
title='Combined Business Manager')
combinedBM.build()
new_bm_list.insert(0, combinedBM)
combinedBM = reduce(lambda x, y: x+y, new_bm_list)
final_path_list = combinedBM.getTemplatePathList()
final_path_item_list = []
final_path_item_list.extend(combinedBM._path_item_list)
removable_sha_list = []
removable_path_list = []
for item in old_installation_state._path_item_list:
if item.path in path_list and item.sha in sha_list:
# If there is Business Item which have no change on updation, then
# no need to reinstall it, cause in that case we prefer the changes
# at ZODB
# XXX: BAD DESIGN: Should compare both path as well as hash and keep
# them together in a dictionary,using them separately can lead to
# conflict in case two paths have same hash.
removable_sha_list.append(item.sha)
removable_path_list.append(item.path)
else:
# If there is update of path item, change the sign of the last
# version of that Business Item and add it to final_path_item_list
item.sign = -1
final_path_item_list.append(item)
final_path_list.extend(old_installation_state.getTemplatePathList())
# Remove the Business Item objects from final_path_item_list which have
# same sha and path
final_path_list = [path for path
in final_path_list
if path not in removable_path_list]
final_path_item_list = [item for item
in final_path_item_list
if item.sha not in removable_sha_list]
final_path_item_list.sort(key=lambda x: x.sign)
# Remove the old installation state
self._delObject(old_installation_state.getId())
combinedBM._setTemplatePathList(final_path_list)
combinedBM._path_item_list = final_path_item_list
# Change the title of the combined BM
combinedBM.setTitle('Installation State')
# XXX: We are missing the part of creating installed_BM for all the BM
# we have in bm_list, because this would be needed in case we build
# Business Manager again.
# Reduce the final Business Manager
#combinedBM.reduceBusinessManager()
return combinedBM
security.declareProtected(Permissions.ManagePortal,
'compareInstallationStateWithOFS')
def compareInstallationStateWithOFS(self, buildBM, new_installation_state,
old_installation_state):
"""
Compare the buildBM and to be installed BM and show the changes in a way
it can be notified or installed.
1. Compare the hash of the objects and create a diff file in case of
conflict
2. If forced installation, delete the old object and install the ones
from update Business Manager
Returns:
- has_confict: True , if there is a conflict between the 2 BMs
- DiffFile: In case there is conflict between the two states
"""
# XXX: BAD DESIGN: Should compare both path as well as hash, just path
# can lead to conflict in case two paths have same sha.
built_item_dict = {
item.path: item.sha for item
in buildBM._path_item_list
}
old_item_dict = {
item.path: item.sha for item
in old_installation_state._path_item_list
}
# For creating new_item_dict, we have to take use of template_path_list
# property as there can be case where we have path but not path_item as
# the new state already gets filtered while creation
new_item_dict = {
item.path: item.sha for item
in new_installation_state._path_item_list
if item.sign == 1
}
build_sha_list = built_item_dict.values()
final_item_list = []
for item in new_installation_state._path_item_list:
if item.sign == 1:
if path in old_item_dict.keys():
if old_item_dict[path] == item.sha:
pass
for item in new_installation_state._path_item_list:
if item.sha in build_sha_list and item.sign == 1:
# No need to install value which we already have
continue
else:
final_item_list.append(item)
new_installation_state._path_item_list = final_item_list
security.declareProtected(Permissions.ManagePortal,
'compareMultipleBusinessManager')
def compareBusinessManager(self, new_bm, old_bm):
"""
Compare two business manager and return a new Business manager based on
the difference. This is specially required to compare two versions of
Business Manager(s).
"""
compared_bm = new_bm - old_bm
# Return the subtraction of the Business Manager
return compared_bm
security.declareProtected(Permissions.ManagePortal,
'cleanInstallationState')
def cleanInstallationState(self, installation_state):
"""
Installation State is the Business Manager which has been installed
Cleaning means removal of all the Business Item with negative sign
**WARNING**:This should only be done after installing the Business Manager
"""
if installation_state.getStatus() != 'installed':
LOG('WARNING', 0, 'Trying to clean installation state before installing')
raise ValueError, "Can't clean before installing"
final_path_item_list = []
for item in installation_state._path_item_list:
if item.sign == 1:
final_path_item_list.append(item)
installation_state._path_item_list = final_path_item_list
def getInstalledBusinessManagerList(self): def getInstalledBusinessManagerList(self):
bm_list = self.objectValues(portal_type='Business Manager') bm_list = self.objectValues(portal_type='Business Manager')
installed_bm_list = [bm for bm in bm_list if bm.getStatus() == 'installed'] installed_bm_list = [bm for bm in bm_list if bm.getStatus() == 'installed']
......
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