aboutsummaryrefslogtreecommitdiff
path: root/hwpack
diff options
context:
space:
mode:
authorMichael Hudson <michael.hudson@linaro.org>2010-12-16 13:14:04 +1300
committerMichael Hudson <michael.hudson@linaro.org>2010-12-16 13:14:04 +1300
commite734cd17b33b46c522bd2f140263b4fdce660702 (patch)
treedc4d58d88d62bbc15285dc4df5a484eaae154127 /hwpack
parentfd542a11c69821aff52f500ae2e91846f4ea420d (diff)
make sure that the Packages file created by sources_entry_for_debs has Filename: entries that work
Diffstat (limited to 'hwpack')
-rw-r--r--hwpack/packages.py19
-rw-r--r--hwpack/testing.py1
-rw-r--r--hwpack/tests/test_packages.py39
3 files changed, 50 insertions, 9 deletions
diff --git a/hwpack/packages.py b/hwpack/packages.py
index ed7e858..fda5475 100644
--- a/hwpack/packages.py
+++ b/hwpack/packages.py
@@ -17,7 +17,7 @@ from debian.debfile import DebFile
logger = logging.getLogger(__name__)
-def get_packages_file(packages, extra_text=None):
+def get_packages_file(packages, extra_text=None, rel_to=None):
"""Get the Packages file contents indexing `packages`.
:param packages: the packages to index.
@@ -25,6 +25,7 @@ def get_packages_file(packages, extra_text=None):
:param extra_text: extra text to insert in to each stanza.
Should not end with a newline.
:type extra_text: str or None
+ :param rel_to: XXX
:return: the Packages file contents indexing `packages`.
:rtype: str
"""
@@ -35,7 +36,10 @@ def get_packages_file(packages, extra_text=None):
if extra_text is not None:
parts.append(extra_text)
parts.append('Version: %s' % package.version)
- parts.append('Filename: %s' % package.filename)
+ filename = package.filepath
+ if rel_to is not None:
+ filename = os.path.relpath(filename, rel_to)
+ parts.append('Filename: %s' % filename)
parts.append('Size: %d' % package.size)
parts.append('Architecture: %s' % package.architecture)
if package.depends:
@@ -161,7 +165,7 @@ class LocalArchiveMaker(TemporaryDirectoryManager):
def sources_entry_for_debs(self, local_debs):
tmpdir = self.make_temporary_directory()
with open(os.path.join(tmpdir, 'Packages'), 'w') as packages_file:
- packages_file.write(get_packages_file(local_debs))
+ packages_file.write(get_packages_file(local_debs, rel_to=tmpdir))
return 'file://%s ./' % (tmpdir, )
@@ -296,6 +300,14 @@ class FetchedPackage(object):
self.replaces = replaces
self.breaks = breaks
self.content = None
+ self._file_path = None
+
+ @property
+ def filepath(self):
+ if self._file_path is not None:
+ return self._file_path
+ else:
+ return self.filename
@classmethod
def from_apt(cls, pkg, filename, content=None):
@@ -351,6 +363,7 @@ class FetchedPackage(object):
name, version, filename, size, md5sum, architecture, depends,
pre_depends, conflicts, recommends, provides, replaces, breaks)
pkg.content = open(deb_file_path)
+ pkg._file_path = deb_file_path
return pkg
# A list of attributes that are compared to determine equality. Note that
diff --git a/hwpack/testing.py b/hwpack/testing.py
index aed788a..7a9b19d 100644
--- a/hwpack/testing.py
+++ b/hwpack/testing.py
@@ -73,6 +73,7 @@ class DummyFetchedPackage(FetchedPackage):
self.breaks = breaks
self._no_content = no_content
self._content = content
+ self._file_path = None
@property
def filename(self):
diff --git a/hwpack/tests/test_packages.py b/hwpack/tests/test_packages.py
index c49d989..e67dfb7 100644
--- a/hwpack/tests/test_packages.py
+++ b/hwpack/tests/test_packages.py
@@ -1,13 +1,18 @@
import os
+import shutil
from StringIO import StringIO
import subprocess
+import tempfile
import textwrap
+import apt_pkg
from debian.debfile import DebFile
from testtools import TestCase
+from testtools.matchers import Equals
from hwpack.packages import (
DependencyNotSatisfied,
+ DummyProgress,
FetchedPackage,
get_packages_file,
IsolatedAptCache,
@@ -15,6 +20,7 @@ from hwpack.packages import (
PackageFetcher,
PackageMaker,
stringify_relationship,
+ TemporaryDirectoryManager,
)
from hwpack.testing import (
AptSourceFixture,
@@ -207,26 +213,26 @@ class StringifyRelationshipTests(TestCaseWithFixtures):
class TemporaryDirectoryManagerTests(TestCaseWithFixtures):
def test_enter_twice_fails(self):
- maker = PackageMaker()
+ maker = TemporaryDirectoryManager()
maker.__enter__()
self.assertRaises(AssertionError, maker.__enter__)
def test_exit_without_enter_silent(self):
- maker = PackageMaker()
+ maker = TemporaryDirectoryManager()
maker.__exit__()
def test_make_temporary_directory_without_enter_fails(self):
- maker = PackageMaker()
+ maker = TemporaryDirectoryManager()
self.assertRaises(AssertionError, maker.make_temporary_directory)
def test_make_temporary_directory_makes_directory(self):
- maker = PackageMaker()
+ maker = TemporaryDirectoryManager()
self.useFixture(ContextManagerFixture(maker))
tmpdir = maker.make_temporary_directory()
self.assertTrue(os.path.isdir(tmpdir))
def test_exit_removes_temporary_directory(self):
- maker = PackageMaker()
+ maker = TemporaryDirectoryManager()
self.useFixture(ContextManagerFixture(maker))
tmpdir = maker.make_temporary_directory()
maker.__exit__()
@@ -246,6 +252,27 @@ class LocalArchiveMakerTests(TestCaseWithFixtures):
candidate, package.filename)
self.assertThat(created_package, MatchesPackage(package))
+ def test_packages_from_sources_entry_for_debs_are_fetchable(self):
+ local_archive_maker = LocalArchiveMaker()
+ package_maker = PackageMaker()
+ self.useFixture(ContextManagerFixture(local_archive_maker))
+ self.useFixture(ContextManagerFixture(package_maker))
+ deb_file_path = package_maker.make_package("foo", "1.0", {})
+ target_package = FetchedPackage.from_deb(deb_file_path)
+ entry = local_archive_maker.sources_entry_for_debs(
+ [target_package])
+ tmpdir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, tmpdir)
+ with IsolatedAptCache([entry]) as cache:
+ candidate = cache.cache['foo'].candidate
+ acq = apt_pkg.Acquire(DummyProgress())
+ base = os.path.basename(candidate.filename)
+ acqfile = apt_pkg.AcquireFile(
+ acq, candidate.uri, candidate.md5, candidate.size,
+ base, destfile=os.path.join(tmpdir, 'deb'))
+ acq.run()
+ self.assertThat(acqfile.status, Equals(acqfile.STAT_DONE))
+
class PackageMakerTests(TestCaseWithFixtures):
@@ -720,7 +747,7 @@ class FetchedPackageTests(TestCaseWithFixtures):
target_package = DummyFetchedPackage(
"foo", "1.0", content=open(deb_file_path).read(), **dummy_relationships)
created_package = FetchedPackage.from_deb(deb_file_path)
- self.assertEqual(target_package, created_package)
+ self.assertThat(created_package, MatchesPackage(target_package))
def test_from_deb_with_depends(self):
self.create_package_and_assert_from_deb_translates_relationships(