~morphis/ubuntu-push/add-source-format

« back to all changes in this revision

Viewing changes to bus/systemimage/systemimage.go

  • Committer: Tarmac
  • Author(s): jonas-drange
  • Date: 2016-03-10 13:21:20 UTC
  • mfrom: (422.2.2 lp1554547-automatic)
  • Revision ID: tarmac-20160310132120-bqam2rhwnkbbteuy
[r=jonas-drange] deprecate the usage of Info and replace it with Information

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
package systemimage
19
19
 
20
20
import (
 
21
        "strconv"
 
22
        "strings"
 
23
 
21
24
        "launchpad.net/ubuntu-push/bus"
22
25
        "launchpad.net/ubuntu-push/logger"
23
26
)
37
40
        // xxx channel_target missing
38
41
        LastUpdate    string
39
42
        VersionDetail map[string]string
 
43
        Raw           map[string]string
40
44
}
41
45
 
42
46
// A SystemImage exposes the a subset of system-image service.
43
47
type SystemImage interface {
44
 
        Info() (*InfoResult, error)
 
48
        Information() (*InfoResult, error)
45
49
}
46
50
 
47
51
type systemImage struct {
56
60
 
57
61
var _ SystemImage = &systemImage{} // ensures it conforms
58
62
 
59
 
func (si *systemImage) Info() (*InfoResult, error) {
60
 
        si.log.Debugf("invoking Info")
61
 
        res := &InfoResult{}
62
 
        err := si.endp.Call("Info", bus.Args(), &res.BuildNumber, &res.Device, &res.Channel, &res.LastUpdate, &res.VersionDetail)
 
63
func (si *systemImage) Information() (*InfoResult, error) {
 
64
        si.log.Debugf("invoking Information")
 
65
        m := map[string]string{}
 
66
        err := si.endp.Call("Information", bus.Args(), &m)
 
67
 
63
68
        if err != nil {
64
 
                si.log.Errorf("Info failed: %v", err)
 
69
                si.log.Errorf("Information failed: %v", err)
65
70
                return nil, err
66
71
        }
 
72
 
 
73
        res := &InfoResult{}
 
74
 
 
75
        // Try parsing the build number if it exist.
 
76
        if bn := m["current_build_number"]; len(bn) > 0 {
 
77
                bn, err := strconv.ParseInt(bn, 10, 32)
 
78
                if err == nil {
 
79
                        res.BuildNumber = int32(bn)
 
80
                } else {
 
81
                        res.BuildNumber = -1
 
82
                }
 
83
        }
 
84
 
 
85
        res.Device = m["device_name"]
 
86
        res.Channel = m["channel_name"]
 
87
        res.LastUpdate = m["last_update_date"]
 
88
        res.VersionDetail = map[string]string{}
 
89
 
 
90
        // Split version detail key=value,key2=value2 into a string map
 
91
        // Note that even if
 
92
        vals := strings.Split(m["version_detail"], ",")
 
93
        for _, val := range vals {
 
94
                pairs := strings.Split(val, "=")
 
95
                if len(pairs) != 2 {
 
96
                        continue
 
97
                }
 
98
                res.VersionDetail[pairs[0]] = pairs[1]
 
99
        }
 
100
        res.Raw = m
 
101
 
67
102
        return res, err
68
103
}