textmapper.py 1005 B

123456789101112131415161718192021222324252627282930313233343536
  1. from dataladmetadatamodel.mapper.gitmapper.gitbackend.subprocess import (
  2. git_load_str,
  3. git_save_str
  4. )
  5. from dataladmetadatamodel.mapper.mapper import Mapper
  6. from dataladmetadatamodel.mapper.reference import Reference
  7. class TextGitMapper(Mapper):
  8. def map_in_impl(self,
  9. text: "Text",
  10. realm: str,
  11. reference: Reference) -> None:
  12. from ...text import Text
  13. assert isinstance(text, Text)
  14. assert isinstance(reference, Reference)
  15. assert reference.class_name == "Text"
  16. text.content = git_load_str(realm, reference.location)
  17. # TODO: what about the references?
  18. def map_out_impl(self,
  19. text: "Text",
  20. realm: str,
  21. force_write: bool) -> Reference:
  22. from ...text import Text
  23. assert isinstance(text, Text)
  24. text_location = git_save_str(realm, text.content)
  25. return Reference("Text", text_location)