Move graph into deb/ package, passing collection factory. #169

This commit is contained in:
Andrey Smirnov
2015-01-13 19:10:39 +03:00
parent b50cb70a0e
commit 427c42f4b8
3 changed files with 17 additions and 19 deletions
+4 -4
View File
@@ -3,21 +3,21 @@ package api
import (
"bytes"
"fmt"
"github.com/gin-gonic/gin"
"github.com/smira/aptly/deb"
"io"
"os"
"os/exec"
"github.com/gin-gonic/gin"
"github.com/smira/aptly/graph"
)
// GET /api/graph
func apiGraph(c *gin.Context) {
var (
err error
err error
output []byte
)
graph, err := graph.BuildGraph(context)
graph, err := deb.BuildGraph(context.CollectionFactory())
if err != nil {
c.JSON(500, err)
return
+2 -2
View File
@@ -3,8 +3,8 @@ package cmd
import (
"bytes"
"fmt"
"github.com/smira/aptly/deb"
"github.com/smira/commander"
"github.com/smira/aptly/graph"
"io"
"io/ioutil"
"os"
@@ -20,7 +20,7 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
}
fmt.Printf("Generating graph...\n")
graph, err := graph.BuildGraph(context)
graph, err := deb.BuildGraph(context.CollectionFactory())
if err != nil {
return err
}
+11 -13
View File
@@ -1,14 +1,12 @@
package graph
package deb
import (
"code.google.com/p/gographviz"
"fmt"
"strings"
"github.com/smira/aptly/context"
"github.com/smira/aptly/deb"
)
func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
func BuildGraph(collectionFactory *CollectionFactory) (gographviz.Interface, error) {
var err error
graph := gographviz.NewEscape()
@@ -17,8 +15,8 @@ func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
existingNodes := map[string]bool{}
err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *RemoteRepo) error {
err := collectionFactory.RemoteRepoCollection().LoadComplete(repo)
if err != nil {
return err
}
@@ -39,8 +37,8 @@ func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
return nil, err
}
err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
err = collectionFactory.LocalRepoCollection().ForEach(func(repo *LocalRepo) error {
err := collectionFactory.LocalRepoCollection().LoadComplete(repo)
if err != nil {
return err
}
@@ -60,13 +58,13 @@ func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
return nil, err
}
context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
collectionFactory.SnapshotCollection().ForEach(func(snapshot *Snapshot) error {
existingNodes[snapshot.UUID] = true
return nil
})
err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *Snapshot) error {
err := collectionFactory.SnapshotCollection().LoadComplete(snapshot)
if err != nil {
return err
}
@@ -98,7 +96,7 @@ func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
return nil, err
}
context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
collectionFactory.PublishedRepoCollection().ForEach(func(repo *PublishedRepo) error {
graph.AddNode("aptly", repo.UUID, map[string]string{
"shape": "Mrecord",
"style": "filled",
@@ -118,4 +116,4 @@ func BuildGraph(context *context.AptlyContext) (gographviz.Interface, error) {
})
return graph, nil
}
}