Merge lp:~chipaca/snapweb/filter-by-type into lp:~snappy-dev/snapweb/trunk

Proposed by John Lenton on 2015-05-06
Status: Merged
Approved by: Sergio Schvezov on 2015-05-07
Approved revision: 122
Merged at revision: 129
Proposed branch: lp:~chipaca/snapweb/filter-by-type
Merge into: lp:~snappy-dev/snapweb/trunk
Diff against target: 78 lines (+23/-3)
2 files modified
snappy/converge.go (+22/-2)
snappy/handlers.go (+1/-1)
To merge this branch: bzr merge lp:~chipaca/snapweb/filter-by-type
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-05-06 Approve on 2015-05-07
Review via email: mp+258408@code.launchpad.net

Commit Message

allPackages now filters by type.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

Hey, this looks good, but it won't work entirely, can you look at my inline comment?

review: Needs Fixing
lp:~chipaca/snapweb/filter-by-type updated on 2015-05-06
120. By John Lenton on 2015-05-06

don't look into non-aliased packages for now

Sergio Schvezov (sergiusens) wrote :

curl -X GET -d '{"types": ["oem"] }' http://localhost:4200/api/v2/packages/| python -m json.tool

returns a bigger list that just type oem, can you double check please?

Thanks for working on this, and I know this part is a consistency mess withing snappy.

review: Needs Fixing
lp:~chipaca/snapweb/filter-by-type updated on 2015-05-07
121. By John Lenton on 2015-05-07

Merged json-responses into filter-by-type.

122. By John Lenton on 2015-05-07

 Merged json-responses into filter-by-type.

Sergio Schvezov (sergiusens) wrote :

works like a charm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/converge.go'
2--- snappy/converge.go 2015-05-07 15:37:20 +0000
3+++ snappy/converge.go 2015-05-07 16:33:54 +0000
4@@ -18,6 +18,7 @@
5 package snappy
6
7 import (
8+ "regexp"
9 "sort"
10 "strconv"
11 "strings"
12@@ -86,7 +87,7 @@
13 return snapPkg{}, snappy.ErrPackageNotFound
14 }
15
16-func (h *Handler) allPackages(installedOnly bool) ([]snapPkg, error) {
17+func (h *Handler) allPackages(filter *listFilter) ([]snapPkg, error) {
18 mLocal := snappy.NewMetaLocalRepository()
19
20 installedSnaps, err := mLocal.Installed()
21@@ -94,8 +95,21 @@
22 return nil, err
23 }
24
25+ typeFilter := func(string) bool { return true }
26+
27+ if len(filter.Types) != 0 {
28+ regex, err := regexp.Compile("^(?:" + strings.Join(filter.Types, "|") + ")")
29+ if err != nil {
30+ return nil, err
31+ }
32+ typeFilter = regex.MatchString
33+ }
34+
35 installedSnapQs := make([]snapPkg, 0, len(installedSnaps))
36 for i := range installedSnaps {
37+ if !typeFilter(string(installedSnaps[i].Type())) {
38+ continue
39+ }
40 installedSnapQs = append(installedSnapQs, h.snapQueryToPayload(installedSnaps[i]))
41 }
42
43@@ -109,15 +123,21 @@
44
45 for _, remote := range remoteSnaps {
46 if alias := remote.Alias; alias != nil {
47+ if !typeFilter(string(alias.Type())) {
48+ continue
49+ }
50 remoteSnapQs = append(remoteSnapQs, h.snapQueryToPayload(alias))
51 } else {
52 for _, part := range remote.Parts {
53+ if !typeFilter(string(part.Type())) {
54+ continue
55+ }
56 remoteSnapQs = append(remoteSnapQs, h.snapQueryToPayload(part))
57 }
58 }
59 }
60
61- return mergeSnaps(installedSnapQs, remoteSnapQs, installedOnly), nil
62+ return mergeSnaps(installedSnapQs, remoteSnapQs, filter.InstalledOnly), nil
63 }
64
65 func (h *Handler) doRemovePackage(progress *webprogress.WebProgress, ID string) {
66
67=== modified file 'snappy/handlers.go'
68--- snappy/handlers.go 2015-05-06 23:40:58 +0000
69+++ snappy/handlers.go 2015-05-07 16:33:54 +0000
70@@ -67,7 +67,7 @@
71 return
72 }
73
74- payload, err := h.allPackages(filter.InstalledOnly)
75+ payload, err := h.allPackages(&filter)
76 if err != nil {
77 w.WriteHeader(http.StatusInternalServerError)
78 enc.Encode(fmt.Sprintf("Error: %s", err))

Subscribers

People subscribed via source and target branches

to all changes: