説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

dummy.py 2.3KB

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