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
=== modified file 'hwpack/packages.py'
--- hwpack/packages.py 2010-09-02 23:04:32 +0000
+++ hwpack/packages.py 2010-09-10 16:11:18 +0000
@@ -159,6 +159,9 @@
159 self.cache = Cache(rootdir=self.tempdir, memonly=True)159 self.cache = Cache(rootdir=self.tempdir, memonly=True)
160 self.cache.update()160 self.cache.update()
161 self.cache.open()161 self.cache.open()
162 return self
163
164 __enter__ = prepare
162165
163 def cleanup(self):166 def cleanup(self):
164 """Cleanup any remaining artefacts.167 """Cleanup any remaining artefacts.
@@ -169,6 +172,10 @@
169 if self.tempdir is not None and os.path.exists(self.tempdir):172 if self.tempdir is not None and os.path.exists(self.tempdir):
170 shutil.rmtree(self.tempdir)173 shutil.rmtree(self.tempdir)
171174
175 def __exit__(self, exc_type, exc_value, traceback):
176 self.cleanup()
177 return False
178
172 def fetch_packages(self, packages):179 def fetch_packages(self, packages):
173 """Fetch the files for the given list of package names.180 """Fetch the files for the given list of package names.
174181
175182
=== modified file 'hwpack/tests/test_packages.py'
--- hwpack/tests/test_packages.py 2010-09-02 23:04:32 +0000
+++ hwpack/tests/test_packages.py 2010-09-10 16:11:18 +0000
@@ -195,6 +195,14 @@
195 open(os.path.join(195 open(os.path.join(
196 fetcher.tempdir, "etc", "apt", "apt.conf")).read())196 fetcher.tempdir, "etc", "apt", "apt.conf")).read())
197197
198 def test_context_manager(self):
199 # A smoketest that PackageFetcher can be used as a context
200 # manager
201 with PackageFetcher([]) as fetcher:
202 tempdir = fetcher.tempdir
203 self.assertTrue(os.path.isdir(tempdir))
204 self.assertFalse(os.path.exists(tempdir))
205
198 def get_fetcher(self, sources, architecture=None):206 def get_fetcher(self, sources, architecture=None):
199 fetcher = PackageFetcher(207 fetcher = PackageFetcher(
200 [s.sources_entry for s in sources], architecture=architecture)208 [s.sources_entry for s in sources], architecture=architecture)

Subscribers

People subscribed via source and target branches