Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

datasettree.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from typing import (
  2. List,
  3. Optional,
  4. Tuple
  5. )
  6. from dataladmetadatamodel.metadatapath import MetadataPath
  7. from dataladmetadatamodel.metadatarootrecord import MetadataRootRecord
  8. from dataladmetadatamodel.mtreenode import MTreeNode
  9. from dataladmetadatamodel.mtreeproxy import MTreeProxy
  10. from dataladmetadatamodel.mapper.reference import Reference
  11. datalad_root_record_name = ".datalad_metadata_root_record"
  12. class DatasetTree(MTreeProxy):
  13. def __init__(self,
  14. mtree: Optional[MTreeNode] = None,
  15. reference: Optional[Reference] = None):
  16. assert isinstance(mtree, (type(None), MTreeNode))
  17. assert isinstance(reference, (type(None), Reference))
  18. super().__init__(MetadataRootRecord, mtree, reference)
  19. def __contains__(self, path: MetadataPath) -> bool:
  20. return self.mtree.get_object_at_path(path / datalad_root_record_name) is not None
  21. def add_dataset(self,
  22. path: MetadataPath,
  23. metadata_root_record: MetadataRootRecord):
  24. self.mtree.add_child_at(metadata_root_record,
  25. path / datalad_root_record_name)
  26. def get_metadata_root_record(self,
  27. path: MetadataPath
  28. ) -> Optional[MetadataRootRecord]:
  29. mrr = self.mtree.get_object_at_path(
  30. path / datalad_root_record_name)
  31. if mrr is None:
  32. return None
  33. assert isinstance(mrr, MetadataRootRecord)
  34. mrr.ensure_mapped()
  35. return mrr
  36. def get_dataset_paths(self
  37. ) -> List[Tuple[MetadataPath, MetadataRootRecord]]:
  38. return [
  39. (MetadataPath("/".join(path.parts[:-1])), node)
  40. for path, node in self.mtree.get_paths_recursive()
  41. if path.parts[-1] == datalad_root_record_name
  42. ]
  43. def add_subtree(self,
  44. subtree: "DatasetTree",
  45. subtree_path: MetadataPath):
  46. self.mtree.add_child_at(subtree.mtree, subtree_path)
  47. def delete_subtree(self,
  48. subtree_path: MetadataPath):
  49. self.mtree.remove_child_at(subtree_path)