Merge lp:~jml/pkgme/run-all-info-once into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 149
Merged at revision: 150
Proposed branch: lp:~jml/pkgme/run-all-info-once
Merge into: lp:pkgme
Diff against target: 47 lines (+24/-3)
2 files modified
pkgme/package_files.py (+3/-3)
pkgme/tests/test_package_files.py (+21/-0)
To merge this branch: bzr merge lp:~jml/pkgme/run-all-info-once
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+126478@code.launchpad.net

Commit message

Only call all_info once

Description of the change

all_info was being called three times when packaging things for pkgme-service.

That's because PackageFiles.get_files() was using 'get_all' on the original
project_info object that it got three times. 'get_all' is a bit of a nasty
API, in that it pretty much always spawns a subprocess, unless it's a DictInfo.

The solution here is to wrap the results in a DictInfo. All the necessary
keys should be there.

I've added a test, which is a little clumsy.

cheers,
jml

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/package_files.py'
2--- pkgme/package_files.py 2012-09-12 03:31:40 +0000
3+++ pkgme/package_files.py 2012-09-26 15:27:20 +0000
4@@ -127,11 +127,11 @@
5 keys = (
6 [ExtraFiles.name] + [ExtraFilesFromPaths.name]
7 + [element.name for element in elements])
8- values = project_info.get_all(keys)
9- new_info = DictInfo(values)
10+ # Cache the resulting info so we don't call the helpers again.
11+ project_info = DictInfo(project_info.get_all(keys))
12 files = []
13 for file_cls in self.files_cls:
14- files.append(file_cls.from_info(new_info))
15+ files.append(file_cls.from_info(project_info))
16 extra_files = ExtraFiles.get_value(project_info)
17 for path, contents in extra_files.items():
18 files.append(BasicFile(path, contents))
19
20=== modified file 'pkgme/tests/test_package_files.py'
21--- pkgme/tests/test_package_files.py 2012-09-12 03:31:40 +0000
22+++ pkgme/tests/test_package_files.py 2012-09-26 15:27:20 +0000
23@@ -646,3 +646,24 @@
24 self.assertEqual('foo.txt', foo.path)
25 self.assertEqual(foo_content, foo.get_contents())
26 self.assertEqual(True, foo.overwrite)
27+
28+ def test_get_info_once(self):
29+ foo_content = self.getUniqueString()
30+ tree = self.useFixture(
31+ FileTree(
32+ {'foo': {'content': foo_content},
33+ 'bar': {}}))
34+ group = PackageFileGroup()
35+ project_info = DictInfo({
36+ ExtraFilesFromPaths.name: {
37+ 'foo.txt': tree.join('foo'),
38+ 'debian/install': tree.join('bar'),
39+ }})
40+ calls = []
41+ orig_get_all = project_info.get_all
42+ def get_all(keys):
43+ calls.append(keys)
44+ return orig_get_all(keys)
45+ project_info.get_all = get_all
46+ group.get_files(project_info)
47+ self.assertEqual(1, len(calls), calls)

Subscribers

People subscribed via source and target branches