Provide an alternate way to control the compound graph
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 31 Mar 2017 15:47:40 +0200
changeset 2592 8477512718c8
parent 2591 d33d90d4daad
child 2593 9ca36b8def1f
Provide an alternate way to control the compound graph using global sets instead of through partial .keyword attribute.
cubicweb_seda/__init__.py
--- a/cubicweb_seda/__init__.py	Fri Mar 31 14:55:09 2017 +0200
+++ b/cubicweb_seda/__init__.py	Fri Mar 31 15:47:40 2017 +0200
@@ -17,22 +17,19 @@
 
 Data Exchange Standard for Archival
 """
-from functools import partial
 
-from cubicweb_compound import skip_rtypes_set, CompositeGraph
+from cubicweb_compound import skip_rtypes_set, structure_def, 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=[])
+# control of compound graph by adding etype / rtype to the corresponding set below
+GRAPH_SKIP_ETYPES = set()
+GRAPH_SKIP_RTYPES = set()
 
 
 def seda_profile_container_def(schema):
     """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()]
+    return structure_def(schema, 'SEDAArchiveTransfer',
+                         skipetypes=GRAPH_SKIP_ETYPES, skiprtypes=GRAPH_SKIP_RTYPES).items()
 
 
 def iter_external_rdefs(eschema, skip_rtypes=skip_rtypes_set(['container'])):
@@ -53,7 +50,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 = SEDAArchiveTransferGraph(schema)
+    graph = CompositeGraph(schema, skipetypes=GRAPH_SKIP_ETYPES, skiprtypes=GRAPH_SKIP_RTYPES)
     stack = [container_etype]
     visited = set(stack)
     while stack: