func (p *Package) DotGraph(sb *stringbuffer.StringBuffer) { if p.dependencies.Len() == 0 { sb.Add(fmt.Sprintf("\t\"%s\";\n", p.Name)) } else { for dep := range p.dependencies.Iter() { sb.Add(fmt.Sprintf("\t\"%s\" -> \"%s\";\n", p.Name, dep)) } } }
func (d Dag) MakeDotGraph(filename string) { var file *os.File var fileinfo *os.FileInfo var e os.Error var sb *stringbuffer.StringBuffer fileinfo, e = os.Stat(filename) if e == nil { if fileinfo.IsRegular() { e = os.Remove(fileinfo.Name) if e != nil { log.Fatalf("[ERROR] failed to remove: %s\n", filename) } } } sb = stringbuffer.NewSize(500) file, e = os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0644) if e != nil { log.Fatalf("[ERROR] %s\n", e) } sb.Add("digraph depgraph {\n\trankdir=LR;\n") for _, v := range d { v.DotGraph(sb) } sb.Add("}\n") file.WriteString(sb.String()) file.Close() }