BuildGraph generates graph contents from aptly object database
(collectionFactory *CollectionFactory, layout string)
| 9 | |
| 10 | // BuildGraph generates graph contents from aptly object database |
| 11 | func BuildGraph(collectionFactory *CollectionFactory, layout string) (gographviz.Interface, error) { |
| 12 | var err error |
| 13 | |
| 14 | graph := gographviz.NewEscape() |
| 15 | _ = graph.SetDir(true) |
| 16 | _ = graph.SetName("aptly") |
| 17 | |
| 18 | var labelStart string |
| 19 | var labelEnd string |
| 20 | |
| 21 | switch layout { |
| 22 | case "vertical": |
| 23 | _ = graph.AddAttr("aptly", "rankdir", "LR") |
| 24 | labelStart = "" |
| 25 | labelEnd = "" |
| 26 | case "horizontal": |
| 27 | fallthrough |
| 28 | default: |
| 29 | labelStart = "{" |
| 30 | labelEnd = "}" |
| 31 | } |
| 32 | |
| 33 | existingNodes := map[string]bool{} |
| 34 | |
| 35 | err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *RemoteRepo) error { |
| 36 | e := collectionFactory.RemoteRepoCollection().LoadComplete(repo) |
| 37 | if e != nil { |
| 38 | return e |
| 39 | } |
| 40 | |
| 41 | _ = graph.AddNode("aptly", repo.UUID, map[string]string{ |
| 42 | "shape": "Mrecord", |
| 43 | "style": "filled", |
| 44 | "fillcolor": "darkgoldenrod1", |
| 45 | "label": fmt.Sprintf("%sMirror %s|url: %s|dist: %s|comp: %s|arch: %s|pkgs: %d%s", labelStart, repo.Name, repo.ArchiveRoot, |
| 46 | repo.Distribution, strings.Join(repo.Components, ", "), |
| 47 | strings.Join(repo.Architectures, ", "), repo.NumPackages(), labelEnd), |
| 48 | }) |
| 49 | existingNodes[repo.UUID] = true |
| 50 | return nil |
| 51 | }) |
| 52 | |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | |
| 57 | err = collectionFactory.LocalRepoCollection().ForEach(func(repo *LocalRepo) error { |
| 58 | e := collectionFactory.LocalRepoCollection().LoadComplete(repo) |
| 59 | if e != nil { |
| 60 | return e |
| 61 | } |
| 62 | |
| 63 | _ = graph.AddNode("aptly", repo.UUID, map[string]string{ |
| 64 | "shape": "Mrecord", |
| 65 | "style": "filled", |
| 66 | "fillcolor": "mediumseagreen", |
| 67 | "label": fmt.Sprintf("%sRepo %s|comment: %s|pkgs: %d%s", labelStart, |
| 68 | repo.Name, repo.Comment, repo.NumPackages(), labelEnd), |
no test coverage detected