Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.ref_graph Namespace Reference

Classes

class  Node
class  Edge

Functions

def obj2id
def str2id
def local_reference_graph
def build_graph
def getDot
def get_image
def get_png
def get_cmapx

Variables

 local_refernece_graph = local_reference_graph

Detailed Description

Graphviz local object referencs, allows any refrerenceable object to
produce a graph and a client side map. When we can export this as SVG
(and expect clients to handle it) it will be much easier to style to
the look of the site.

Inspired by code from Andreas Jung

Function Documentation

def Archetypes.ref_graph.build_graph (   graphs,
  inst 
)

Definition at line 101 of file ref_graph.py.

00101 
00102 def build_graph(graphs, inst):
00103     fp = StringIO()
00104     print >>fp, 'digraph G {'
00105     uid = inst.UID()
00106     seen = {}
00107     shown = {}
00108     for direction, graph in graphs.iteritems(): #forw/back
00109         for relationship, edges in graph.iteritems():
00110             rel_id = "unqualified"
00111             if relationship: rel_id = str2id(relationship)
00112             print >>fp, 'subgraph cluster_%s {' % rel_id
00113 
00114 
00115             for e in iter(edges):
00116                 for n in e.src, e.dest:
00117                     if n not in seen:
00118                         seen[n] = 1
00119                         print >>fp, '\t%s [label="%s", href="%s"' % (n.id,
00120                                                                    n.title,
00121                                                                    n.url),
00122                         if uid == n.uid:
00123                             print >>fp, '\tstyle=filled, fillcolor=blue',
00124                         print >>fp, ']'
00125 
00126             for e in iter(edges):
00127                 if e in shown: continue
00128                 if direction == "forward":
00129                     print >>fp, '\t%s -> %s [label="%s", href="%s/reference_graph"]' % (
00130                     e.src,
00131                     e.dest,
00132                     e.relationship,
00133                     e.dest.url)
00134                 else:
00135                     print >>fp, '\t%s -> %s [label="%s", href="%s/reference_graph"]' % (
00136                     e.src,
00137                     e.dest,
00138                     e.relationship,
00139                     e.src.url)
00140                 shown[e] = e
00141 
00142             print >>fp, '\t}\n'
00143 
00144     print >>fp, "}"
00145     return fp.getvalue()
00146 
00147 
00148 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 166 of file ref_graph.py.

00166 
00167     def get_cmapx(inst):
00168         data = getDot(inst)
00169 
00170         stdout, stdin = popen2('%s -Gpack -Tcmapx ' % GRAPHVIZ_BINARY)
00171         stdin.write(data)
00172         stdin.close()
00173         output = stdout.read()
00174         return output
00175 
00176 
else:

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ref_graph.get_image (   inst,
  fmt 
)

Definition at line 155 of file ref_graph.py.

00155 
00156     def get_image(inst, fmt):
00157         data = getDot(inst)
00158 
00159         stdout, stdin = popen2('%s -Gpack -T%s' % (GRAPHVIZ_BINARY, fmt))
00160         stdin.write(data)
00161         stdin.close()
00162         output = stdout.read()
00163         return output

Here is the call graph for this function:

Definition at line 164 of file ref_graph.py.

00164 
00165     def get_png(inst): return get_image(inst, fmt="png")

Here is the caller graph for this function:

Definition at line 150 of file ref_graph.py.

00150 
00151     def getDot(inst):
00152         g = local_reference_graph(inst)
00153         data = build_graph(g, inst)
00154         return data

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file ref_graph.py.

00064 
00065 def local_reference_graph(inst):
00066     nodes  = {}
00067     graphs = { 'forward' : {},
00068                'backward' : {},
00069                }
00070 
00071     rc = inst.reference_catalog
00072 
00073     references = rc.getReferences(inst)
00074     back_references = rc.getBackReferences(inst)
00075 
00076     node = Node(inst)
00077     nodes[inst.UID()] = node
00078 
00079     for ref in references:
00080         tob = ref.getTargetObject()
00081         target = Node(tob)
00082         if tob.UID() not in nodes:
00083             nodes[tob.UID()] = target
00084 
00085         e = Edge(node, target, ref)
00086         graphs['forward'].setdefault(ref.relationship, []).append(e)
00087 
00088     for ref in back_references:
00089         sob = ref.getSourceObject()
00090         source = Node(sob)
00091         if sob.UID() not in nodes:
00092             nodes[sob.UID()] = source
00093 
00094         e = Edge(source, node, ref)
00095         graphs['backward'].setdefault(ref.relationship, []).append(e)
00096 
00097     return graphs
00098 
# typo, but keep API

Here is the caller graph for this function:

convert an issue to an ID 

Definition at line 16 of file ref_graph.py.

00016 
00017 def obj2id(obj):
00018     """ convert an issue to an ID """
00019     str = obj.absolute_url(1)
00020     return str2id(str)

Here is the call graph for this function:

Definition at line 21 of file ref_graph.py.

00021 
00022 def str2id(str):
00023     id = unquote(str)
00024     id = id.replace('-', '_')
00025     id = id.replace('/', '_')
00026     id=  id.replace(' ', '_')
00027     id=  id.replace('.', '_')
00028     return id
00029 
00030 

Here is the caller graph for this function:


Variable Documentation

Definition at line 99 of file ref_graph.py.