No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dummy.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. ## Manage Model changes
  3. class DummyMigrationHandler(object):
  4. def __init__(self, debug = False):
  5. self.debug = debug
  6. ## @brief Record a change in the EditorialModel and indicate wether or not it is possible to make it
  7. # @note The states ( initial_state and new_state ) contains only fields that changes
  8. # @param uid int : The uid of the change EmComponent
  9. # @param initial_state dict | None : dict with field name as key and field value as value. Representing the original state. None mean creation of a new component.
  10. # @param new_state dict | None : dict with field name as key and field value as value. Representing the new state. None mean component deletion
  11. # @throw EditorialModel.exceptions.MigrationHandlerChangeError if the change was refused
  12. def register_change(self, uid, initial_state, new_state):
  13. if self.debug:
  14. print("\n##############")
  15. print("DummyMigrationHandler debug. Changes for component with uid %d :"%uid)
  16. if initial_state is None:
  17. print("Component creation (uid = %d): \n\t"%uid,new_state)
  18. elif new_state is None:
  19. print("Component deletion (uid = %d): \n\t"%uid,initial_state)
  20. else:
  21. field_list = set(initial_state.keys()).union(set(new_state.keys()))
  22. for field_name in field_list:
  23. str_chg = "\t%s "%field_name
  24. if field_name in initial_state:
  25. str_chg += "'"+str(initial_state[field_name])+"'"
  26. else:
  27. str_chg += " creating "
  28. str_chg += " => "
  29. if field_name in new_state:
  30. str_chg += "'"+str(new_state[field_name])+"'"
  31. else:
  32. str_chg += " deletion "
  33. print(str_chg)
  34. print("##############\n")
  35. pass
  36. def register_model_state(self, state_hash):
  37. if self.debug:
  38. print("New EditorialModel state registered : '%s'"%state_hash)