/
indexes.go
87 lines (74 loc) · 2.24 KB
/
indexes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"github.com/ian-kent/go-log/log"
"github.com/ian-kent/gopan/gopan"
)
// GoPAN indexes - CPAN, BackPAN etc - map[config.name]map[source.name]*Source
var indexes map[string]map[string]*gopan.Source
// Maps authors by id (A -> AB -> ABC)
var mapped = make(map[string]map[string]map[string]map[string]*gopan.Author)
// Maps package names (e.g. Mojolicious, Mojolicious::Command etc)
var packages = make(map[string]*PkgSpace)
var idxpackages = make(map[string]map[string]*PkgSpace)
// Maps SmartPAN virtual URLs (a/ab/abc/package.tar.gz) to indexes (BackPAN/CPAN)
var filemap = make(map[string]string)
// Represents a partial namespace (e.g. 'Mojolicious' and 'Mojolicious'->'Command' for Mojolicious::Command)
type PkgSpace struct {
Namespace string
Packages []*gopan.PerlPackage
Children map[string]*PkgSpace
Parent *PkgSpace
Versions map[float64]*gopan.PerlPackage
}
// Returns the full package name
func (p *PkgSpace) FullName() string {
s := ""
if p.Parent != nil {
s = p.Parent.FullName() + "::"
}
s += p.Namespace
return s
}
// Returns the latest version available from any source
func (p *PkgSpace) Version() float64 {
if len(p.Packages) == 0 {
return 0
}
// FIXME use a sort
l := float64(0)
for v, _ := range p.Versions {
if v > l {
l = v
}
}
return l
}
// Populates a package namespace, e.g. constructing each part of the namespace
// when passed []string{'Mojolicious','Plugin','PODRenderer'}
func (p *PkgSpace) Populate(parts []string, pkg *gopan.PerlPackage) {
if len(parts) > 0 {
if _, ok := p.Children[parts[0]]; !ok {
p.Children[parts[0]] = &PkgSpace{
Namespace: parts[0],
Packages: make([]*gopan.PerlPackage, 0),
Children: make(map[string]*PkgSpace),
Parent: p,
Versions: make(map[float64]*gopan.PerlPackage),
}
}
if len(parts) == 1 {
p.Children[parts[0]].Packages = append(p.Children[parts[0]].Packages, pkg)
p.Children[parts[0]].Versions[gopan.VersionFromString(pkg.Version)] = pkg
log.Trace("Version linked: %f for %s in %s", gopan.VersionFromString(pkg.Version), pkg.Name, p.Namespace)
} else {
p.Children[parts[0]].Populate(parts[1:], pkg)
}
}
}
type Summary struct {
Sources int
Authors int
Modules int
Packages int
}
var summary *Summary