Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dummy.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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)