Exemplo n.º 1
0
func (p *Pod) Graph() error {
	logs.WithF(p.fields).Info("Graphing")
	os.MkdirAll(p.target, 0777)

	var buffer bytes.Buffer
	buffer.WriteString("digraph {\n")
	buffer.WriteString("  {\n")
	buffer.WriteString("  ")
	buffer.WriteString("\"")
	buffer.WriteString(p.manifest.Name.TinyNameId())
	buffer.WriteString("\"")
	buffer.WriteString(" [style=filled, fillcolor=yellow, shape=box]\n")
	buffer.WriteString("  }\n")

	for _, e := range p.manifest.Pod.Apps {
		for _, d := range e.Dependencies {
			buffer.WriteString("  ")
			buffer.WriteString("\"")
			buffer.WriteString(d.TinyNameId())
			buffer.WriteString("\"")
			buffer.WriteString(" -> ")
			buffer.WriteString("\"")
			buffer.WriteString(p.manifest.Name.TinyNameId())
			buffer.WriteString("\"")
			buffer.WriteString("\n")
		}
	}

	buffer.WriteString("}\n")

	if err := ioutil.WriteFile(p.target+pathGraphDot, buffer.Bytes(), 0644); err != nil {
		return errs.WithEF(err, p.fields.WithField("file", p.target+pathGraphDot), "Failed to write file")
	}

	if _, _, err := common.ExecCmdGetStdoutAndStderr("dot", "-V"); err == nil {
		if std, stderr, err := common.ExecCmdGetStdoutAndStderr("dot", "-Tpng", p.target+pathGraphDot, "-o", p.target+pathGraphPng); err != nil {
			return errs.WithEF(err, p.fields.WithField("stdout", std).WithField("stderr", stderr), "Failed to create graph image")
		}
	}

	return nil

}
Exemplo n.º 2
0
func (aci *Aci) Graph() error {
	defer aci.giveBackUserRightsToTarget()
	logs.WithF(aci.fields).Debug("Graphing")

	os.MkdirAll(aci.target, 0777)

	var buffer bytes.Buffer
	buffer.WriteString("digraph {\n")

	for _, dep := range aci.manifest.Aci.Dependencies {
		buffer.WriteString("  ")
		buffer.WriteString("\"")
		buffer.WriteString(dep.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString(" -> ")
		buffer.WriteString("\"")
		buffer.WriteString(aci.manifest.NameAndVersion.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString("\n")
	}

	for _, dep := range aci.manifest.Builder.Dependencies {
		buffer.WriteString("  ")
		buffer.WriteString("\"")
		buffer.WriteString(dep.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString(" -> ")
		buffer.WriteString("\"")
		buffer.WriteString(aci.manifest.NameAndVersion.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString("[color=red,penwidth=2.0]")
		buffer.WriteString("\n")
	}

	for _, dep := range aci.manifest.Tester.Builder.Dependencies {
		buffer.WriteString("  ")
		buffer.WriteString("\"")
		buffer.WriteString(dep.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString(" -> ")
		buffer.WriteString("\"")
		buffer.WriteString(aci.manifest.NameAndVersion.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString("[color=green,penwidth=2.0]")
		buffer.WriteString("\n")
	}

	for _, dep := range aci.manifest.Tester.Aci.Dependencies {
		buffer.WriteString("  ")
		buffer.WriteString("\"")
		buffer.WriteString(dep.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString(" -> ")
		buffer.WriteString("\"")
		buffer.WriteString(aci.manifest.NameAndVersion.TinyNameId())
		buffer.WriteString("\"")
		buffer.WriteString("[color=blue,penwidth=2.0]")
		buffer.WriteString("\n")
	}

	buffer.WriteString("}\n")

	if err := ioutil.WriteFile(aci.target+pathGraphDot, buffer.Bytes(), 0644); err != nil {
		return errs.WithEF(err, aci.fields.WithField("file", aci.target+pathGraphDot), "Failed to write file")
	}

	if _, _, err := common.ExecCmdGetStdoutAndStderr("dot", "-V"); err == nil {
		if std, stderr, err := common.ExecCmdGetStdoutAndStderr("dot", "-Tpng", aci.target+pathGraphDot, "-o", aci.target+pathGraphPng); err != nil {
			return errs.WithEF(err, aci.fields.WithField("stdout", std).WithField("stderr", stderr), "Failed to create graph image")
		}
	}

	return nil
}