Merge lp:~brian-murray/cupstream2distro/bug-1530870 into lp:cupstream2distro

Proposed by Brian Murray
Status: Merged
Merged at revision: 1352
Proposed branch: lp:~brian-murray/cupstream2distro/bug-1530870
Merge into: lp:cupstream2distro
Diff against target: 37 lines (+6/-5)
2 files modified
cupstream2distro/silomanager.py (+4/-3)
tests/unit/test_silomanager.py (+2/-2)
To merge this branch: bzr merge lp:~brian-murray/cupstream2distro/bug-1530870
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Approve
Review via email: mp+284805@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

Clever job getting the series from the filename, I'll need to think about how stable that'll be (the file path has changed a few times over the years).

There's an unrelated issue that affects this part of the code as well, let me know if you'd like to tackle it within the same branch or if it makes more sense to do it as a separate branch.

The thing is that these files you're reading don't even need to be created in the first place. It used to be that these files would be created at one point, preserved on the server, and then read at a different point, but the architecture of the system has shifted a bit and we currently do a silly sort of thing where one part of the code writes these files, another part of the code immediately reads them, and then when the job is done running it all gets deleted. So it should be possible to just set a value in an instance attribute somewhere rather than even writing/reading to disk at all.

Take a look here:

http://bazaar.launchpad.net/+branch/cupstream2distro/view/head:/cupstream2distro/archive.py#L217

That's where the file is written, in Archive.archive_pocket(). Instead of calling set_file (and indeed if you drop set_file I think set_file can be entirely deleted as this is the last remaining user of the method), just set an instance attribute, and then in SiloManager.published_versions you should be able to iterate over all the build objects and their 'published' attribute. Although SiloManager probably doesn't have a direct reference from one to the other so you might need some poking to connect the dots there.

1354. By Brian Murray

remove setdefault usage

Revision history for this message
Robert Bruce Park (robru) wrote :

ok lgtm, just going to test in staging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cupstream2distro/silomanager.py'
2--- cupstream2distro/silomanager.py 2016-01-24 08:33:40 +0000
3+++ cupstream2distro/silomanager.py 2016-02-02 22:55:48 +0000
4@@ -355,14 +355,15 @@
5
6 @property
7 def published_versions(self):
8- """Return a list of what versions have been published."""
9- versions = defaultdict(list)
10+ """Return a dictionary of what versions have been published."""
11+ versions = defaultdict(dict)
12 fileglob = join(SILOS_DIR, self.siloname, '*', '*', '*published')
13 for filename in sorted(glob(fileglob)):
14 source = basename(filename).split('_')[0].split('+')[0]
15+ series = filename.split('/')[-3]
16 with utf8_open(filename) as data:
17 version = data.read().strip()
18- versions[source].append(version)
19+ versions[source][series] = version
20 return json.dumps(versions, sort_keys=True)
21
22 @property
23
24=== modified file 'tests/unit/test_silomanager.py'
25--- tests/unit/test_silomanager.py 2016-01-24 08:33:40 +0000
26+++ tests/unit/test_silomanager.py 2016-02-02 22:55:48 +0000
27@@ -624,8 +624,8 @@
28 data.write(version)
29 self.assertEqual(
30 self.state.published_versions,
31- '{"alpha": ["1.0+15.04", "1.0+16.04"], '
32- '"beta": ["1.0+15.04", "1.0+16.04"]}')
33+ '{"alpha": {"vivid": "1.0+15.04", "xenial": "1.0+16.04"}, '
34+ '"beta": {"vivid": "1.0+15.04", "xenial": "1.0+16.04"}}')
35
36 @patch('cupstream2distro.silomanager.SiloState.sources', ['foobar'])
37 @patch('cupstream2distro.silomanager.SiloState.mps', dict(merger=[]))

Subscribers

People subscribed via source and target branches

to all changes: