Merge lp:~james-w/linaro-image-tools/extra-text-in-packages-files into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Merged at revision: 83
Proposed branch: lp:~james-w/linaro-image-tools/extra-text-in-packages-files
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/set-content-mtime
Diff against target: 54 lines (+22/-1)
2 files modified
hwpack/packages.py (+6/-1)
hwpack/tests/test_packages.py (+16/-0)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/extra-text-in-packages-files
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+35335@code.launchpad.net

Description of the change

Hi,

Another small change to allow specifying extra text for the Packages file.

The motivation for this is that the /var/lib/dpkg/status "database" of
installed packages uses this format with an extra line per-stanza.

I'm not particularly keen on the implementation, but I'm also wary of
adding lots of attributes to the Package class to accomodate this sort
of thing.

If someone thinks we should do this in a different way then I will be
happy to do so.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

14 + :param extra_text: extra text to insert in to each stanza.
15 + Should not end with a newline.

rstrip() will simplify it for your users.

Other than that I agree. I had similar issues in that past (class growing too many attributes) and such solutions tend to look not very pretty but are effective in practice. If you start abusing this argument you can always revisit this problem and add an extra attribute.

One other method that you might consider would be a callback that is called with each package to return this text. This would allow you do have one "hook" that decides on the extra bits on the caller side.

review: Approve
145. By James Westby

Merged set-content-mtime into extra-text-in-packages-files.

146. By James Westby

Merged set-content-mtime into extra-text-in-packages-files.

Revision history for this message
James Westby (james-w) wrote :

On Mon, 13 Sep 2010 21:21:00 -0000, Zygmunt Krynicki <email address hidden> wrote:
> Review: Approve
> 14 + :param extra_text: extra text to insert in to each stanza.
> 15 + Should not end with a newline.
>
> rstrip() will simplify it for your users.

I'm not sure I want to do that, as whitespace can be significant in this
file. I was more trying to set expectations that you specify a line
fragment, rather than a whole line. I can reword it if you like.

> Other than that I agree. I had similar issues in that past (class
> growing too many attributes) and such solutions tend to look not very
> pretty but are effective in practice. If you start abusing this
> argument you can always revisit this problem and add an extra
> attribute.
>
> One other method that you might consider would be a callback that is
> called with each package to return this text. This would allow you do
> have one "hook" that decides on the extra bits on the caller side.

I think that's overkill for this use, but would certainly be warranted
if we actually want to generate usable Packages files with this code.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/packages.py'
2--- hwpack/packages.py 2010-09-13 21:29:42 +0000
3+++ hwpack/packages.py 2010-09-13 21:29:42 +0000
4@@ -7,11 +7,14 @@
5 import apt_pkg
6
7
8-def get_packages_file(packages):
9+def get_packages_file(packages, extra_text=None):
10 """Get the Packages file contents indexing `packages`.
11
12 :param packages: the packages to index.
13 :type packages: an iterable of FetchedPackages.
14+ :param extra_text: extra text to insert in to each stanza.
15+ Should not end with a newline.
16+ :type extra_text: str or None
17 :return: the Packages file contents indexing `packages`.
18 :rtype: str
19 """
20@@ -19,6 +22,8 @@
21 for package in packages:
22 parts = []
23 parts.append('Package: %s' % package.name)
24+ if extra_text is not None:
25+ parts.append(extra_text)
26 parts.append('Version: %s' % package.version)
27 parts.append('Filename: %s' % package.filename)
28 parts.append('Size: %d' % package.size)
29
30=== modified file 'hwpack/tests/test_packages.py'
31--- hwpack/tests/test_packages.py 2010-09-13 21:29:42 +0000
32+++ hwpack/tests/test_packages.py 2010-09-13 21:29:42 +0000
33@@ -81,6 +81,22 @@
34 self.get_stanza(package, "Recommends: bar | baz\n"),
35 get_packages_file([package]))
36
37+ def test_with_extra_text(self):
38+ package = DummyFetchedPackage("foo", "1.1")
39+ self.assertEqual(textwrap.dedent("""\
40+ Package: foo
41+ Status: bar
42+ Version: 1.1
43+ Filename: %(filename)s
44+ Size: %(size)d
45+ Architecture: all
46+ MD5sum: %(md5)s
47+ \n""" % {
48+ 'filename': package.filename,
49+ 'size': package.size,
50+ 'md5': package.md5,
51+ }), get_packages_file([package], extra_text="Status: bar"))
52+
53
54 class StringifyRelationshipTests(TestCaseWithFixtures):
55

Subscribers

People subscribed via source and target branches