[PATCH 1 of 1 seda] Provide an alternate way to control the compound graph

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 31 17:09:11 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490968060 -7200
#      Fri Mar 31 15:47:40 2017 +0200
# Node ID 3616158ae8e433063556217b62708c5eedb44566
# Parent  c0e871401ee8ed4cead897f84566bcd0f494434f
Provide an alternate way to control the compound graph

using global sets instead of through partial .keyword attribute.

diff --git a/cubicweb_seda/__init__.py b/cubicweb_seda/__init__.py
--- a/cubicweb_seda/__init__.py
+++ b/cubicweb_seda/__init__.py
@@ -15,26 +15,23 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda application package
 
 Data Exchange Standard for Archival
 """
-from functools import partial
-
-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=[])
+from cubicweb_compound import skip_rtypes_set, structure_def, CompositeGraph
+
+
+# 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'])):
     """Return an iterator on (rdef, role) of external relations from entity schema (i.e.
     non-composite relations).
@@ -51,11 +48,11 @@ def iter_external_rdefs(eschema, skip_rt
 
 def iter_all_rdefs(schema, container_etype):
     """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:
         etype = stack.pop()
         for (rtype, role), targets in graph.child_relations(etype):


More information about the saem-devel mailing list