Merge lp:~james-w/linaro-image-tools/metadata-from-config into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 110
Merged at revision: 67
Proposed branch: lp:~james-w/linaro-image-tools/metadata-from-config
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/architectures-from-config
Diff against target: 58 lines (+37/-0)
2 files modified
hwpack/hardwarepack.py (+22/-0)
hwpack/tests/test_hardwarepack.py (+15/-0)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/metadata-from-config
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+34468@code.launchpad.net

Description of the change

Hi,

A tiny branch to add a second constructor for Metdadata objects that
allows them to be created from their cousin, the Config object,
with a couple of other items specified.

Version doesn't go in the config, so has to be specified externally.

While architectures are in the configuration, we want to select a
single one for the particular hardware pack that is being built.

Thanks,

James

To post a comment you must log in.
109. By James Westby

Add a docstring for from_config.

110. By James Westby

Merged architectures-from-config into metadata-from-config.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

You could check that the supplied architecture is in the config. Otherwise fine.

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

On Fri, 03 Sep 2010 05:07:42 -0000, Michael Hudson <email address hidden> wrote:
> Review: Approve
> You could check that the supplied architecture is in the config. Otherwise fine.

I wanted to avoid that, as there may be an option in the future to force
building for a different architecture than the config specifies, so I
went with the simpler code.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/hardwarepack.py'
2--- hwpack/hardwarepack.py 2010-09-02 23:07:48 +0000
3+++ hwpack/hardwarepack.py 2010-09-02 23:07:48 +0000
4@@ -39,6 +39,28 @@
5 self.support = support
6 self.architecture = architecture
7
8+ @classmethod
9+ def from_config(cls, config, version, architecture):
10+ """Create a Metadata from a Config object.
11+
12+ As a Config will contain most of the information needed for a
13+ Metadata, we can provide this convenient way to construct one.
14+
15+ Information that is not in the config has to be provided by
16+ the caller.
17+
18+ :param config: the config to take values from.
19+ :type config: Config
20+ :param version: the version to record in the metadata.
21+ :type version: str
22+ :param architecture: the architecture that the hardware pack is
23+ targetting.
24+ :type architecture: str
25+ """
26+ return cls(
27+ config.name, version, architecture, origin=config.origin,
28+ maintainer=config.maintainer, support=config.support)
29+
30 def __str__(self):
31 """Get the contents of the metadata file."""
32 metadata = "NAME=%s\n" % self.name
33
34=== modified file 'hwpack/tests/test_hardwarepack.py'
35--- hwpack/tests/test_hardwarepack.py 2010-09-02 23:07:48 +0000
36+++ hwpack/tests/test_hardwarepack.py 2010-09-02 23:07:48 +0000
37@@ -74,6 +74,21 @@
38 "SUPPORT=unsupported\n",
39 str(metadata))
40
41+ def test_from_config(self):
42+ class Config:
43+ name = "foo"
44+ origin = "linaro"
45+ maintainer = "someone"
46+ support = "supported"
47+ config = Config()
48+ metadata = Metadata.from_config(config, "2.0", "i386")
49+ self.assertEqual(config.name, metadata.name)
50+ self.assertEqual(config.origin, metadata.origin)
51+ self.assertEqual(config.maintainer, metadata.maintainer)
52+ self.assertEqual(config.support, metadata.support)
53+ self.assertEqual("2.0", metadata.version)
54+ self.assertEqual("i386", metadata.architecture)
55+
56
57 class HardwarePackHasFile(TarfileHasFile):
58 """A subclass of TarfileHasFile specific to hardware packs.

Subscribers

People subscribed via source and target branches