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
=== modified file 'ubuntu-device-flash/args.go'
--- ubuntu-device-flash/args.go 2014-09-03 12:53:40 +0000
+++ ubuntu-device-flash/args.go 2014-10-02 08:49:00 +0000
@@ -28,6 +28,7 @@
28 Revision int `long:"revision" description:"revision to flash, absolute or relative allowed"`28 Revision int `long:"revision" description:"revision to flash, absolute or relative allowed"`
29 Bootstrap bool `long:"bootstrap" description:"bootstrap the system, do this from the bootloader"`29 Bootstrap bool `long:"bootstrap" description:"bootstrap the system, do this from the bootloader"`
30 ListChannels bool `long:"list-channels" description:"List available channels"`30 ListChannels bool `long:"list-channels" description:"List available channels"`
31 ListImages bool `long:"list-images" description:"List available images for a channel"`
31 Wipe bool `long:"wipe" description:"Clear all data after flashing"`32 Wipe bool `long:"wipe" description:"Clear all data after flashing"`
32 Channel string `long:"channel" description:"Specify an alternate channel"`33 Channel string `long:"channel" description:"Specify an alternate channel"`
33 ShowImage bool `long:"show-image" description:"Show information for an image in the given channel"`34 ShowImage bool `long:"show-image" description:"Show information for an image in the given channel"`
3435
=== modified file 'ubuntu-device-flash/main.go'
--- ubuntu-device-flash/main.go 2014-09-25 13:40:20 +0000
+++ ubuntu-device-flash/main.go 2014-10-02 08:49:00 +0000
@@ -98,6 +98,25 @@
98 }98 }
99 return99 return
100 }100 }
101
102 if args.ListImages {
103 if args.Device == "" {
104 log.Fatal("You must specify a device type")
105 }
106
107 deviceChannel, err := channels.GetDeviceChannel(
108 args.Server, args.Channel, args.Device)
109 if err != nil {
110 log.Fatal(err)
111 }
112
113 err = deviceChannel.ListImageVersions()
114 if err != nil {
115 log.Fatal(err)
116 }
117 return
118 }
119
101 cacheDir := ubuntuimage.GetCacheDir()120 cacheDir := ubuntuimage.GetCacheDir()
102 if args.CleanCache {121 if args.CleanCache {
103 log.Print("Cleaning prevously downloaded content")122 log.Print("Cleaning prevously downloaded content")
104123
=== modified file 'ubuntuimage/channels.go'
--- ubuntuimage/channels.go 2014-04-16 17:00:53 +0000
+++ ubuntuimage/channels.go 2014-10-02 08:49:00 +0000
@@ -26,10 +26,12 @@
26 "errors"26 "errors"
27 "fmt"27 "fmt"
28 "net/http"28 "net/http"
29 "io/ioutil"
29)30)
3031
31const (32const (
32 channelsPath = "/channels.json"33 channelsPath = "/channels.json"
34 indexName = "index.json"
33 FULL_IMAGE = "full"35 FULL_IMAGE = "full"
34)36)
3537
@@ -80,6 +82,8 @@
80 return i1.Version > i2.Version82 return i1.Version > i2.Version
81 }83 }
82 ImageBy(order).ImageSort(deviceChannel.Images)84 ImageBy(order).ImageSort(deviceChannel.Images)
85
86 deviceChannel.Url = channelUri
83 return deviceChannel, err87 return deviceChannel, err
84}88}
8589
@@ -93,6 +97,53 @@
93 return image, fmt.Errorf("Failed to locate image %d", revision)97 return image, fmt.Errorf("Failed to locate image %d", revision)
94}98}
9599
100func (deviceChannel *DeviceChannel) ListImageVersions() (err error) {
101
102 jsonData := map[string]interface{}{}
103
104 resp, err := client.Get(deviceChannel.Url)
105 if err != nil {
106 return err
107 }
108
109 if (resp.StatusCode != 200) {
110 statusErr := errors.New(fmt.Sprintf("Invalid HTTP response: %d", resp.StatusCode))
111 return statusErr
112 }
113
114 defer resp.Body.Close()
115
116 body, err := ioutil.ReadAll(resp.Body)
117 if err != nil {
118 return err
119 }
120
121 err = json.Unmarshal(body, &jsonData)
122 if err != nil {
123 return err
124 }
125
126 images := jsonData["images"].([]interface{})
127
128 for i := range images {
129 entry := images[i].(map[string]interface{})
130
131 imageType := entry["type"]
132
133 if imageType != FULL_IMAGE {
134 // ignore delta images as they cannot be used to
135 // perform an initial device flash
136 continue
137 }
138
139 fmt.Printf("%d: description='%s'\n",
140 int(entry["version"].(float64)),
141 entry["description"])
142 }
143
144 return nil
145}
146
96func (deviceChannel *DeviceChannel) GetRelativeImage(revision int) (image Image, err error) {147func (deviceChannel *DeviceChannel) GetRelativeImage(revision int) (image Image, err error) {
97 var steps int148 var steps int
98 if revision < 0 {149 if revision < 0 {
99150
=== modified file 'ubuntuimage/types.go'
--- ubuntuimage/types.go 2014-04-16 11:43:38 +0000
+++ ubuntuimage/types.go 2014-10-02 08:49:00 +0000
@@ -30,6 +30,12 @@
3030
31type Channels map[string]Channel31type Channels map[string]Channel
3232
33type ImageVersion struct {
34 Description string
35}
36
37type ImageVersions map[int]ImageVersion
38
33type File struct {39type File struct {
34 Server string40 Server string
35 Checksum, Path, Signature string41 Checksum, Path, Signature string
@@ -43,6 +49,7 @@
43}49}
4450
45type DeviceChannel struct {51type DeviceChannel struct {
52 Url string
46 Alias string53 Alias string
47 Images []Image54 Images []Image
48}55}

Subscribers

People subscribed via source and target branches