Merge lp:~jamesodhunt/goget-ubuntu-touch/add-list-images-option into lp:goget-ubuntu-touch

Proposed by James Hunt
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 75
Merged at revision: 75
Proposed branch: lp:~jamesodhunt/goget-ubuntu-touch/add-list-images-option
Merge into: lp:goget-ubuntu-touch
Diff against target: 146 lines (+78/-0)
4 files modified
ubuntu-device-flash/args.go (+1/-0)
ubuntu-device-flash/main.go (+19/-0)
ubuntuimage/channels.go (+51/-0)
ubuntuimage/types.go (+7/-0)
To merge this branch: bzr merge lp:~jamesodhunt/goget-ubuntu-touch/add-list-images-option
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+236510@code.launchpad.net

Commit message

ubuntu-device-flash: add '--list-images' option to display brief image details, one per line.

Description of the change

Add '--list-images' option.

To post a comment you must log in.
74. By James Hunt

[ Sergio Schvezov ]
ubuntu-device-flash: minor improvements to user experience and code
polish

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:73
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~jamesodhunt/goget-ubuntu-touch/add-list-images-option/+merge/236510/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-ci/72/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-amd64-ci/36
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-armhf-ci/36
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-i386-ci/36

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/goget-ubuntu-touch-ci/72/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:74
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~jamesodhunt/goget-ubuntu-touch/add-list-images-option/+merge/236510/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-ci/73/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-amd64-ci/37
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-armhf-ci/37
    SUCCESS: http://jenkins.qa.ubuntu.com/job/goget-ubuntu-touch-utopic-i386-ci/37

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/goget-ubuntu-touch-ci/73/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

you probably want to do something like this (or move it to a separate function maybe)

if args.ListImages
 if args.Device == "" {
  log.Fatal("You must specify a device type")
 }

 deviceChannel, err := channels.GetDeviceChannel(
  args.Server, args.Channel, args.Device)
 if err != nil {
  log.Fatal(err)
 }

 return deviceChannel.ListImageVersions()
}

and keep the original deviceChannel setup that in it's original location to avoid the from below to not break current "device" autodetection

review: Needs Fixing
75. By James Hunt

* ubuntu-device-flash/main.go: Revert to calling GetDeviceChannel() as
  late as possible to avoid breaking device auto-detection when not
  running '--list-images'.

Revision history for this message
James Hunt (jamesodhunt) wrote :

Thanks for reviewing. Branch updated.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu-device-flash/args.go'
2--- ubuntu-device-flash/args.go 2014-09-03 12:53:40 +0000
3+++ ubuntu-device-flash/args.go 2014-10-02 08:49:00 +0000
4@@ -28,6 +28,7 @@
5 Revision int `long:"revision" description:"revision to flash, absolute or relative allowed"`
6 Bootstrap bool `long:"bootstrap" description:"bootstrap the system, do this from the bootloader"`
7 ListChannels bool `long:"list-channels" description:"List available channels"`
8+ ListImages bool `long:"list-images" description:"List available images for a channel"`
9 Wipe bool `long:"wipe" description:"Clear all data after flashing"`
10 Channel string `long:"channel" description:"Specify an alternate channel"`
11 ShowImage bool `long:"show-image" description:"Show information for an image in the given channel"`
12
13=== modified file 'ubuntu-device-flash/main.go'
14--- ubuntu-device-flash/main.go 2014-09-25 13:40:20 +0000
15+++ ubuntu-device-flash/main.go 2014-10-02 08:49:00 +0000
16@@ -98,6 +98,25 @@
17 }
18 return
19 }
20+
21+ if args.ListImages {
22+ if args.Device == "" {
23+ log.Fatal("You must specify a device type")
24+ }
25+
26+ deviceChannel, err := channels.GetDeviceChannel(
27+ args.Server, args.Channel, args.Device)
28+ if err != nil {
29+ log.Fatal(err)
30+ }
31+
32+ err = deviceChannel.ListImageVersions()
33+ if err != nil {
34+ log.Fatal(err)
35+ }
36+ return
37+ }
38+
39 cacheDir := ubuntuimage.GetCacheDir()
40 if args.CleanCache {
41 log.Print("Cleaning prevously downloaded content")
42
43=== modified file 'ubuntuimage/channels.go'
44--- ubuntuimage/channels.go 2014-04-16 17:00:53 +0000
45+++ ubuntuimage/channels.go 2014-10-02 08:49:00 +0000
46@@ -26,10 +26,12 @@
47 "errors"
48 "fmt"
49 "net/http"
50+ "io/ioutil"
51 )
52
53 const (
54 channelsPath = "/channels.json"
55+ indexName = "index.json"
56 FULL_IMAGE = "full"
57 )
58
59@@ -80,6 +82,8 @@
60 return i1.Version > i2.Version
61 }
62 ImageBy(order).ImageSort(deviceChannel.Images)
63+
64+ deviceChannel.Url = channelUri
65 return deviceChannel, err
66 }
67
68@@ -93,6 +97,53 @@
69 return image, fmt.Errorf("Failed to locate image %d", revision)
70 }
71
72+func (deviceChannel *DeviceChannel) ListImageVersions() (err error) {
73+
74+ jsonData := map[string]interface{}{}
75+
76+ resp, err := client.Get(deviceChannel.Url)
77+ if err != nil {
78+ return err
79+ }
80+
81+ if (resp.StatusCode != 200) {
82+ statusErr := errors.New(fmt.Sprintf("Invalid HTTP response: %d", resp.StatusCode))
83+ return statusErr
84+ }
85+
86+ defer resp.Body.Close()
87+
88+ body, err := ioutil.ReadAll(resp.Body)
89+ if err != nil {
90+ return err
91+ }
92+
93+ err = json.Unmarshal(body, &jsonData)
94+ if err != nil {
95+ return err
96+ }
97+
98+ images := jsonData["images"].([]interface{})
99+
100+ for i := range images {
101+ entry := images[i].(map[string]interface{})
102+
103+ imageType := entry["type"]
104+
105+ if imageType != FULL_IMAGE {
106+ // ignore delta images as they cannot be used to
107+ // perform an initial device flash
108+ continue
109+ }
110+
111+ fmt.Printf("%d: description='%s'\n",
112+ int(entry["version"].(float64)),
113+ entry["description"])
114+ }
115+
116+ return nil
117+}
118+
119 func (deviceChannel *DeviceChannel) GetRelativeImage(revision int) (image Image, err error) {
120 var steps int
121 if revision < 0 {
122
123=== modified file 'ubuntuimage/types.go'
124--- ubuntuimage/types.go 2014-04-16 11:43:38 +0000
125+++ ubuntuimage/types.go 2014-10-02 08:49:00 +0000
126@@ -30,6 +30,12 @@
127
128 type Channels map[string]Channel
129
130+type ImageVersion struct {
131+ Description string
132+}
133+
134+type ImageVersions map[int]ImageVersion
135+
136 type File struct {
137 Server string
138 Checksum, Path, Signature string
139@@ -43,6 +49,7 @@
140 }
141
142 type DeviceChannel struct {
143+ Url string
144 Alias string
145 Images []Image
146 }

Subscribers

People subscribed via source and target branches