Commit 4df1d2db authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Instead of raising error one by one, collect in error_list

parent 27afa42c
...@@ -33,6 +33,7 @@ from App.config import getConfiguration ...@@ -33,6 +33,7 @@ from App.config import getConfiguration
import os import os
import shutil import shutil
import sys import sys
import hashlib
from Acquisition import Implicit, Explicit from Acquisition import Implicit, Explicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -1752,12 +1753,15 @@ class TemplateTool (BaseTool): ...@@ -1752,12 +1753,15 @@ class TemplateTool (BaseTool):
installation_process._path_item_list = to_install_path_item_list installation_process._path_item_list = to_install_path_item_list
self.compareOldStateToOFS(installation_process, old_installation_state) error_list = self.compareOldStateToOFS(installation_process, old_installation_state)
# Change status of all BM installed # Change status of all BM installed
for bm in bm_list: for bm in bm_list:
bm.setStatus('installed') bm.setStatus('installed')
if error_list:
raise ValueError(' '.join(error_list))
installMultipleBusinessManager = updateInstallationState installMultipleBusinessManager = updateInstallationState
def compareOldStateToOFS(self, installation_process, old_state): def compareOldStateToOFS(self, installation_process, old_state):
...@@ -1772,20 +1776,20 @@ class TemplateTool (BaseTool): ...@@ -1772,20 +1776,20 @@ class TemplateTool (BaseTool):
try: try:
obj = portal.restrictedTraverse(path) obj = portal.restrictedTraverse(path)
obj_sha = hashlib.sha256(obj.toXML()).hexdigest() obj_sha = hashlib.sha256(obj.asXML()).hexdigest()
# Get item at old state # Get item at old state
old_item = old_state.getBusinessItemByPath() old_item = old_state.getBusinessItemByPath(path)
# Check if there is an object at old state at this path # Check if there is an object at old state at this path
if old_item: if old_item:
# Compare hash with ZODB # Compare hash with ZODB
if old_item._sha == obj._sha: if old_item._sha == obj_sha:
# No change at ZODB on old item, so get the new item # No change at ZODB on old item, so get the new item
new_item = installation_process.getBusinessItemByPath(path) new_item = installation_process.getBusinessItemByPath(path)
# Compare new item hash with ZODB # Compare new item hash with ZODB
if new_item._sha == obj._sha: if new_item._sha == obj_sha:
# If same hash, do nothing # If same hash, do nothing
continue continue
...@@ -1798,28 +1802,26 @@ class TemplateTool (BaseTool): ...@@ -1798,28 +1802,26 @@ class TemplateTool (BaseTool):
new_item = installation_process.getBusinessItemByPath(path) new_item = installation_process.getBusinessItemByPath(path)
# Compare new item hash with ZODB # Compare new item hash with ZODB
if new_item._sha == obj._sha: if new_item._sha == obj_sha:
# If same hash, do nothing # If same hash, do nothing
continue continue
else: else:
# Raise error # Raise error
error_list.append('Trying to remove changes at ZODB at %s' % path) error_list.append('Trying to remove changes at ZODB at %s' % path)
raise ValueError('Trying to remove changes at ZODB at %s' % path)
else: else:
# Object created at ZODB by the user # Object created at ZODB by the user
# Compare with the new_item # Compare with the new_item
new_item = installation_process.getBusinessItemByPath(path) new_item = installation_process.getBusinessItemByPath(path)
if new_item._sha == obj._sha: if new_item._sha == obj_sha:
# If same hash, do nothing # If same hash, do nothing
continue continue
else: else:
# Raise error # Raise error
error_list.append('Trying to remove changes at ZODB at %s' % path) error_list.append('Trying to remove changes at ZODB at %s' % path)
raise ValueError('Trying to remove changes at ZODB at %s' % path)
except Exception: except Exception:
# Get item at old state # Get item at old state
...@@ -1834,13 +1836,14 @@ class TemplateTool (BaseTool): ...@@ -1834,13 +1836,14 @@ class TemplateTool (BaseTool):
if new_item._sign == 1: if new_item._sign == 1:
error_list.append('Object at %s removed by user' % path) error_list.append('Object at %s removed by user' % path)
raise ValueError('Object at %s removed by user' % path)
else: else:
# If there is no item at old state, install the new_item # If there is no item at old state, install the new_item
new_item = installation_process.getBusinessItemByPath(path) new_item = installation_process.getBusinessItemByPath(path)
new_item.install(installation_process) new_item.install(installation_process)
return error_list
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'createNewInstallationState') 'createNewInstallationState')
def createNewInstallationState(self, bm_list, old_installation_state): def createNewInstallationState(self, bm_list, old_installation_state):
......
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