Skip to content

Instantly share code, notes, and snippets.

@invadersmustdie
Created March 24, 2013 13:36
Show Gist options
  • Save invadersmustdie/5231999 to your computer and use it in GitHub Desktop.
Save invadersmustdie/5231999 to your computer and use it in GitHub Desktop.
quick hack to convert dot representation of your puppet catalog to yed-enhanced graphml. open with http://www.yworks.com/en/products_yed_download.html to get most of the graph.
#!/usr/bin/env ruby
def mk_oid(name)
name
end
out = File.new(ARGV[1], "w")
nodes = 0
edges = 0
out.puts %Q{<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
<!--Created by yFiles for Java 2.10-->
<key for="graphml" id="d0" yfiles.type="resources"/>
<key for="port" id="d1" yfiles.type="portgraphics"/>
<key for="port" id="d2" yfiles.type="portgeometry"/>
<key for="port" id="d3" yfiles.type="portuserdata"/>
<key attr.name="url" attr.type="string" for="node" id="d4"/>
<key attr.name="description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
<key attr.name="url" attr.type="string" for="edge" id="d7"/>
<key attr.name="description" attr.type="string" for="edge" id="d8"/>
<key for="edge" id="d9" yfiles.type="edgegraphics"/>
<graph edgedefault="directed" id="G">
}
File.readlines(ARGV[0]).each do |line|
m = line.match(/^\s*\"([A-Z].[a-z]+\[\S+\])" \[\s*$/)
if m
node_id = mk_oid(m[1])
out.puts %Q{
<node id="#{node_id}">
<data key="d5"/>
<data key="d6">
<y:ShapeNode>
<y:NodeLabel alignment="center" autoSizePolicy="content">#{m[1]}</y:NodeLabel>
<y:Shape type="rectangle"/>
</y:ShapeNode>
</data>
</node>
}
nodes += 1
end
m = line.match(/^\s*\"([A-Z].[a-z]+\[\S+\])" \-\> \"([A-Z].[a-z]+\[\S+\])" \[\s*$/)
if m
source_id = mk_oid(m[1])
target_id = mk_oid(m[2])
edge_id = mk_oid("#{m[1]}->#{m[2]}")
out.puts %Q{
<edge id="#{edge_id}" source="#{source_id}" target="#{target_id}">
<data key="d8"/>
<data key="d9">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
<y:LineStyle color="#000000" type="line" width="1.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
}
edges += 1
end
end
out.puts %Q{
</graph>
</graphml>
}
out.close
puts "#{nodes} nodes"
puts "#{edges} edges"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment