Skip to content

Commit

Permalink
stateengine plugin: improve order handling (set correct order values …
Browse files Browse the repository at this point in the history
…in beginning, improve copied states for released_by attribute
  • Loading branch information
onkelandy committed Oct 27, 2023
1 parent b9c0c07 commit ed1ce48
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions stateengine/StateEngineItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,27 +1124,52 @@ def __reorder_states(self, init=True):
self.__logger.info("Recalculating state order. Current order: {}", self.__states)
_copied_states = {}
_add_order = 0
_changed_orders = []
for i, state in enumerate(self.__states, 1):
try:
_original_order = state.order
_issue = None
if state.is_copy_for and state not in _copied_states:
_order = i
_add_order += 1
_order = i - 0.01
_copied_states[state] = _order
self.__logger.develop("State {} is copy, set to {}", state, _order)
else:
_issue = state.update_order()
_order = state.order
if _order != _original_order:
_changed_orders.append(_order)
_add_order -= 1
self.__logger.develop("State {} changed order: {},"
" i: {} add order: {}.",
state, _order, i, _add_order)
elif any(_order < value for value in _changed_orders):
_order = i + _add_order
_issue = state.update_order(_order)
self.__logger.develop("State {} smaller, order: {},"
" i: {} add order: {}.",
state, _order, i, _add_order)
elif any(_order == value for value in _changed_orders):
_order = i + _add_order
_issue = state.update_order(_order)
self.__logger.develop("State {} equal, order: {},"
" i: {} add order: {}.",
state, _order, i, _add_order)
_add_order += 1
else:
self.__logger.develop("State {} order: {},"
" i: {} add order: {}.",
state, _order, i, _add_order)
if _issue not in [[], None, [None]]:
self.__config_issues.update({state.id: {'issue': _issue, 'attribute': 'se_stateorder'}})
self.__logger.warning("Issue while getting state order: {}, using original order {}", _issue, _original_order)
self.__logger.warning("Issue while getting state order: {},"
" using original order {}", _issue, _original_order)
_order = _original_order
state.update_order(_original_order)
elif _copied_states.get(state) and _copied_states.get(state) > _order:
_reordered_states.remove((_copied_states.get(state), state))
state.is_copy_for = None
_add_order -= 1
elif state not in _copied_states:
elif state not in _copied_states and init is False:
_order += _add_order
_reordered_states.append((_order, state))
except Exception as ex:
Expand All @@ -1170,8 +1195,10 @@ def __initialize_state(self, item_state, _statecount):
_state = StateEngineState.SeState(self, item_state)
_issue = _state.update_order(_statecount)
if _issue:
self.__config_issues.update({item_state.property.path: {'issue': _issue, 'attribute': 'se_stateorder'}})
self.__logger.error("Issue with state {0} while setting order: {1}", item_state.property.path, _issue)
self.__config_issues.update({item_state.property.path:
{'issue': _issue, 'attribute': 'se_stateorder'}})
self.__logger.error("Issue with state {0} while setting order: {1}",
item_state.property.path, _issue)
self.__states.append(_state)
self.__state_ids.update({item_state.property.path: _state})
self.__logger.info("Appended state {}", item_state.property.path)
Expand All @@ -1183,12 +1210,14 @@ def __initialize_state(self, item_state, _statecount):
except ValueError as ex:
self.update_issues('state', {item_state.property.path: {'issue': ex, 'issueorigin':
[{'conditionset': 'None', 'condition': 'ValueError'}]}})
self.__logger.error("Ignoring state {0} because ValueError: {1}", item_state.property.path, ex)
self.__logger.error("Ignoring state {0} because ValueError: {1}",
item_state.property.path, ex)
return _statecount
except Exception as ex:
self.update_issues('state', {item_state.property.path: {'issue': ex, 'issueorigin':
[{'conditionset': 'None', 'condition': 'GeneralError'}]}})
self.__logger.error("Ignoring state {0} because: {1}", item_state.property.path, ex)
self.__logger.error("Ignoring state {0} because: {1}",
item_state.property.path, ex)
return _statecount

def __finish_states(self):
Expand Down

0 comments on commit ed1ce48

Please sign in to comment.