__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from collections import defaultdict
  2. from typing import (
  3. DefaultDict,
  4. Dict
  5. )
  6. from .gitmapper import GIT_MAPPER_LOCATIONS
  7. git_mapper_family_name = "git"
  8. locations = {
  9. git_mapper_family_name: GIT_MAPPER_LOCATIONS
  10. }
  11. registered_mapper: DefaultDict[str, Dict[str, "Mapper"]] = defaultdict(dict)
  12. def _get_locations(mapper_family: str):
  13. return locations.get(mapper_family, (None, None))
  14. def get_uuid_set_location(mapper_family: str):
  15. return _get_locations(mapper_family)[1]
  16. def get_tree_version_list_location(mapper_family: str):
  17. return _get_locations(mapper_family)[0]
  18. def get_mapper(class_name: str, backend_type: str) -> "Mapper":
  19. return registered_mapper[backend_type][class_name]
  20. def set_mapper(class_name: str, backend_type: str, mapper: "Mapper"):
  21. registered_mapper[backend_type][class_name] = mapper
  22. def initialize_object_store():
  23. from .gitmapper.metadatamapper import MetadataGitMapper
  24. from .gitmapper.metadatarootrecordmapper import MetadataRootRecordGitMapper
  25. from .gitmapper.mtreenodemapper import MTreeNodeGitMapper
  26. from .gitmapper.textmapper import TextGitMapper
  27. from .gitmapper.uuidsetmapper import UUIDSetGitMapper
  28. from .gitmapper.versionlistmapper import (
  29. TreeVersionListGitMapper,
  30. VersionListGitMapper
  31. )
  32. set_mapper("DatasetTree", "git", MTreeNodeGitMapper("MTreeNode"))
  33. set_mapper("FileTree", "git", MTreeNodeGitMapper("MTreeNode"))
  34. set_mapper("Metadata", "git", MetadataGitMapper("Metadata"))
  35. set_mapper("MetadataRootRecord", "git", MetadataRootRecordGitMapper("MetadataRootRecord"))
  36. set_mapper("MTreeNode", "git", MTreeNodeGitMapper("MTreeNode"))
  37. set_mapper("Text", "git", TextGitMapper("Text"))
  38. set_mapper("TreeVersionList", "git", TreeVersionListGitMapper("TreeVersionList"))
  39. set_mapper("UUIDSet", "git", UUIDSetGitMapper("UUIDSet"))
  40. set_mapper("VersionList", "git", VersionListGitMapper("VersionList"))
  41. initialize_object_store()