Merge ~cloud-images-release-managers/cloud-images/+git/mfdiff:features/snap-diffs into ~cloud-images-release-managers/cloud-images/+git/mfdiff:master

Proposed by Tobias Koch
Status: Merged
Merged at revision: da2d5005aca2a41d392de2c788a69cfc2765ab83
Proposed branch: ~cloud-images-release-managers/cloud-images/+git/mfdiff:features/snap-diffs
Merge into: ~cloud-images-release-managers/cloud-images/+git/mfdiff:master
Diff against target: 654 lines (+268/-136)
6 files modified
test/test_manifest.py (+18/-15)
test/test_manifestdiff.py (+127/-46)
test/util.py (+12/-6)
ubuntu/cloudimage/mfdiff/cli.py (+15/-7)
ubuntu/cloudimage/mfdiff/manifest.py (+11/-20)
ubuntu/cloudimage/mfdiff/manifestdiff.py (+85/-42)
Reviewer Review Type Date Requested Status
Philip Roche (community) Approve
Dan Watkins (community) Approve
Review via email: mp+361239@code.launchpad.net

Commit message

diff snaps

Description of the change

The output of the command looks like this now (shortened for readability):

new: {}
removed: {'python3-pam': '0.4.2-13.2ubuntu6'}
changed: ['dash', 'python3-twisted', 'python3-twisted-bin:amd64']
new snaps: {'test-snap': ['stable', '1']}
removed snaps: {'lxd': ['stable/ubuntu-19.04', '9795']}
changed snaps: ['core']
==== dash: 0.5.10.2-2 => 0.5.10.2-3ubuntu1 ====
==== dash
  * preinst is removed, thus divertion is not setup upon
  ...
==== twisted: 18.7.0-2 => 18.9.0-3 ====
==== python3-twisted python3-twisted-bin:amd64
  * Don't fix package substvars in binary-arch:, they did not depend on hamcrest
  ...

To post a comment you must log in.
Revision history for this message
Dan Watkins (oddbloke) wrote :

I haven't had time to do a full review, but I have a naming change suggestion: snaps are packages too, so using "pkgs" for debs is a little confusing. Could you do s/pkgs/debs/ (or deb_pkgs or something)?

Revision history for this message
Dan Watkins (oddbloke) wrote :

