Merge lp:~james-w/linaro-image-tools/package-fetcher-config-manager into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 113
Merged at revision: 69
Proposed branch: lp:~james-w/linaro-image-tools/package-fetcher-config-manager
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/architecture-in-filename
Diff against target: 43 lines (+15/-0)
2 files modified
hwpack/packages.py (+7/-0)
hwpack/tests/test_packages.py (+8/-0)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/package-fetcher-config-manager
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+35128@code.launchpad.net

Description of the change

Hi,

Another small branch. PackageFetcher has a lifecycle, so making it suport
the context manager protocol makes sense. This branch does that and just adds
a smoke test that it can be used like that, and relies on the exiting tests
for the prepare and cleanup methods to test that they do the correct thing.

Thanks,

James

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

Merge trunk.

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

Also fine.

 merge approved

Cheers,
mwh

review: Approve

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-02 23:04:32 +0000
3+++ hwpack/packages.py 2010-09-10 16:11:18 +0000
4@@ -159,6 +159,9 @@
5 self.cache = Cache(rootdir=self.tempdir, memonly=True)
6 self.cache.update()
7 self.cache.open()
8+ return self
9+
10+ __enter__ = prepare
11
12 def cleanup(self):
13 """Cleanup any remaining artefacts.
14@@ -169,6 +172,10 @@
15 if self.tempdir is not None and os.path.exists(self.tempdir):
16 shutil.rmtree(self.tempdir)
17
18+ def __exit__(self, exc_type, exc_value, traceback):
19+ self.cleanup()
20+ return False
21+
22 def fetch_packages(self, packages):
23 """Fetch the files for the given list of package names.
24
25
26=== modified file 'hwpack/tests/test_packages.py'
27--- hwpack/tests/test_packages.py 2010-09-02 23:04:32 +0000
28+++ hwpack/tests/test_packages.py 2010-09-10 16:11:18 +0000
29@@ -195,6 +195,14 @@
30 open(os.path.join(
31 fetcher.tempdir, "etc", "apt", "apt.conf")).read())
32
33+ def test_context_manager(self):
34+ # A smoketest that PackageFetcher can be used as a context
35+ # manager
36+ with PackageFetcher([]) as fetcher:
37+ tempdir = fetcher.tempdir
38+ self.assertTrue(os.path.isdir(tempdir))
39+ self.assertFalse(os.path.exists(tempdir))
40+
41 def get_fetcher(self, sources, architecture=None):
42 fetcher = PackageFetcher(
43 [s.sources_entry for s in sources], architecture=architecture)

Subscribers

People subscribed via source and target branches