aboutsummaryrefslogtreecommitdiff
path: root/hwpack
diff options
context:
space:
mode:
authorMichael Hudson <michael.hudson@linaro.org>2010-12-16 14:14:36 +1300
committerMichael Hudson <michael.hudson@linaro.org>2010-12-16 14:14:36 +1300
commit260a6cffd5ee31b4504278b78901ee220a7833ce (patch)
tree22da0bb56a7b0936780a624ac302475a9eed767b /hwpack
parentad618cafaae8b81bbd10bf2897f70753bbdd669e (diff)
make test pass, some hacking though
Diffstat (limited to 'hwpack')
-rw-r--r--hwpack/builder.py5
-rw-r--r--hwpack/packages.py22
-rw-r--r--hwpack/tests/test_builder.py2
3 files changed, 23 insertions, 6 deletions
diff --git a/hwpack/builder.py b/hwpack/builder.py
index 8aa2b04..8e049f2 100644
--- a/hwpack/builder.py
+++ b/hwpack/builder.py
@@ -47,11 +47,12 @@ class HardwarePackBuilder(object):
sources[None] = (
local_archive_maker.sources_entry_for_debs(
[FetchedPackage.from_deb(deb)
- for deb in self.local_debs]))
+ for deb in self.local_debs],
+ 'hwpack-local'))
hwpack.add_apt_sources(sources)
logger.info("Fetching packages")
fetcher = PackageFetcher(
- sources.values(), architecture=architecture)
+ sources.values(), architecture=architecture, prefer_label='hwpack-local')
with fetcher:
fetcher.ignore_packages(self.config.assume_installed)
packages = fetcher.fetch_packages(
diff --git a/hwpack/packages.py b/hwpack/packages.py
index fda5475..629e631 100644
--- a/hwpack/packages.py
+++ b/hwpack/packages.py
@@ -162,10 +162,14 @@ class TemporaryDirectoryManager(object):
class LocalArchiveMaker(TemporaryDirectoryManager):
- def sources_entry_for_debs(self, local_debs):
+ def sources_entry_for_debs(self, local_debs, label=None):
tmpdir = self.make_temporary_directory()
with open(os.path.join(tmpdir, 'Packages'), 'w') as packages_file:
packages_file.write(get_packages_file(local_debs, rel_to=tmpdir))
+ if label:
+ os.system(
+ 'apt-ftparchive -o"APT::FTPArchive::Release::Label=%s" '
+ 'release %s > %s/Release' % (label, tmpdir, tmpdir))
return 'file://%s ./' % (tmpdir, )
@@ -419,7 +423,7 @@ class IsolatedAptCache(object):
:type cache: apt.cache.Cache
"""
- def __init__(self, sources, architecture=None):
+ def __init__(self, sources, architecture=None, prefer_label=None):
"""Create an IsolatedAptCache.
:param sources: a list of sources such that they can be prefixed
@@ -431,6 +435,7 @@ class IsolatedAptCache(object):
self.sources = sources
self.architecture = architecture
self.tempdir = None
+ self.prefer_label = prefer_label
def prepare(self):
"""Prepare the IsolatedAptCache for use.
@@ -460,6 +465,14 @@ class IsolatedAptCache(object):
f.write(
'Apt {\nArchitecture "%s";\n'
'Install-Recommends "true";\n}\n' % self.architecture)
+ if self.prefer_label is not None:
+ apt_preferences = os.path.join(
+ self.tempdir, "etc", "apt", "preferences")
+ with open(apt_preferences, 'w') as f:
+ f.write(
+ 'Package: *\n'
+ 'Pin: release l=%s\n'
+ 'Pin-Priority: 1001\n' % self.prefer_label)
self.cache = Cache(rootdir=self.tempdir, memonly=True)
logger.debug("Updating apt cache")
self.cache.update()
@@ -511,7 +524,7 @@ class DependencyNotSatisfied(Exception):
class PackageFetcher(object):
"""A class to fetch packages from a defined list of sources."""
- def __init__(self, sources, architecture=None):
+ def __init__(self, sources, architecture=None, prefer_label=None):
"""Create a PackageFetcher.
Once created a PackageFetcher should have its `prepare` method
@@ -523,7 +536,8 @@ class PackageFetcher(object):
:param architecture: the architecture to fetch packages for.
:type architecture: str
"""
- self.cache = IsolatedAptCache(sources, architecture=architecture)
+ self.cache = IsolatedAptCache(
+ sources, architecture=architecture, prefer_label=prefer_label)
def prepare(self):
"""Prepare the PackageFetcher for use.
diff --git a/hwpack/tests/test_builder.py b/hwpack/tests/test_builder.py
index ecd870b..a393614 100644
--- a/hwpack/tests/test_builder.py
+++ b/hwpack/tests/test_builder.py
@@ -220,6 +220,8 @@ class HardwarePackBuilderTests(TestCaseWithFixtures):
source_id = "ubuntu"
maker = PackageMaker()
self.useFixture(ContextManagerFixture(maker))
+ # The point here is that remote_package has a later version than
+ # local_package, but local_package is still preferred.
remote_package = DummyFetchedPackage(
package_name, "1.1", architecture=architecture)
local_path = maker.make_package(