uuidsetmapper.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from uuid import UUID
  2. from dataladmetadatamodel.mapper.gitmapper.objectreference import GitReference
  3. from dataladmetadatamodel.mapper.gitmapper.gitbackend.subprocess import (
  4. git_ls_tree,
  5. git_save_tree,
  6. git_update_ref
  7. )
  8. from dataladmetadatamodel.mapper.mapper import Mapper
  9. from dataladmetadatamodel.mapper.reference import Reference
  10. class UUIDSetGitMapper(Mapper):
  11. def map_in_impl(self,
  12. uuid_set: "UUIDSet",
  13. realm: str,
  14. reference: Reference) -> None:
  15. from dataladmetadatamodel.uuidset import UUIDSet
  16. from dataladmetadatamodel.versionlist import VersionList
  17. assert isinstance(uuid_set, UUIDSet)
  18. assert isinstance(realm, str)
  19. assert isinstance(reference, Reference)
  20. uuid_set.uuid_set = dict()
  21. for line in git_ls_tree(realm, reference.location):
  22. line_elements = line.split()
  23. version_list = VersionList(
  24. realm=realm,
  25. reference=Reference("VersionList", line_elements[2]))
  26. uuid_set.uuid_set[UUID(line_elements[3])] = version_list
  27. def map_out_impl(self,
  28. uuid_set: "UUIDSet",
  29. realm: str,
  30. force_write: bool) -> Reference:
  31. from dataladmetadatamodel.uuidset import UUIDSet
  32. assert isinstance(uuid_set, UUIDSet)
  33. tree_entries = [
  34. (
  35. "100644",
  36. "blob",
  37. version_list.write_out(realm).location,
  38. str(uuid)
  39. )
  40. for uuid, version_list in uuid_set.uuid_set.items()
  41. ]
  42. location = git_save_tree(realm, set(tree_entries))
  43. git_update_ref(realm, GitReference.UUID_SET.value, location)
  44. return Reference("UUIDSet", location)