Provide a way to control the compound graph
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Mar 2017 13:53:01 +0200
changeset 2555 0ae7957cf9e3
parent 2553 0145618f8da7
child 2563 455ce14bb7bf
Provide a way to control the compound graph useful for e.g. the saem_ref cube that introduces some entity types (Activity) which would be shared by different compound graph while we want it to be skipped.
cubicweb_seda/__init__.py
--- a/cubicweb_seda/__init__.py	Wed Mar 29 15:41:45 2017 +0200
+++ b/cubicweb_seda/__init__.py	Thu Mar 30 13:53:01 2017 +0200
@@ -17,13 +17,22 @@
 
 Data Exchange Standard for Archival
 """
+from functools import partial
 
-from cubicweb_compound import structure_def, skip_rtypes_set, CompositeGraph
+from cubicweb_compound import skip_rtypes_set, CompositeGraph
+
+# data structure allowing control of the compound graph:
+#
+# SEDAArchiveTransferGraph.keywords['skipetypes'].append('SomeEtype')
+# SEDAArchiveTransferGraph.keywords['skiprtypes'].append('some_rtype')
+SEDAArchiveTransferGraph = partial(CompositeGraph, skipetypes=[], skiprtypes=[])
 
 
 def seda_profile_container_def(schema):
-    """Define container for SEDAProfile"""
-    return structure_def(schema, 'SEDAArchiveTransfer').items()
+    """Define container for SEDAArchiveTransfer, as a list of (etype, parent_rdefs)."""
+    graph = SEDAArchiveTransferGraph(schema)
+    return [(child, set(relinfo))
+            for child, relinfo in graph.parent_structure('SEDAArchiveTransfer').items()]
 
 
 def iter_external_rdefs(eschema, skip_rtypes=skip_rtypes_set(['container'])):
@@ -44,7 +53,7 @@
     """Return an iterator on (rdef, role) of all relations of the compound graph starting from the
     given entity type, both internal (composite) and external (non-composite).
     """
-    graph = CompositeGraph(schema)
+    graph = SEDAArchiveTransferGraph(schema)
     stack = [container_etype]
     visited = set(stack)
     while stack: