Ingen beskrivning
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.

migrationhandler.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. ## @package lodel.datasource.migrationhandler.generic
  3. # @brief A generic migration handler
  4. #
  5. # According to it, every moditification is possible
  6. #
  7. ## Manage model changes
  8. class GenericMigrationHandler(object):
  9. def __init__(self, debug=False):
  10. self.debug = debug
  11. ## @brief Records a change in the EditorialModel and indicates whether or not it is possible to make it
  12. # @note The states (initial_state and new_state) contains only fields that changes
  13. def register_change(self, em, uid, initial_state, new_state):
  14. if self.debug:
  15. print("\n##############")
  16. print("GenericMigrationHandler debug. Changes for component with uid %s :" % uid)
  17. if initial_state is None:
  18. print("Component creation (uid = %s): \n\t" % uid, new_state)
  19. elif new_state is None:
  20. print("Component deletion (uid = %s): \n\t" % uid, initial_state)
  21. else:
  22. field_list = set(initial_state.keys()).union(set(new_state.keys()))
  23. for field_name in field_list:
  24. str_chg = "\t%s " % field_name
  25. if field_name in initial_state:
  26. str_chg += "'" + str(initial_state[field_name]) + "'"
  27. else:
  28. str_chg += " creating "
  29. str_chg += " => "
  30. if field_name in new_state:
  31. str_chg += "'" + str(new_state[field_name]) + "'"
  32. else:
  33. str_chg += " deletion "
  34. print(str_chg)
  35. print("##############\n")
  36. ## @brief Not usefull for the moment
  37. def register_model_state(self, em, state_hash):
  38. if self.debug:
  39. print("New EditorialModel state registered : '%s'" % state_hash)