~rogpeppe/juju-core/387-use-testing-set

« back to all changes in this revision

Viewing changes to environs/tools/storage.go

  • Committer: Ian Booth
  • Date: 2013-08-21 05:38:38 UTC
  • mto: (1603.8.2 simplify-tools-search)
  • mto: This revision was merged to the branch mainline in revision 1702.
  • Revision ID: ian.booth@canonical.com-20130821053838-3c9oahds4mg2u0l7
Pull out Tools struct to its own package

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        "os"
11
11
        "strings"
12
12
 
13
 
        agenttools "launchpad.net/juju-core/agent/tools"
14
13
        "launchpad.net/juju-core/environs"
 
14
        coretools "launchpad.net/juju-core/tools"
15
15
        "launchpad.net/juju-core/version"
16
16
)
17
17
 
18
18
var ErrNoTools = errors.New("no tools available")
19
 
var ErrNoMatches = errors.New("no matching tools available")
20
19
 
21
20
const (
22
21
        DefaultToolPrefix = "tools/juju-"
38
37
 
39
38
// ReadList returns a List of the tools in store with the given major version.
40
39
// If store contains no such tools, it returns ErrNoMatches.
41
 
func ReadList(storage environs.StorageReader, majorVersion int) (List, error) {
 
40
func ReadList(storage environs.StorageReader, majorVersion int) (coretools.List, error) {
42
41
        logger.Debugf("reading v%d.* tools", majorVersion)
43
42
        names, err := storage.List(toolPrefix)
44
43
        if err != nil {
45
44
                return nil, err
46
45
        }
47
 
        var list List
 
46
        var list coretools.List
48
47
        var foundAnyTools bool
49
48
        for _, name := range names {
50
49
                if !strings.HasPrefix(name, toolPrefix) || !strings.HasSuffix(name, toolSuffix) {
51
50
                        continue
52
51
                }
53
 
                var t agenttools.Tools
 
52
                var t coretools.Tools
54
53
                vers := name[len(toolPrefix) : len(name)-len(toolSuffix)]
55
54
                if t.Version, err = version.ParseBinary(vers); err != nil {
56
55
                        continue
67
66
        }
68
67
        if len(list) == 0 {
69
68
                if foundAnyTools {
70
 
                        return nil, ErrNoMatches
 
69
                        return nil, coretools.ErrNoMatches
71
70
                }
72
71
                return nil, ErrNoTools
73
72
        }
81
80
// of the built tools will be uploaded for use by machines of those series.
82
81
// Juju tools built for one series do not necessarily run on another, but this
83
82
// func exists only for development use cases.
84
 
func Upload(storage environs.Storage, forceVersion *version.Number, fakeSeries ...string) (*agenttools.Tools, error) {
 
83
func Upload(storage environs.Storage, forceVersion *version.Number, fakeSeries ...string) (*coretools.Tools, error) {
85
84
        // TODO(rog) find binaries from $PATH when not using a development
86
85
        // version of juju within a $GOPATH.
87
86
 
133
132
        if err != nil {
134
133
                return nil, err
135
134
        }
136
 
        return &agenttools.Tools{toolsVersion, url}, nil
 
135
        return &coretools.Tools{toolsVersion, url}, nil
137
136
}