Merge lp:~chipaca/snappy/pkg-types into lp:~snappy-dev/snappy/snappy-moved-to-github
- pkg-types
- Merge into snappy-moved-to-github
Proposed by
John Lenton
Status: | Merged |
---|---|
Approved by: | Sergio Schvezov |
Approved revision: | 463 |
Merged at revision: | 464 |
Proposed branch: | lp:~chipaca/snappy/pkg-types |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
990 lines (+210/-128) 24 files modified
cmd/snappy/cmd_booted.go (+2/-1) cmd/snappy/cmd_info.go (+4/-3) cmd/snappy/cmd_list.go (+2/-1) cmd/snappy/cmd_search.go (+2/-1) pkg/types.go (+58/-0) pkg/types_test.go (+64/-0) snappy/click.go (+10/-9) snappy/click_test.go (+2/-1) snappy/common_test.go (+5/-4) snappy/errors.go (+1/-1) snappy/firstboot.go (+2/-1) snappy/firstboot_test.go (+8/-6) snappy/oem.go (+2/-1) snappy/parts.go (+5/-39) snappy/parts_test.go (+3/-2) snappy/remove_test.go (+7/-5) snappy/rollback_test.go (+5/-3) snappy/security.go (+2/-1) snappy/security_test.go (+3/-1) snappy/set_test.go (+2/-1) snappy/snapp.go (+12/-11) snappy/snapp_test.go (+2/-32) snappy/systemimage.go (+4/-3) snappy/udev.go (+3/-1) |
To merge this branch: | bzr merge lp:~chipaca/snappy/pkg-types |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sergio Schvezov | Approve | ||
Review via email: mp+259485@code.launchpad.net |
Commit message
Move SnapType -> pkg.Type
Description of the change
To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote : | # |
I think saying that that will be in the _next_ MP would be ambitious. But soon.
Whether it's pkg/oem or pkg/snap/oem (with common snap-level things in snap) is unclear to me at this point, I'm keeping an open mind until I've finished worrying the code some more.
Interfaces would be in pkg, unless it got too hairy in which case I wouldn't mind pkg/interface or some such.
The fractal nature of the dependencies right now makes it hard for me to give concrete answers. You probably have more of all of this in your head, so we should discuss.
Revision history for this message
Sergio Schvezov (sergiusens) wrote : | # |
The road map feels excellent so this gets to land!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmd/snappy/cmd_booted.go' |
2 | --- cmd/snappy/cmd_booted.go 2015-05-18 19:05:50 +0000 |
3 | +++ cmd/snappy/cmd_booted.go 2015-05-19 11:17:28 +0000 |
4 | @@ -19,6 +19,7 @@ |
5 | |
6 | import ( |
7 | "launchpad.net/snappy/logger" |
8 | + "launchpad.net/snappy/pkg" |
9 | "launchpad.net/snappy/priv" |
10 | "launchpad.net/snappy/snappy" |
11 | ) |
12 | @@ -43,7 +44,7 @@ |
13 | } |
14 | defer privMutex.Unlock() |
15 | |
16 | - parts, err := snappy.ActiveSnapsByType(snappy.SnapTypeCore) |
17 | + parts, err := snappy.ActiveSnapsByType(pkg.TypeCore) |
18 | if err != nil { |
19 | return err |
20 | } |
21 | |
22 | === modified file 'cmd/snappy/cmd_info.go' |
23 | --- cmd/snappy/cmd_info.go 2015-05-18 19:05:50 +0000 |
24 | +++ cmd/snappy/cmd_info.go 2015-05-19 11:17:28 +0000 |
25 | @@ -22,6 +22,7 @@ |
26 | "strings" |
27 | |
28 | "launchpad.net/snappy/logger" |
29 | + "launchpad.net/snappy/pkg" |
30 | "launchpad.net/snappy/snappy" |
31 | ) |
32 | |
33 | @@ -80,7 +81,7 @@ |
34 | } |
35 | |
36 | func ubuntuCoreChannel() string { |
37 | - parts, err := snappy.ActiveSnapsByType(snappy.SnapTypeCore) |
38 | + parts, err := snappy.ActiveSnapsByType(pkg.TypeCore) |
39 | if len(parts) == 1 && err == nil { |
40 | return parts[0].Channel() |
41 | } |
42 | @@ -90,8 +91,8 @@ |
43 | |
44 | func info() error { |
45 | release := ubuntuCoreChannel() |
46 | - frameworks, _ := snappy.ActiveSnapNamesByType(snappy.SnapTypeFramework) |
47 | - apps, _ := snappy.ActiveSnapNamesByType(snappy.SnapTypeApp) |
48 | + frameworks, _ := snappy.ActiveSnapNamesByType(pkg.TypeFramework) |
49 | + apps, _ := snappy.ActiveSnapNamesByType(pkg.TypeApp) |
50 | |
51 | fmt.Printf("release: %s\n", release) |
52 | fmt.Printf("architecture: %s\n", snappy.Architecture()) |
53 | |
54 | === modified file 'cmd/snappy/cmd_list.go' |
55 | --- cmd/snappy/cmd_list.go 2015-05-18 19:05:50 +0000 |
56 | +++ cmd/snappy/cmd_list.go 2015-05-19 11:17:28 +0000 |
57 | @@ -25,6 +25,7 @@ |
58 | "time" |
59 | |
60 | "launchpad.net/snappy/logger" |
61 | + "launchpad.net/snappy/pkg" |
62 | "launchpad.net/snappy/snappy" |
63 | ) |
64 | |
65 | @@ -134,7 +135,7 @@ |
66 | // there are only two version instaleld and |
67 | // there is only a single part that may requires |
68 | // a reboot |
69 | - if part.Type() != snappy.SnapTypeCore { |
70 | + if part.Type() != pkg.TypeCore { |
71 | continue |
72 | } |
73 | |
74 | |
75 | === modified file 'cmd/snappy/cmd_search.go' |
76 | --- cmd/snappy/cmd_search.go 2015-05-18 19:05:50 +0000 |
77 | +++ cmd/snappy/cmd_search.go 2015-05-19 11:17:28 +0000 |
78 | @@ -23,6 +23,7 @@ |
79 | "text/tabwriter" |
80 | |
81 | "launchpad.net/snappy/logger" |
82 | + "launchpad.net/snappy/pkg" |
83 | "launchpad.net/snappy/snappy" |
84 | ) |
85 | |
86 | @@ -68,7 +69,7 @@ |
87 | } |
88 | } else { |
89 | for _, part := range sharedName.Parts { |
90 | - if sharedName.IsAlias(part.Namespace()) || part.Type() == snappy.SnapTypeFramework { |
91 | + if sharedName.IsAlias(part.Namespace()) || part.Type() == pkg.TypeFramework { |
92 | fmt.Fprintln(w, fmt.Sprintf("%s\t%s\t%s\t", part.Name(), part.Version(), part.Description())) |
93 | } else { |
94 | fmt.Fprintln(w, fmt.Sprintf("%s.%s\t%s\t%s\t", part.Name(), part.Namespace(), part.Version(), part.Description())) |
95 | |
96 | === added directory 'pkg' |
97 | === added file 'pkg/types.go' |
98 | --- pkg/types.go 1970-01-01 00:00:00 +0000 |
99 | +++ pkg/types.go 2015-05-19 11:17:28 +0000 |
100 | @@ -0,0 +1,58 @@ |
101 | +/* |
102 | + * Copyright (C) 2014-2015 Canonical Ltd |
103 | + * |
104 | + * This program is free software: you can redistribute it and/or modify |
105 | + * it under the terms of the GNU General Public License version 3 as |
106 | + * published by the Free Software Foundation. |
107 | + * |
108 | + * This program is distributed in the hope that it will be useful, |
109 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
110 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
111 | + * GNU General Public License for more details. |
112 | + * |
113 | + * You should have received a copy of the GNU General Public License |
114 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
115 | + * |
116 | + */ |
117 | + |
118 | +// Package pkg packages odds and ends that apply to packages in more than one |
119 | +// layer (to more than one of deb, click, snap, and part). |
120 | +package pkg |
121 | + |
122 | +import ( |
123 | + "encoding/json" |
124 | +) |
125 | + |
126 | +// Type represents the kind of snap (app, core, frameworks, oem) |
127 | +type Type string |
128 | + |
129 | +// The various types of snap parts we support |
130 | +const ( |
131 | + TypeApp Type = "app" |
132 | + TypeCore Type = "core" |
133 | + TypeFramework Type = "framework" |
134 | + TypeOem Type = "oem" |
135 | +) |
136 | + |
137 | +// MarshalJSON returns *m as the JSON encoding of m. |
138 | +func (m Type) MarshalJSON() ([]byte, error) { |
139 | + return json.Marshal(string(m)) |
140 | +} |
141 | + |
142 | +// UnmarshalJSON sets *m to a copy of data. |
143 | +func (m *Type) UnmarshalJSON(data []byte) error { |
144 | + var str string |
145 | + if err := json.Unmarshal(data, &str); err != nil { |
146 | + return err |
147 | + } |
148 | + |
149 | + // this is a workaround as the store sends "application" but snappy uses |
150 | + // "app" for TypeApp |
151 | + if str == "application" { |
152 | + *m = TypeApp |
153 | + } else { |
154 | + *m = Type(str) |
155 | + } |
156 | + |
157 | + return nil |
158 | +} |
159 | |
160 | === added file 'pkg/types_test.go' |
161 | --- pkg/types_test.go 1970-01-01 00:00:00 +0000 |
162 | +++ pkg/types_test.go 2015-05-19 11:17:28 +0000 |
163 | @@ -0,0 +1,64 @@ |
164 | +/* |
165 | + * Copyright (C) 2014-2015 Canonical Ltd |
166 | + * |
167 | + * This program is free software: you can redistribute it and/or modify |
168 | + * it under the terms of the GNU General Public License version 3 as |
169 | + * published by the Free Software Foundation. |
170 | + * |
171 | + * This program is distributed in the hope that it will be useful, |
172 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
173 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
174 | + * GNU General Public License for more details. |
175 | + * |
176 | + * You should have received a copy of the GNU General Public License |
177 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
178 | + * |
179 | + */ |
180 | + |
181 | +package pkg |
182 | + |
183 | +import ( |
184 | + "encoding/json" |
185 | + "testing" |
186 | + |
187 | + . "launchpad.net/gocheck" |
188 | +) |
189 | + |
190 | +type typeSuite struct{} |
191 | + |
192 | +// Hook up gocheck into the "go test" runner |
193 | +func Test(t *testing.T) { TestingT(t) } |
194 | + |
195 | +var _ = Suite(&typeSuite{}) |
196 | + |
197 | +func (s *typeSuite) TestJSONerr(c *C) { |
198 | + var t Type |
199 | + err := json.Unmarshal([]byte("false"), &t) |
200 | + c.Assert(err, NotNil) |
201 | +} |
202 | + |
203 | +func (s *typeSuite) TestMarshalTypes(c *C) { |
204 | + out, err := json.Marshal(TypeApp) |
205 | + c.Assert(err, IsNil) |
206 | + c.Check(string(out), Equals, "\"app\"") |
207 | + |
208 | + out, err = json.Marshal(TypeOem) |
209 | + c.Assert(err, IsNil) |
210 | + c.Check(string(out), Equals, "\"oem\"") |
211 | +} |
212 | + |
213 | +func (s *typeSuite) TestUnmarshalTypes(c *C) { |
214 | + var st Type |
215 | + |
216 | + err := json.Unmarshal([]byte("\"application\""), &st) |
217 | + c.Assert(err, IsNil) |
218 | + c.Check(st, Equals, TypeApp) |
219 | + |
220 | + err = json.Unmarshal([]byte("\"app\""), &st) |
221 | + c.Assert(err, IsNil) |
222 | + c.Check(st, Equals, TypeApp) |
223 | + |
224 | + err = json.Unmarshal([]byte("\"oem\""), &st) |
225 | + c.Assert(err, IsNil) |
226 | + c.Check(st, Equals, TypeOem) |
227 | +} |
228 | |
229 | === modified file 'snappy/click.go' |
230 | --- snappy/click.go 2015-05-18 19:15:37 +0000 |
231 | +++ snappy/click.go 2015-05-19 11:17:28 +0000 |
232 | @@ -43,6 +43,7 @@ |
233 | "launchpad.net/snappy/clickdeb" |
234 | "launchpad.net/snappy/helpers" |
235 | "launchpad.net/snappy/logger" |
236 | + "launchpad.net/snappy/pkg" |
237 | "launchpad.net/snappy/policy" |
238 | "launchpad.net/snappy/systemd" |
239 | |
240 | @@ -55,7 +56,7 @@ |
241 | Name string `json:"name"` |
242 | Version string `json:"version"` |
243 | Architecture []string `json:"architecture,omitempty"` |
244 | - Type SnapType `json:"type,omitempty"` |
245 | + Type pkg.Type `json:"type,omitempty"` |
246 | Framework string `json:"framework,omitempty"` |
247 | Description string `json:"description,omitempty"` |
248 | Icon string `json:"icon,omitempty"` |
249 | @@ -300,7 +301,7 @@ |
250 | // generate the name |
251 | func generateBinaryName(m *packageYaml, binary Binary) string { |
252 | var binName string |
253 | - if m.Type == SnapTypeFramework { |
254 | + if m.Type == pkg.TypeFramework { |
255 | binName = filepath.Base(binary.Name) |
256 | } else { |
257 | binName = fmt.Sprintf("%s.%s", m.Name, filepath.Base(binary.Name)) |
258 | @@ -469,7 +470,7 @@ |
259 | PostStop: service.PostStop, |
260 | StopTimeout: time.Duration(service.StopTimeout), |
261 | AaProfile: aaProfile, |
262 | - IsFramework: m.Type == SnapTypeFramework, |
263 | + IsFramework: m.Type == pkg.TypeFramework, |
264 | BusName: service.BusName, |
265 | UdevAppName: udevPartName, |
266 | }), nil |
267 | @@ -533,7 +534,7 @@ |
268 | |
269 | // If necessary, generate the DBus policy file so the framework |
270 | // service is allowed to start |
271 | - if m.Type == SnapTypeFramework && service.BusName != "" { |
272 | + if m.Type == pkg.TypeFramework && service.BusName != "" { |
273 | content, err := genBusPolicyFile(service.BusName) |
274 | if err != nil { |
275 | return err |
276 | @@ -796,7 +797,7 @@ |
277 | return err |
278 | } |
279 | |
280 | - if cm.Type != SnapTypeFramework && cm.Type != SnapTypeOem { |
281 | + if cm.Type != pkg.TypeFramework && cm.Type != pkg.TypeOem { |
282 | // add the namespace to the name |
283 | cm.Name = fmt.Sprintf("%s.%s", cm.Name, namespace) |
284 | } |
285 | @@ -861,7 +862,7 @@ |
286 | |
287 | targetDir := snapAppsDir |
288 | // the "oem" parts are special |
289 | - if manifest.Type == SnapTypeOem { |
290 | + if manifest.Type == pkg.TypeOem { |
291 | targetDir = snapOemDir |
292 | |
293 | // TODO do the following at a higher level once the store publishes snap types |
294 | @@ -885,7 +886,7 @@ |
295 | |
296 | fullName := manifest.Name |
297 | // namespacing only applies to apps. |
298 | - if manifest.Type != SnapTypeFramework && manifest.Type != SnapTypeOem { |
299 | + if manifest.Type != pkg.TypeFramework && manifest.Type != pkg.TypeOem { |
300 | fullName += "." + namespace |
301 | } |
302 | instDir := filepath.Join(targetDir, fullName, manifest.Version) |
303 | @@ -1158,7 +1159,7 @@ |
304 | return err |
305 | } |
306 | |
307 | - if manifest.Type == SnapTypeFramework { |
308 | + if manifest.Type == pkg.TypeFramework { |
309 | |
310 | if err := policy.Remove(m.Name, clickDir); err != nil { |
311 | return err |
312 | @@ -1204,7 +1205,7 @@ |
313 | return err |
314 | } |
315 | |
316 | - if newActiveManifest.Type == SnapTypeFramework { |
317 | + if newActiveManifest.Type == pkg.TypeFramework { |
318 | if err := policy.Install(m.Name, baseDir); err != nil { |
319 | return err |
320 | } |
321 | |
322 | === modified file 'snappy/click_test.go' |
323 | --- snappy/click_test.go 2015-05-16 15:29:55 +0000 |
324 | +++ snappy/click_test.go 2015-05-19 11:17:28 +0000 |
325 | @@ -32,6 +32,7 @@ |
326 | |
327 | "launchpad.net/snappy/clickdeb" |
328 | "launchpad.net/snappy/helpers" |
329 | + "launchpad.net/snappy/pkg" |
330 | "launchpad.net/snappy/policy" |
331 | "launchpad.net/snappy/progress" |
332 | "launchpad.net/snappy/systemd" |
333 | @@ -1237,7 +1238,7 @@ |
334 | m := packageYaml{ |
335 | Name: "xkcd-webserver", |
336 | Version: "0.3.4", |
337 | - Type: SnapTypeFramework, |
338 | + Type: pkg.TypeFramework, |
339 | } |
340 | |
341 | generatedWrapper, err := generateSnapServicesFile(service, pkgPath, aaProfile, &m) |
342 | |
343 | === modified file 'snappy/common_test.go' |
344 | --- snappy/common_test.go 2015-05-06 12:26:38 +0000 |
345 | +++ snappy/common_test.go 2015-05-19 11:17:28 +0000 |
346 | @@ -23,12 +23,13 @@ |
347 | "os" |
348 | "path" |
349 | "path/filepath" |
350 | + "strings" |
351 | |
352 | "launchpad.net/snappy/helpers" |
353 | + "launchpad.net/snappy/pkg" |
354 | |
355 | "gopkg.in/yaml.v2" |
356 | . "launchpad.net/gocheck" |
357 | - "strings" |
358 | ) |
359 | |
360 | const ( |
361 | @@ -147,10 +148,10 @@ |
362 | return path.Join(tmpdir, snapFile) |
363 | } |
364 | |
365 | -// makeTwoTestSnaps creates two real snaps of SnapType of name |
366 | +// makeTwoTestSnaps creates two real snaps of pkg.Type of name |
367 | // "foo", with version "1.0" and "2.0", "2.0" being marked as the |
368 | // active snap. |
369 | -func makeTwoTestSnaps(c *C, snapType SnapType, extra ...string) { |
370 | +func makeTwoTestSnaps(c *C, snapType pkg.Type, extra ...string) { |
371 | inter := &MockProgressMeter{} |
372 | |
373 | packageYaml := `name: foo |
374 | @@ -161,7 +162,7 @@ |
375 | packageYaml += strings.Join(extra, "\n") + "\n" |
376 | } |
377 | |
378 | - if snapType != SnapTypeApp { |
379 | + if snapType != pkg.TypeApp { |
380 | packageYaml += fmt.Sprintf("type: %s\n", snapType) |
381 | } |
382 | |
383 | |
384 | === modified file 'snappy/errors.go' |
385 | --- snappy/errors.go 2015-05-18 19:15:37 +0000 |
386 | +++ snappy/errors.go 2015-05-19 11:17:28 +0000 |
387 | @@ -119,7 +119,7 @@ |
388 | // an interface is partial. |
389 | ErrNotImplemented = errors.New("not implemented") |
390 | |
391 | - // ErrNoOemConfiguration may be returned when there is a SnapTypeOem installed |
392 | + // ErrNoOemConfiguration may be returned when there is a pkg.TypeOem installed |
393 | // but does not provide a configuration. |
394 | ErrNoOemConfiguration = errors.New("no configuration entry found in the oem snap") |
395 | |
396 | |
397 | === modified file 'snappy/firstboot.go' |
398 | --- snappy/firstboot.go 2015-05-08 16:07:35 +0000 |
399 | +++ snappy/firstboot.go 2015-05-19 11:17:28 +0000 |
400 | @@ -24,6 +24,7 @@ |
401 | "path/filepath" |
402 | |
403 | "launchpad.net/snappy/helpers" |
404 | + "launchpad.net/snappy/pkg" |
405 | |
406 | "gopkg.in/yaml.v2" |
407 | ) |
408 | @@ -54,7 +55,7 @@ |
409 | } |
410 | defer stampFirstBoot() |
411 | |
412 | - oemSnap, err := activeSnapsByType(SnapTypeOem) |
413 | + oemSnap, err := activeSnapsByType(pkg.TypeOem) |
414 | if err != nil { |
415 | return err |
416 | } |
417 | |
418 | === modified file 'snappy/firstboot_test.go' |
419 | --- snappy/firstboot_test.go 2015-04-14 16:46:57 +0000 |
420 | +++ snappy/firstboot_test.go 2015-05-19 11:17:28 +0000 |
421 | @@ -23,13 +23,15 @@ |
422 | "path/filepath" |
423 | |
424 | . "launchpad.net/gocheck" |
425 | + |
426 | + "launchpad.net/snappy/pkg" |
427 | ) |
428 | |
429 | type fakePart struct { |
430 | SnapPart |
431 | config []byte |
432 | oemConfig SystemConfig |
433 | - snapType SnapType |
434 | + snapType pkg.Type |
435 | } |
436 | |
437 | func (p *fakePart) Config(b []byte) (string, error) { |
438 | @@ -41,7 +43,7 @@ |
439 | return p.oemConfig |
440 | } |
441 | |
442 | -func (p *fakePart) Type() SnapType { |
443 | +func (p *fakePart) Type() pkg.Type { |
444 | return p.snapType |
445 | } |
446 | |
447 | @@ -69,8 +71,8 @@ |
448 | } |
449 | |
450 | func (s *FirstBootTestSuite) mockActiveSnapNamesByType() *fakePart { |
451 | - fakeOem := fakePart{oemConfig: s.oemConfig, snapType: SnapTypeOem} |
452 | - activeSnapsByType = func(snapsTs ...SnapType) ([]Part, error) { |
453 | + fakeOem := fakePart{oemConfig: s.oemConfig, snapType: pkg.TypeOem} |
454 | + activeSnapsByType = func(snapsTs ...pkg.Type) ([]Part, error) { |
455 | return []Part{&fakeOem}, nil |
456 | } |
457 | |
458 | @@ -78,7 +80,7 @@ |
459 | } |
460 | |
461 | func (s *FirstBootTestSuite) mockActiveSnapByName() *fakePart { |
462 | - fakeMyApp := fakePart{snapType: SnapTypeApp} |
463 | + fakeMyApp := fakePart{snapType: pkg.TypeApp} |
464 | activeSnapByName = func(needle string) Part { |
465 | return &fakeMyApp |
466 | } |
467 | @@ -108,7 +110,7 @@ |
468 | } |
469 | |
470 | func (s *FirstBootTestSuite) TestNoErrorWhenNoOEM(c *C) { |
471 | - activeSnapsByType = func(snapsTs ...SnapType) ([]Part, error) { |
472 | + activeSnapsByType = func(snapsTs ...pkg.Type) ([]Part, error) { |
473 | return nil, nil |
474 | } |
475 | |
476 | |
477 | === modified file 'snappy/oem.go' |
478 | --- snappy/oem.go 2015-05-11 16:06:50 +0000 |
479 | +++ snappy/oem.go 2015-05-19 11:17:28 +0000 |
480 | @@ -31,6 +31,7 @@ |
481 | |
482 | "launchpad.net/snappy/helpers" |
483 | "launchpad.net/snappy/logger" |
484 | + "launchpad.net/snappy/pkg" |
485 | ) |
486 | |
487 | // OEM represents the structure inside the package.yaml for the oem component |
488 | @@ -101,7 +102,7 @@ |
489 | var getOem = getOemImpl |
490 | |
491 | var getOemImpl = func() (*packageYaml, error) { |
492 | - oems, _ := ActiveSnapsByType(SnapTypeOem) |
493 | + oems, _ := ActiveSnapsByType(pkg.TypeOem) |
494 | if len(oems) == 1 { |
495 | return oems[0].(*SnapPart).m, nil |
496 | } |
497 | |
498 | === modified file 'snappy/parts.go' |
499 | --- snappy/parts.go 2015-05-07 15:19:05 +0000 |
500 | +++ snappy/parts.go 2015-05-19 11:17:28 +0000 |
501 | @@ -18,53 +18,19 @@ |
502 | package snappy |
503 | |
504 | import ( |
505 | - "encoding/json" |
506 | "fmt" |
507 | "net" |
508 | "net/url" |
509 | "strings" |
510 | "time" |
511 | |
512 | + "launchpad.net/snappy/pkg" |
513 | "launchpad.net/snappy/progress" |
514 | ) |
515 | |
516 | -// SnapType represents the kind of snap (app, core, frameworks, oem) |
517 | -type SnapType string |
518 | - |
519 | -// MarshalJSON returns *m as the JSON encoding of m. |
520 | -func (m SnapType) MarshalJSON() ([]byte, error) { |
521 | - return json.Marshal(string(m)) |
522 | -} |
523 | - |
524 | -// UnmarshalJSON sets *m to a copy of data. |
525 | -func (m *SnapType) UnmarshalJSON(data []byte) error { |
526 | - var str string |
527 | - if err := json.Unmarshal(data, &str); err != nil { |
528 | - return err |
529 | - } |
530 | - |
531 | - // this is a workaround as the store sends "application" but snappy uses |
532 | - // "app" for SnapTypeApp |
533 | - if str == "application" { |
534 | - *m = SnapTypeApp |
535 | - } else { |
536 | - *m = SnapType(str) |
537 | - } |
538 | - |
539 | - return nil |
540 | -} |
541 | - |
542 | // SystemConfig is a config map holding configs for multiple packages |
543 | type SystemConfig map[string]interface{} |
544 | |
545 | -// The various types of snap parts we support |
546 | -const ( |
547 | - SnapTypeApp SnapType = "app" |
548 | - SnapTypeCore SnapType = "core" |
549 | - SnapTypeFramework SnapType = "framework" |
550 | - SnapTypeOem SnapType = "oem" |
551 | -) |
552 | - |
553 | // Services implements snappy packages that offer services |
554 | type Services interface { |
555 | Services() []Service |
556 | @@ -78,7 +44,7 @@ |
557 | // Dirname of a Part is the Name, in most cases qualified with the |
558 | // Namespace |
559 | func Dirname(p Part) string { |
560 | - if t := p.Type(); t == SnapTypeFramework || t == SnapTypeOem { |
561 | + if t := p.Type(); t == pkg.TypeFramework || t == pkg.TypeOem { |
562 | return p.Name() |
563 | } |
564 | return p.Name() + "." + p.Namespace() |
565 | @@ -110,7 +76,7 @@ |
566 | Icon() string |
567 | |
568 | // Returns app, framework, core |
569 | - Type() SnapType |
570 | + Type() pkg.Type |
571 | |
572 | InstalledSize() int64 |
573 | DownloadSize() int64 |
574 | @@ -237,7 +203,7 @@ |
575 | } |
576 | |
577 | // ActiveSnapsByType returns all installed snaps with the given type |
578 | -func ActiveSnapsByType(snapTs ...SnapType) (res []Part, err error) { |
579 | +func ActiveSnapsByType(snapTs ...pkg.Type) (res []Part, err error) { |
580 | m := NewMetaRepository() |
581 | installed, err := m.Installed() |
582 | if err != nil { |
583 | @@ -261,7 +227,7 @@ |
584 | // ActiveSnapNamesByType returns all installed snap names with the given type |
585 | var ActiveSnapNamesByType = activeSnapNamesByTypeImpl |
586 | |
587 | -func activeSnapNamesByTypeImpl(snapTs ...SnapType) (res []string, err error) { |
588 | +func activeSnapNamesByTypeImpl(snapTs ...pkg.Type) (res []string, err error) { |
589 | installed, err := ActiveSnapsByType(snapTs...) |
590 | for _, part := range installed { |
591 | res = append(res, part.Name()) |
592 | |
593 | === modified file 'snappy/parts_test.go' |
594 | --- snappy/parts_test.go 2015-04-21 12:05:22 +0000 |
595 | +++ snappy/parts_test.go 2015-05-19 11:17:28 +0000 |
596 | @@ -24,6 +24,7 @@ |
597 | |
598 | . "launchpad.net/gocheck" |
599 | |
600 | + "launchpad.net/snappy/pkg" |
601 | "launchpad.net/snappy/progress" |
602 | ) |
603 | |
604 | @@ -43,12 +44,12 @@ |
605 | c.Assert(err, IsNil) |
606 | makeSnapActive(yamlPath) |
607 | |
608 | - parts, err := ActiveSnapsByType(SnapTypeApp) |
609 | + parts, err := ActiveSnapsByType(pkg.TypeApp) |
610 | c.Assert(err, IsNil) |
611 | c.Assert(parts, HasLen, 1) |
612 | c.Assert(parts[0].Name(), Equals, "app1") |
613 | |
614 | - parts, err = ActiveSnapsByType(SnapTypeFramework) |
615 | + parts, err = ActiveSnapsByType(pkg.TypeFramework) |
616 | c.Assert(err, IsNil) |
617 | c.Assert(parts, HasLen, 1) |
618 | c.Assert(parts[0].Name(), Equals, "framework1") |
619 | |
620 | === modified file 'snappy/remove_test.go' |
621 | --- snappy/remove_test.go 2015-04-15 13:17:22 +0000 |
622 | +++ snappy/remove_test.go 2015-05-19 11:17:28 +0000 |
623 | @@ -19,6 +19,8 @@ |
624 | |
625 | import ( |
626 | . "launchpad.net/gocheck" |
627 | + |
628 | + "launchpad.net/snappy/pkg" |
629 | "launchpad.net/snappy/progress" |
630 | ) |
631 | |
632 | @@ -30,7 +32,7 @@ |
633 | } |
634 | |
635 | func (s *SnapTestSuite) TestSnapRemoveByVersion(c *C) { |
636 | - makeTwoTestSnaps(c, SnapTypeApp) |
637 | + makeTwoTestSnaps(c, pkg.TypeApp) |
638 | |
639 | err := Remove("foo=1.0", 0, &progress.NullProgress{}) |
640 | |
641 | @@ -41,7 +43,7 @@ |
642 | } |
643 | |
644 | func (s *SnapTestSuite) TestSnapRemoveActive(c *C) { |
645 | - makeTwoTestSnaps(c, SnapTypeApp) |
646 | + makeTwoTestSnaps(c, pkg.TypeApp) |
647 | |
648 | err := Remove("foo", 0, &progress.NullProgress{}) |
649 | |
650 | @@ -52,7 +54,7 @@ |
651 | } |
652 | |
653 | func (s *SnapTestSuite) TestSnapRemoveActiveOemFails(c *C) { |
654 | - makeTwoTestSnaps(c, SnapTypeOem) |
655 | + makeTwoTestSnaps(c, pkg.TypeOem) |
656 | |
657 | err := Remove("foo", 0, &progress.NullProgress{}) |
658 | c.Assert(err, DeepEquals, ErrPackageNotRemovable) |
659 | @@ -67,13 +69,13 @@ |
660 | installed, err := m.Installed() |
661 | c.Assert(err, IsNil) |
662 | c.Assert(installed[0].Name(), Equals, "foo") |
663 | - c.Assert(installed[0].Type(), Equals, SnapTypeOem) |
664 | + c.Assert(installed[0].Type(), Equals, pkg.TypeOem) |
665 | c.Assert(installed[0].Version(), Equals, "2.0") |
666 | c.Assert(installed, HasLen, 1) |
667 | } |
668 | |
669 | func (s *SnapTestSuite) TestSnapRemoveGC(c *C) { |
670 | - makeTwoTestSnaps(c, SnapTypeApp) |
671 | + makeTwoTestSnaps(c, pkg.TypeApp) |
672 | err := Remove("foo", DoRemoveGC, &progress.NullProgress{}) |
673 | c.Assert(err, IsNil) |
674 | m := NewMetaRepository() |
675 | |
676 | === modified file 'snappy/rollback_test.go' |
677 | --- snappy/rollback_test.go 2015-04-30 16:56:15 +0000 |
678 | +++ snappy/rollback_test.go 2015-05-19 11:17:28 +0000 |
679 | @@ -19,10 +19,12 @@ |
680 | |
681 | import ( |
682 | . "launchpad.net/gocheck" |
683 | + |
684 | + "launchpad.net/snappy/pkg" |
685 | ) |
686 | |
687 | func (s *SnapTestSuite) TestRollbackWithVersion(c *C) { |
688 | - makeTwoTestSnaps(c, SnapTypeApp) |
689 | + makeTwoTestSnaps(c, pkg.TypeApp) |
690 | c.Assert(ActiveSnapByName("foo").Version(), Equals, "2.0") |
691 | |
692 | // rollback with version |
693 | @@ -34,7 +36,7 @@ |
694 | } |
695 | |
696 | func (s *SnapTestSuite) TestRollbackFindVersion(c *C) { |
697 | - makeTwoTestSnaps(c, SnapTypeApp) |
698 | + makeTwoTestSnaps(c, pkg.TypeApp) |
699 | c.Assert(ActiveSnapByName("foo").Version(), Equals, "2.0") |
700 | |
701 | // rollback without version |
702 | @@ -46,7 +48,7 @@ |
703 | } |
704 | |
705 | func (s *SnapTestSuite) TestRollbackService(c *C) { |
706 | - makeTwoTestSnaps(c, SnapTypeApp, `services: |
707 | + makeTwoTestSnaps(c, pkg.TypeApp, `services: |
708 | - name: svc1 |
709 | `) |
710 | pkg := ActiveSnapByName("foo") |
711 | |
712 | === modified file 'snappy/security.go' |
713 | --- snappy/security.go 2015-05-18 19:05:50 +0000 |
714 | +++ snappy/security.go 2015-05-19 11:17:28 +0000 |
715 | @@ -12,6 +12,7 @@ |
716 | |
717 | "launchpad.net/snappy/helpers" |
718 | "launchpad.net/snappy/logger" |
719 | + "launchpad.net/snappy/pkg" |
720 | ) |
721 | |
722 | type apparmorJSONTemplate struct { |
723 | @@ -112,7 +113,7 @@ |
724 | |
725 | func getSecurityProfile(m *packageYaml, appName, baseDir string) (string, error) { |
726 | cleanedName := strings.Replace(appName, "/", "-", -1) |
727 | - if m.Type == SnapTypeFramework || m.Type == SnapTypeOem { |
728 | + if m.Type == pkg.TypeFramework || m.Type == pkg.TypeOem { |
729 | return fmt.Sprintf("%s_%s_%s", m.Name, cleanedName, m.Version), nil |
730 | } |
731 | |
732 | |
733 | === modified file 'snappy/security_test.go' |
734 | --- snappy/security_test.go 2015-04-19 14:02:33 +0000 |
735 | +++ snappy/security_test.go 2015-05-19 11:17:28 +0000 |
736 | @@ -6,6 +6,8 @@ |
737 | "path/filepath" |
738 | |
739 | . "launchpad.net/gocheck" |
740 | + |
741 | + "launchpad.net/snappy/pkg" |
742 | ) |
743 | |
744 | type SecurityTestSuite struct { |
745 | @@ -143,7 +145,7 @@ |
746 | m := packageYaml{ |
747 | Name: "foo", |
748 | Version: "1.0", |
749 | - Type: SnapTypeFramework, |
750 | + Type: pkg.TypeFramework, |
751 | } |
752 | b := Binary{Name: "bin/app"} |
753 | ap, err := getSecurityProfile(&m, b.Name, "/apps/foo.mvo/1.0/") |
754 | |
755 | === modified file 'snappy/set_test.go' |
756 | --- snappy/set_test.go 2015-04-30 16:56:15 +0000 |
757 | +++ snappy/set_test.go 2015-05-19 11:17:28 +0000 |
758 | @@ -24,6 +24,7 @@ |
759 | |
760 | . "launchpad.net/gocheck" |
761 | |
762 | + "launchpad.net/snappy/pkg" |
763 | "launchpad.net/snappy/progress" |
764 | ) |
765 | |
766 | @@ -73,7 +74,7 @@ |
767 | } |
768 | |
769 | func (s *SnapTestSuite) TestSetActive(c *C) { |
770 | - makeTwoTestSnaps(c, SnapTypeApp) |
771 | + makeTwoTestSnaps(c, pkg.TypeApp) |
772 | |
773 | path, err := filepath.EvalSymlinks(filepath.Join(snapAppsDir, fooComposedName, "current")) |
774 | c.Assert(err, IsNil) |
775 | |
776 | === modified file 'snappy/snapp.go' |
777 | --- snappy/snapp.go 2015-05-18 16:05:45 +0000 |
778 | +++ snappy/snapp.go 2015-05-19 11:17:28 +0000 |
779 | @@ -40,6 +40,7 @@ |
780 | "launchpad.net/snappy/clickdeb" |
781 | "launchpad.net/snappy/helpers" |
782 | "launchpad.net/snappy/logger" |
783 | + "launchpad.net/snappy/pkg" |
784 | "launchpad.net/snappy/policy" |
785 | "launchpad.net/snappy/progress" |
786 | "launchpad.net/snappy/release" |
787 | @@ -200,7 +201,7 @@ |
788 | Version string |
789 | Vendor string |
790 | Icon string |
791 | - Type SnapType |
792 | + Type pkg.Type |
793 | |
794 | // the spec allows a string or a list here *ick* so we need |
795 | // to convert that into something sensible via reflect |
796 | @@ -240,7 +241,7 @@ |
797 | RatingsAverage float64 `json:"ratings_average,omitempty"` |
798 | SupportURL string `json:"support_url"` |
799 | Title string `json:"title"` |
800 | - Type SnapType `json:"content,omitempty"` |
801 | + Type pkg.Type `json:"content,omitempty"` |
802 | Version string `json:"version"` |
803 | } |
804 | |
805 | @@ -343,7 +344,7 @@ |
806 | return nil |
807 | } |
808 | |
809 | - if m.Type != SnapTypeFramework && m.Type != SnapTypeOem { |
810 | + if m.Type != pkg.TypeFramework && m.Type != pkg.TypeOem { |
811 | if part.Namespace() != namespace { |
812 | return ErrPackageNameAlreadyInstalled |
813 | } |
814 | @@ -375,7 +376,7 @@ |
815 | } |
816 | |
817 | func (m *packageYaml) checkForFrameworks() error { |
818 | - installed, err := ActiveSnapNamesByType(SnapTypeFramework) |
819 | + installed, err := ActiveSnapNamesByType(pkg.TypeFramework) |
820 | if err != nil { |
821 | return err |
822 | } |
823 | @@ -497,7 +498,7 @@ |
824 | } |
825 | |
826 | // Type returns the type of the SnapPart (app, oem, ...) |
827 | -func (s *SnapPart) Type() SnapType { |
828 | +func (s *SnapPart) Type() pkg.Type { |
829 | if s.m.Type != "" { |
830 | return s.m.Type |
831 | } |
832 | @@ -614,7 +615,7 @@ |
833 | // OEM snaps should not be removed as they are a key |
834 | // building block for OEMs. Prunning non active ones |
835 | // is acceptible. |
836 | - if s.m.Type == SnapTypeOem && s.IsActive() { |
837 | + if s.m.Type == pkg.TypeOem && s.IsActive() { |
838 | return ErrPackageNotRemovable |
839 | } |
840 | |
841 | @@ -674,7 +675,7 @@ |
842 | // |
843 | // /!\ not part of the Part interface. |
844 | func (s *SnapPart) Dependents() ([]*SnapPart, error) { |
845 | - if s.Type() != SnapTypeFramework { |
846 | + if s.Type() != pkg.TypeFramework { |
847 | // only frameworks are depended on |
848 | return nil, nil |
849 | } |
850 | @@ -836,7 +837,7 @@ |
851 | } |
852 | |
853 | namespace := "" |
854 | - if m.Type != SnapTypeFramework && m.Type != SnapTypeOem { |
855 | + if m.Type != pkg.TypeFramework && m.Type != pkg.TypeOem { |
856 | namespace, err = namespaceFromYamlPath(realpath) |
857 | if err != nil { |
858 | return nil, err |
859 | @@ -870,7 +871,7 @@ |
860 | } |
861 | |
862 | // Type returns the type of the SnapPart (app, oem, ...) |
863 | -func (s *RemoteSnapPart) Type() SnapType { |
864 | +func (s *RemoteSnapPart) Type() pkg.Type { |
865 | return s.pkg.Type |
866 | } |
867 | |
868 | @@ -1123,7 +1124,7 @@ |
869 | req.Header.Set("Accept", "application/hal+json") |
870 | |
871 | // frameworks |
872 | - frameworks, _ := ActiveSnapNamesByType(SnapTypeFramework) |
873 | + frameworks, _ := ActiveSnapNamesByType(pkg.TypeFramework) |
874 | req.Header.Set("X-Ubuntu-Frameworks", strings.Join(addCoreFmk(frameworks), ",")) |
875 | req.Header.Set("X-Ubuntu-Architecture", string(Architecture())) |
876 | req.Header.Set("X-Ubuntu-Release", release.String()) |
877 | @@ -1236,7 +1237,7 @@ |
878 | func (s *SnapUbuntuStoreRepository) Updates() (parts []Part, err error) { |
879 | // the store only supports apps, oem and frameworks currently, so no |
880 | // sense in sending it our ubuntu-core snap |
881 | - installed, err := ActiveSnapNamesByType(SnapTypeApp, SnapTypeFramework, SnapTypeOem) |
882 | + installed, err := ActiveSnapNamesByType(pkg.TypeApp, pkg.TypeFramework, pkg.TypeOem) |
883 | if err != nil || len(installed) == 0 { |
884 | return nil, err |
885 | } |
886 | |
887 | === modified file 'snappy/snapp_test.go' |
888 | --- snappy/snapp_test.go 2015-05-16 15:29:55 +0000 |
889 | +++ snappy/snapp_test.go 2015-05-19 11:17:28 +0000 |
890 | @@ -18,7 +18,6 @@ |
891 | package snappy |
892 | |
893 | import ( |
894 | - "encoding/json" |
895 | "io" |
896 | "io/ioutil" |
897 | "net/http" |
898 | @@ -31,6 +30,7 @@ |
899 | "launchpad.net/snappy/clickdeb" |
900 | "launchpad.net/snappy/helpers" |
901 | "launchpad.net/snappy/partition" |
902 | + "launchpad.net/snappy/pkg" |
903 | "launchpad.net/snappy/policy" |
904 | "launchpad.net/snappy/release" |
905 | "launchpad.net/snappy/systemd" |
906 | @@ -510,7 +510,7 @@ |
907 | c.Check(parts[0].Channel(), Equals, "edge") |
908 | } |
909 | func mockActiveSnapNamesByType(mockSnaps []string) { |
910 | - ActiveSnapNamesByType = func(snapTs ...SnapType) (res []string, err error) { |
911 | + ActiveSnapNamesByType = func(snapTs ...pkg.Type) (res []string, err error) { |
912 | return mockSnaps, nil |
913 | } |
914 | } |
915 | @@ -1384,33 +1384,3 @@ |
916 | c.Assert(cmds[1], DeepEquals, aCmd{"udevadm", "trigger"}) |
917 | c.Assert(cmds, HasLen, 2) |
918 | } |
919 | - |
920 | -type SnapTypeSuite struct{} |
921 | - |
922 | -var _ = Suite(&SnapTypeSuite{}) |
923 | - |
924 | -func (s *SnapTypeSuite) TestMarshalTypes(c *C) { |
925 | - out, err := json.Marshal(SnapTypeApp) |
926 | - c.Assert(err, IsNil) |
927 | - c.Check(string(out), Equals, "\"app\"") |
928 | - |
929 | - out, err = json.Marshal(SnapTypeOem) |
930 | - c.Assert(err, IsNil) |
931 | - c.Check(string(out), Equals, "\"oem\"") |
932 | -} |
933 | - |
934 | -func (s *SnapTypeSuite) TestUnmarshalTypes(c *C) { |
935 | - var st SnapType |
936 | - |
937 | - err := json.Unmarshal([]byte("\"application\""), &st) |
938 | - c.Assert(err, IsNil) |
939 | - c.Check(st, Equals, SnapTypeApp) |
940 | - |
941 | - err = json.Unmarshal([]byte("\"app\""), &st) |
942 | - c.Assert(err, IsNil) |
943 | - c.Check(st, Equals, SnapTypeApp) |
944 | - |
945 | - err = json.Unmarshal([]byte("\"oem\""), &st) |
946 | - c.Assert(err, IsNil) |
947 | - c.Check(st, Equals, SnapTypeOem) |
948 | -} |
949 | |
950 | === modified file 'snappy/systemimage.go' |
951 | --- snappy/systemimage.go 2015-05-11 16:06:50 +0000 |
952 | +++ snappy/systemimage.go 2015-05-19 11:17:28 +0000 |
953 | @@ -32,6 +32,7 @@ |
954 | "launchpad.net/snappy/helpers" |
955 | "launchpad.net/snappy/logger" |
956 | "launchpad.net/snappy/partition" |
957 | + "launchpad.net/snappy/pkg" |
958 | "launchpad.net/snappy/progress" |
959 | ) |
960 | |
961 | @@ -94,9 +95,9 @@ |
962 | partition partition.Interface |
963 | } |
964 | |
965 | -// Type returns SnapTypeCore for this snap |
966 | -func (s *SystemImagePart) Type() SnapType { |
967 | - return SnapTypeCore |
968 | +// Type returns pkg.TypeCore for this snap |
969 | +func (s *SystemImagePart) Type() pkg.Type { |
970 | + return pkg.TypeCore |
971 | } |
972 | |
973 | // Name returns the name |
974 | |
975 | === modified file 'snappy/udev.go' |
976 | --- snappy/udev.go 2015-04-22 07:11:43 +0000 |
977 | +++ snappy/udev.go 2015-05-19 11:17:28 +0000 |
978 | @@ -20,10 +20,12 @@ |
979 | import ( |
980 | "fmt" |
981 | "path/filepath" |
982 | + |
983 | + "launchpad.net/snappy/pkg" |
984 | ) |
985 | |
986 | func getUdevPartName(m *packageYaml, baseDir string) (string, error) { |
987 | - if m.Type == SnapTypeFramework || m.Type == SnapTypeOem { |
988 | + if m.Type == pkg.TypeFramework || m.Type == pkg.TypeOem { |
989 | return m.Name, nil |
990 | } |
991 |
This looks good, but I want to know what the next MP will look like.
Will the layout look a bit like:
pkg/oem
pkg/app
pkg/kernel
pkg/os
pkg/framework
?
An interface in pkg (superseeded from Part)?
Maybe a generic implementation of the interface in pkg and every component composing/embedding that?