Other than the naming issue above, this looks really good. (FAOD, I'm not asking you to change every reference to debs as packages; just to modify the names that are introduced/modified in this MP.)

review: Needs Fixing
Revision history for this message
Tobias Koch (tobijk) wrote :

@daniel-thewatkins, ok like this?

Revision history for this message
Dan Watkins (oddbloke) wrote :

Thanks!

review: Approve
Revision history for this message
Philip Roche (philroche) wrote :

Nice

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/test/test_manifest.py b/test/test_manifest.py
2index 29ab614..f3d38a7 100644
3--- a/test/test_manifest.py
4+++ b/test/test_manifest.py
5@@ -9,34 +9,37 @@ class TestManifest(object):
6 manifest_file.write('')
7 manifest = Manifest(str(manifest_file), 'bionic', 'amd64')
8 assert len(manifest) == 0
9- assert manifest.dict == {}
10+ assert manifest.debs == {}
11
12- def test_single_package(self, tmpdir):
13- package_name, package_version = 'package_name', '1.0-0ubuntu1'
14+ def test_single_deb(self, tmpdir):
15+ deb_name, deb_version = 'deb_name', '1.0-0ubuntu1'
16 manifest_file = tmpdir.join('manifest')
17- manifest_file.write(deb_package_line(package_name, package_version))
18+ manifest_file.write(deb_package_line(deb_name, deb_version))
19 manifest = Manifest(str(manifest_file), 'bionic', 'amd64')
20 assert len(manifest) == 1
21- assert manifest.dict == { package_name: package_version }
22+ assert manifest.debs == { deb_name: deb_version }
23
24- def test_snaps_are_skipped(self, tmpdir):
25- package_name, package_version = 'package_name', '1.0-0ubuntu1'
26+ def test_single_snap(self, tmpdir):
27+ snap_name, snap_channel, snap_version = ('snap_name', 'snap_channel',
28+ 'snap_version')
29 manifest_file = tmpdir.join('manifest')
30 manifest_file.write('\n'.join([
31- deb_package_line(package_name, package_version),
32 snap_package_line('snap_name', 'snap_channel', 'snap_version')
33 ]))
34 manifest = Manifest(str(manifest_file), 'bionic', 'amd64')
35 assert len(manifest) == 1
36- assert manifest.dict == { package_name: package_version }
37+ assert manifest.snaps == { snap_name: [snap_channel, snap_version]}
38
39- def test_deb_packages_starting_with_snap_arent_skipped(self, tmpdir):
40- package_name, package_version = 'snapd', '1.0-0ubuntu1'
41+ def test_deb_and_snap(self, tmpdir):
42+ deb_name, deb_version = 'snapd', '1.0-0ubuntu1'
43+ snap_name, snap_channel, snap_version = ('snap_name', 'snap_channel',
44+ 'snap_version')
45 manifest_file = tmpdir.join('manifest')
46 manifest_file.write('\n'.join([
47- deb_package_line(package_name, package_version),
48- snap_package_line('snap_name', 'snap_channel', 'snap_version')
49+ deb_package_line(deb_name, deb_version),
50+ snap_package_line(snap_name, snap_channel, snap_version)
51 ]))
52 manifest = Manifest(str(manifest_file), 'bionic', 'amd64')
53- assert len(manifest) == 1
54- assert manifest.dict == { package_name: package_version }
55+ assert len(manifest) == 2
56+ assert manifest.debs == { deb_name: deb_version }
57+ assert manifest.snaps == { snap_name: [snap_channel, snap_version]}
58diff --git a/test/test_manifestdiff.py b/test/test_manifestdiff.py
59index 3d33731..c391f17 100644
60--- a/test/test_manifestdiff.py
61+++ b/test/test_manifestdiff.py
62@@ -5,11 +5,11 @@ from .util import deb_package_line, snap_package_line, write_manifest_file
63 class TestManifestDiff(object):
64
65 def test_incompatible_manifest_raise_error(self, tmpdir):
66- package_name, package_version = 'package', '1.0-0ubuntu1'
67+ deb_name, deb_version = 'package', '1.0-0ubuntu1'
68 manifest_file1 = tmpdir.join('manifest1')
69 manifest_file2 = tmpdir.join('manifest2')
70- manifest_file1.write(deb_package_line(package_name, package_version))
71- manifest_file2.write(deb_package_line(package_name, package_version))
72+ manifest_file1.write(deb_package_line(deb_name, deb_version))
73+ manifest_file2.write(deb_package_line(deb_name, deb_version))
74 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
75 manifest2 = Manifest(str(manifest_file2), 'bionic', 'arm64')
76
77@@ -21,57 +21,57 @@ class TestManifestDiff(object):
78
79 assert incompatible == True
80
81- def test_find_added_packages(self, tmpdir):
82- package_list = [
83+ def test_find_added_debs(self, tmpdir):
84+ deb_list = [
85 ('package1', '1.0-1'),
86 ('package2', '0.9.1-0ubuntu1'),
87 ]
88- additional_packages = [
89+ additional_debs = [
90 ('package3', '0.8a~tp1-1ubuntu1'),
91 ]
92
93 manifest_file1 = tmpdir.join('manifest1')
94 manifest_file2 = tmpdir.join('manifest2')
95- write_manifest_file(manifest_file1, package_list)
96- write_manifest_file(manifest_file2, package_list
97- + additional_packages)
98+ write_manifest_file(manifest_file1, debs=deb_list)
99+ write_manifest_file(manifest_file2, debs=deb_list
100+ + additional_debs)
101
102 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
103 manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
104
105 diff = ManifestDiff(manifest1, manifest2)
106- added_packages = diff.get_added()
107- assert added_packages == dict(additional_packages)
108+ added_debs = diff.get_added_debs()
109+ assert added_debs == dict(additional_debs)
110
111- def test_find_removed_packages(self, tmpdir):
112- package_list = [
113+ def test_find_removed_debs(self, tmpdir):
114+ deb_list = [
115 ('package1', '1.0-1'),
116 ('package2', '0.9.1-0ubuntu1')
117 ]
118- additional_packages = [
119+ additional_debs = [
120 ('package3', '0.8a~tp1-1ubuntu1')
121 ]
122
123 manifest_file1 = tmpdir.join('manifest1')
124 manifest_file2 = tmpdir.join('manifest2')
125- write_manifest_file(manifest_file1, package_list
126- + additional_packages)
127- write_manifest_file(manifest_file2, package_list)
128+ write_manifest_file(manifest_file1, debs=deb_list
129+ + additional_debs)
130+ write_manifest_file(manifest_file2, debs=deb_list)
131
132 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
133 manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
134
135 diff = ManifestDiff(manifest1, manifest2)
136- removed_packages = diff.get_removed()
137- assert removed_packages == dict(additional_packages)
138+ removed_debs = diff.get_removed_debs()
139+ assert removed_debs == dict(additional_debs)
140
141- def test_find_changed_packages(self, tmpdir):
142- package_list1 = [
143+ def test_find_changed_debs(self, tmpdir):
144+ deb_list1 = [
145 ('package1', '1.0-1'),
146 ('package2', '0.9.1-0ubuntu1'),
147 ('package3', '2.0'),
148 ]
149- package_list2 = [
150+ deb_list2 = [
151 ('package1', '1.0-1'),
152 ('package2', '0.10.1-0ubuntu1'),
153 ('package3', '2.0'),
154@@ -79,17 +79,61 @@ class TestManifestDiff(object):
155
156 manifest_file1 = tmpdir.join('manifest1')
157 manifest_file2 = tmpdir.join('manifest2')
158- write_manifest_file(manifest_file1, package_list1)
159- write_manifest_file(manifest_file2, package_list2)
160+ write_manifest_file(manifest_file1, debs=deb_list1)
161+ write_manifest_file(manifest_file2, debs=deb_list2)
162
163 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
164 manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
165 diff = ManifestDiff(manifest1, manifest2)
166- changed_packages = diff.get_changed()
167- assert changed_packages == ['package2']
168+ changed_debs = diff.get_changed_debs()
169+ assert changed_debs == ['package2']
170+
171+ def test_find_added_snaps(self, tmpdir):
172+ snap_list = [
173+ ('snap1', ['stable', '1.0-1']),
174+ ('snap2', ['edge', '0.9.1-0ubuntu1']),
175+ ]
176+ additional_snaps = [
177+ ('snap3', ['stable/ubuntu-18.04', '0.8a~tp1-1ubuntu1']),
178+ ]
179+
180+ manifest_file1 = tmpdir.join('manifest1')
181+ manifest_file2 = tmpdir.join('manifest2')
182+ write_manifest_file(manifest_file1, snaps=snap_list)
183+ write_manifest_file(manifest_file2, snaps=snap_list
184+ + additional_snaps)
185+
186+ manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
187+ manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
188+
189+ diff = ManifestDiff(manifest1, manifest2)
190+ added_snaps = diff.get_added_snaps()
191+ assert added_snaps == dict(additional_snaps)
192+
193+ def test_find_removed_snaps(self, tmpdir):
194+ snap_list = [
195+ ('snap1', ['stable', '1.0-1']),
196+ ('snap2', ['edge', '0.9.1-0ubuntu1'])
197+ ]
198+ additional_snaps = [
199+ ('package3', ['stable/ubuntu-18.04', '0.8a~tp1-1ubuntu1'])
200+ ]
201+
202+ manifest_file1 = tmpdir.join('manifest1')
203+ manifest_file2 = tmpdir.join('manifest2')
204+ write_manifest_file(manifest_file1, snaps=snap_list
205+ + additional_snaps)
206+ write_manifest_file(manifest_file2, snaps=snap_list)
207+
208+ manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
209+ manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
210+
211+ diff = ManifestDiff(manifest1, manifest2)
212+ removed_snaps = diff.get_removed_snaps()
213+ assert removed_snaps == dict(additional_snaps)
214
215 def test_find_added_removed_changed(self, tmpdir):
216- package_list1 = [
217+ deb_list1 = [
218 ('package1', '1.0'),
219 ('package4', '1.0'),
220 ('package5', '1.0'),
221@@ -99,7 +143,7 @@ class TestManifestDiff(object):
222 ('package9', '1.0'),
223 ('package10', '1.0')
224 ]
225- package_list2 = [
226+ deb_list2 = [
227 ('package1', '1.0'),
228 ('package2', '1.0'),
229 ('package3', '1.0'),
230@@ -110,40 +154,77 @@ class TestManifestDiff(object):
231 ('package10', '1.0')
232 ]
233
234+ snap_list1 = [
235+ ('snap1', ['stable', '1.0']),
236+ ('snap4', ['stable', '1.0']),
237+ ('snap5', ['stable', '1.0']),
238+ ('snap6', ['stable', '1.0']),
239+ ('snap7', ['stable', '1.0']),
240+ ('snap8', ['stable', '1.0']),
241+ ('snap9', ['stable', '1.0']),
242+ ('snap10', ['stable', '1.0']),
243+ ]
244+ snap_list2 = [
245+ ('snap1', ['stable', '1.0']),
246+ ('snap2', ['stable', '1.0']),
247+ ('snap3', ['stable', '1.0']),
248+ ('snap4', ['stable', '2.0']),
249+ ('snap5', ['edge', '1.0']),
250+ ('snap6', ['stable', '1.0']),
251+ ('snap9', ['stable', '1.0']),
252+ ('snap10', ['stable', '1.0']),
253+ ]
254+
255 manifest_file1 = tmpdir.join('manifest1')
256 manifest_file2 = tmpdir.join('manifest2')
257- write_manifest_file(manifest_file1, package_list1)
258- write_manifest_file(manifest_file2, package_list2)
259+ write_manifest_file(manifest_file1, debs=deb_list1,
260+ snaps=snap_list1)
261+ write_manifest_file(manifest_file2, debs=deb_list2,
262+ snaps=snap_list2)
263
264 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
265 manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
266 diff = ManifestDiff(manifest1, manifest2)
267
268- added_packages = diff.get_added()
269- removed_packages = diff.get_removed()
270- changed_packages = diff.get_changed()
271+ added_debs = diff.get_added_debs()
272+ removed_debs = diff.get_removed_debs()
273+ changed_debs = diff.get_changed_debs()
274+
275+ assert added_debs == {'package2': '1.0', 'package3': '1.0'}
276+ assert removed_debs == {'package7': '1.0', 'package8': '1.0'}
277+ assert changed_debs == ['package4', 'package5']
278+
279+ added_snaps = diff.get_added_snaps()
280+ removed_snaps = diff.get_removed_snaps()
281+ changed_snaps = diff.get_changed_snaps()
282
283- assert added_packages == {'package2': '1.0', 'package3': '1.0'}
284- assert removed_packages == {'package7': '1.0', 'package8': '1.0'}
285- assert changed_packages == ['package4', 'package5']
286+ assert added_snaps == {
287+ 'snap2': ['stable', '1.0'],
288+ 'snap3': ['stable', '1.0']
289+ }
290+ assert removed_snaps == {
291+ 'snap7': ['stable', '1.0'],
292+ 'snap8': ['stable', '1.0']
293+ }
294+ assert changed_snaps == ['snap4', 'snap5']
295
296 def test_kernel_fixups(self, tmpdir):
297- package_list1 = [('linux-image-4.13.0-16-generic', '4.13.0-16.19')]
298- package_list2 = [('linux-image-4.13.0-25-generic', '4.13.0-25.29')]
299+ deb_list1 = [('linux-image-4.13.0-16-generic', '4.13.0-16.19')]
300+ deb_list2 = [('linux-image-4.13.0-25-generic', '4.13.0-25.29')]
301
302 manifest_file1 = tmpdir.join('manifest1')
303 manifest_file2 = tmpdir.join('manifest2')
304- write_manifest_file(manifest_file1, package_list1)
305- write_manifest_file(manifest_file2, package_list2)
306+ write_manifest_file(manifest_file1, debs=deb_list1)
307+ write_manifest_file(manifest_file2, debs=deb_list2)
308
309 manifest1 = Manifest(str(manifest_file1), 'bionic', 'amd64')
310 manifest2 = Manifest(str(manifest_file2), 'bionic', 'amd64')
311 diff = ManifestDiff(manifest1, manifest2)
312
313- added_packages = diff.get_added()
314- removed_packages = diff.get_removed()
315- changed_packages = diff.get_changed()
316+ added_debs = diff.get_added_debs()
317+ removed_debs = diff.get_removed_debs()
318+ changed_debs = diff.get_changed_debs()
319
320- assert added_packages == {}
321- assert removed_packages == {}
322- assert changed_packages == ['linux-image-4.13.0-25-generic']
323+ assert added_debs == {}
324+ assert removed_debs == {}
325+ assert changed_debs == ['linux-image-4.13.0-25-generic']
326diff --git a/test/util.py b/test/util.py
327index 9979a78..a39b7ec 100644
328--- a/test/util.py
329+++ b/test/util.py
330@@ -1,6 +1,6 @@
331-def deb_package_line(package_name, package_version):
332+def deb_package_line(deb_name, deb_version):
333 """Format a deb package manifest line"""
334- return '\t'.join([package_name, package_version])
335+ return '\t'.join([deb_name, deb_version])
336
337
338 def snap_package_line(snap_name, snap_channel, snap_version):
339@@ -8,14 +8,20 @@ def snap_package_line(snap_name, snap_channel, snap_version):
340 return '\t'.join(
341 ['snap:{}'.format(snap_name), snap_channel, snap_version])
342
343-def write_manifest_file(path_obj, packages):
344+def write_manifest_file(path_obj, debs=None, snaps=None):
345 """Write a list of packages to a manifest file."""
346 manifest_lines = []
347
348 # Then add more to the second.
349- for package_name, package_version in packages:
350- manifest_lines.append(deb_package_line(
351- package_name, package_version))
352+ if debs is not None:
353+ for deb_name, deb_version in debs:
354+ manifest_lines.append(deb_package_line(
355+ deb_name, deb_version))
356+
357+ if snaps is not None:
358+ for snap_name, (snap_channel, snap_version) in snaps:
359+ manifest_lines.append(snap_package_line(
360+ snap_name, snap_channel, snap_version))
361
362 path_obj.write("\n".join(manifest_lines))
363
364diff --git a/ubuntu/cloudimage/mfdiff/cli.py b/ubuntu/cloudimage/mfdiff/cli.py
365index ba8d102..5cc0629 100644
366--- a/ubuntu/cloudimage/mfdiff/cli.py
367+++ b/ubuntu/cloudimage/mfdiff/cli.py
368@@ -128,14 +128,22 @@ def main():
369 manifest_from = Manifest(manifest_from_filename, release, arch)
370 manifest_diff = ManifestDiff(manifest_from, manifest_to)
371
372- added_pkgs = manifest_diff.get_added()
373- removed_pkgs = manifest_diff.get_removed()
374- changed_pkgs = manifest_diff.get_changed()
375+ added_debs = manifest_diff.get_added_debs()
376+ removed_debs = manifest_diff.get_removed_debs()
377+ changed_debs = manifest_diff.get_changed_debs()
378
379- print("new: %s" % added_pkgs)
380- print("removed: %s" % removed_pkgs)
381- print("changed: %s" % changed_pkgs)
382+ added_snaps = manifest_diff.get_added_snaps()
383+ removed_snaps = manifest_diff.get_removed_snaps()
384+ changed_snaps = manifest_diff.get_changed_snaps()
385+
386+ print("new: %s" % added_debs)
387+ print("removed: %s" % removed_debs)
388+ print("changed: %s" % changed_debs)
389+
390+ print("new snaps: %s" % added_snaps)
391+ print("removed snaps: %s" % removed_snaps)
392+ print("changed snaps: %s" % changed_snaps)
393
394 # if modified packages, download all changelogs from changelogs.
395- if changed_pkgs:
396+ if changed_debs:
397 print(manifest_diff.render_changelog())
398diff --git a/ubuntu/cloudimage/mfdiff/manifest.py b/ubuntu/cloudimage/mfdiff/manifest.py
399index 6907ad8..bd1f416 100644
400--- a/ubuntu/cloudimage/mfdiff/manifest.py
401+++ b/ubuntu/cloudimage/mfdiff/manifest.py
402@@ -27,23 +27,10 @@ class Manifest(object):
403 def __init__(self, filename, release, arch):
404 self.release = release
405 self.arch = arch
406- self.dict = self._manifest_to_dict(filename)
407-
408- def __iter__(self):
409- for item in self.dict:
410- yield item
411-
412- def __getitem__(self, key):
413- return self.dict[key]
414-
415- def __setitem__(self, key, value):
416- self.dict[key] = value
417-
418- def __delitem__(self, key):
419- del self.dict[key]
420+ self.debs, self.snaps = self._manifest_to_dict(filename)
421
422 def __len__(self):
423- return len(self.dict)
424+ return len(self.debs) + len(self.snaps)
425
426 @classmethod
427 def _manifest_to_dict(cls, filename):
428@@ -54,12 +41,16 @@ class Manifest(object):
429 :return: List of package versions by name
430 :rtype: dict
431 """
432- ret = {}
433+ debs = {}
434+ snaps = {}
435+
436 logging.debug('Reading package manifest from %s', filename)
437 with open(filename, "r") as manifest:
438 for line in manifest:
439 if line.startswith("snap:"):
440- continue
441- (pkg, ver) = line.split()
442- ret[pkg] = ver
443- return ret
444+ (name, channel, ver) = line[5:].split()
445+ snaps[name] = [channel, ver]
446+ else:
447+ (name, ver) = line.split()
448+ debs[name] = ver
449+ return debs, snaps
450diff --git a/ubuntu/cloudimage/mfdiff/manifestdiff.py b/ubuntu/cloudimage/mfdiff/manifestdiff.py
451index 20e7804..436e6fa 100644
452--- a/ubuntu/cloudimage/mfdiff/manifestdiff.py
453+++ b/ubuntu/cloudimage/mfdiff/manifestdiff.py
454@@ -64,9 +64,12 @@ class ManifestDiff(object):
455
456 self._manifest_from = manifest_from
457 self._manifest_to = manifest_to
458- self._added_pkgs = {}
459- self._removed_pkgs = {}
460- self._changed_pkgs = []
461+ self._added_debs = {}
462+ self._removed_debs = {}
463+ self._changed_debs = []
464+ self._added_snaps = {}
465+ self._removed_snaps = {}
466+ self._changed_snaps = []
467
468 self._cache = ManifestCache(manifest_from.release,
469 manifest_from.arch)
470@@ -74,37 +77,59 @@ class ManifestDiff(object):
471 if apply_fixups:
472 self.apply_kernel_fixups()
473
474- def get_added(self):
475+ def get_added_debs(self):
476 "Find new packages in manifest_to"
477- if not self._added_pkgs:
478- for pkg in sorted(viewkeys(self._manifest_to.dict) -
479- viewkeys(self._manifest_from.dict)):
480- logging.debug('New package: %s', pkg)
481- self._added_pkgs[pkg] = self._manifest_to.dict[pkg]
482- return self._added_pkgs
483-
484- def get_removed(self):
485+ if not self._added_debs:
486+ self._added_debs = self._get_added_dict_items(
487+ self._manifest_from.debs,
488+ self._manifest_to.debs
489+ )
490+ return self._added_debs
491+
492+ def get_removed_debs(self):
493 "Find packages removed from manifest_from"
494- if not self._removed_pkgs:
495- for pkg in sorted(viewkeys(self._manifest_from.dict) -
496- viewkeys(self._manifest_to.dict)):
497- logging.debug('Removed package: %s', pkg)
498- self._removed_pkgs[pkg] = self._manifest_from[pkg]
499- return self._removed_pkgs
500-
501- def get_changed(self):
502+ if not self._removed_debs:
503+ self._removed_debs = self._get_removed_dict_items(
504+ self._manifest_from.debs,
505+ self._manifest_to.debs
506+ )
507+ return self._removed_debs
508+
509+ def get_changed_debs(self):
510 "Find modified packages"
511- if not self._changed_pkgs:
512- changed = []
513- for pkg in sorted(viewkeys(self._manifest_from.dict) &
514- viewkeys(self._manifest_to.dict)):
515- if self._manifest_from[pkg] != self._manifest_to[pkg]:
516- logging.debug('Changed package: %s', pkg)
517- changed.append(pkg)
518-
519- self._changed_pkgs = changed
520-
521- return self._changed_pkgs
522+ if not self._changed_debs:
523+ self._changed_debs = self._get_changed_dict_items(
524+ self._manifest_from.debs,
525+ self._manifest_to.debs
526+ )
527+ return self._changed_debs
528+
529+ def get_added_snaps(self):
530+ "Find new snaps in manifest_to"
531+ if not self._added_snaps:
532+ self._added_snaps = self._get_added_dict_items(
533+ self._manifest_from.snaps,
534+ self._manifest_to.snaps
535+ )
536+ return self._added_snaps
537+
538+ def get_removed_snaps(self):
539+ "Find snaps removed from manifest_from"
540+ if not self._removed_snaps:
541+ self._removed_snaps = self._get_removed_dict_items(
542+ self._manifest_from.snaps,
543+ self._manifest_to.snaps
544+ )
545+ return self._removed_snaps
546+
547+ def get_changed_snaps(self):
548+ "Find modified snaps"
549+ if not self._changed_snaps:
550+ self._changed_snaps = self._get_changed_dict_items(
551+ self._manifest_from.snaps,
552+ self._manifest_to.snaps
553+ )
554+ return self._changed_snaps
555
556 def render_changelog(self):
557 """
558@@ -114,7 +139,7 @@ class ManifestDiff(object):
559
560 srcs = {}
561 errors = []
562- src2bins = self._cache.get_src2bin_mapping(self._changed_pkgs)
563+ src2bins = self._cache.get_src2bin_mapping(self._changed_debs)
564
565 # Generate changelog data per unique source package
566 for source_name in src2bins:
567@@ -127,19 +152,19 @@ class ManifestDiff(object):
568 # Find the source version data for the binary in manifest #2
569 try:
570 src['version_to'] = self._cache.source_version_for_binary(
571- binary_name, self._manifest_to[binary_name])
572+ binary_name, self._manifest_to.debs[binary_name])
573 except UnknownSourceVersionError as excp:
574 logging.error(str(excp))
575 errors.append(excp)
576 continue
577
578 # Find the source version data for the binary in manifest #1
579- binver_from = self._manifest_from[binary_name]
580+ binver_from = self._manifest_from.debs[binary_name]
581 try:
582 src['version_from'] = self._cache.source_version_for_binary(
583 binary_name, binver_from)
584 except UnknownSourceVersionError as excp:
585- if self._manifest_to[binary_name] == src['version_to']:
586+ if self._manifest_to.debs[binary_name] == src['version_to']:
587 logging.info('Could not find source version data in apt '
588 'cache. Assuming source %s version %s from '
589 'binary %s', source_name, binver_from,
590@@ -189,8 +214,8 @@ class ManifestDiff(object):
591 binlist = sorted(src2bins[source_name])
592 binary = binlist[0]
593 result.append("==== %s: %s => %s ====" %
594- (source_name, self._manifest_from[binary],
595- self._manifest_to[binary]))
596+ (source_name, self._manifest_from.debs[binary],
597+ self._manifest_to.debs[binary]))
598 result.append("==== %s" % ' '.join(binlist))
599 for block in srcs[source_name]["changeblocks"]:
600 entry = '\n'.join([x for x in block.changes() if x])
601@@ -213,17 +238,17 @@ class ManifestDiff(object):
602 """
603 kfixups = {}
604 kmatch = re.compile("linux-image-[0-9]")
605- for pkg in self._manifest_to:
606+ for pkg in self._manifest_to.debs:
607 # if this is a linux-image-* binary package do some hacks to make it
608 # look like manifest_from is the same (format like
609 # linux-image-2.6.32-32-virtual)
610 if kmatch.match(pkg):
611 logging.debug('Found kernel %s in manifest #2', pkg)
612 img_type = pkg.split("-")[-1]
613- if pkg in self._manifest_from:
614+ if pkg in self._manifest_from.debs:
615 logging.debug('Found same kernel in manifest #1')
616 continue
617- for fpkg in self._manifest_from:
618+ for fpkg in self._manifest_from.debs:
619 if kmatch.match(fpkg) and fpkg.endswith("-%s" % img_type):
620 logging.debug('Found similar kernel %s in manifest #1',
621 fpkg)
622@@ -232,8 +257,8 @@ class ManifestDiff(object):
623 for pkg_to, pkg_from in iteritems(kfixups):
624 logging.debug('Substituting kernel %s for %s in manifest #1 to '
625 'enable version comparison', pkg_to, pkg_from)
626- self._manifest_from[pkg_to] = self._manifest_from[pkg_from]
627- del self._manifest_from[pkg_from]
628+ self._manifest_from.debs[pkg_to] = self._manifest_from.debs[pkg_from]
629+ del self._manifest_from.debs[pkg_from]
630
631 def _filter_changelog(self, changelog_path, version_low, version_high):
632 """
633@@ -282,3 +307,21 @@ class ManifestDiff(object):
634 logging.error(error_msg)
635 return change_blocks, error_msg
636
637+ def _get_added_dict_items(self, from_dict, to_dict):
638+ added = {}
639+ for key in sorted(viewkeys(to_dict) - viewkeys(from_dict)):
640+ added[key] = to_dict[key]
641+ return added
642+
643+ def _get_removed_dict_items(self, from_dict, to_dict):
644+ removed = {}
645+ for key in sorted(viewkeys(from_dict) - viewkeys(to_dict)):
646+ removed[key] = from_dict[key]
647+ return removed
648+
649+ def _get_changed_dict_items(self, from_dict, to_dict):
650+ changed = []
651+ for key in sorted(viewkeys(from_dict) & viewkeys(to_dict)):
652+ if from_dict[key] != to_dict[key]:
653+ changed.append(key)
654+ return changed

Subscribers

People subscribed via source and target branches