diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 347: Allow hwpacks to remove packages from the assume-installed set.

Message ID 20110525210124.10110.44485.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

James Westby May 25, 2011, 9:01 p.m. UTC
Merge authors:
  James Westby (james-w)
Related merge proposals:
  https://code.launchpad.net/~james-w/linaro-image-tools/allow-remove-packages/+merge/62357
  proposed by: James Westby (james-w)
------------------------------------------------------------
revno: 347 [merge]
committer: James Westby <james.westby@linaro.org>
branch nick: trunk
timestamp: Wed 2011-05-25 16:59:19 -0400
message:
  Allow hwpacks to remove packages from the assume-installed set.
modified:
  linaro_image_tools/hwpack/packages.py
  linaro_image_tools/hwpack/tests/test_packages.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/hwpack/packages.py'
--- linaro_image_tools/hwpack/packages.py	2011-05-10 15:06:52 +0000
+++ linaro_image_tools/hwpack/packages.py	2011-05-25 20:59:19 +0000
@@ -674,19 +674,35 @@ 
             base = os.path.basename(candidate.filename)
             result_package = FetchedPackage.from_apt(candidate, base)
             fetched[package] = result_package
-        for package in packages:
-            self.cache.cache[package].mark_install(auto_fix=False)
+
+        def check_no_broken_packages():
             if self.cache.cache.broken_count:
                 raise DependencyNotSatisfied(
                     "Unable to satisfy dependencies of %s" %
                     ", ".join([p.name for p in self.cache.cache
                         if p.is_inst_broken]))
+
+        for package in packages:
+            try:
+                self.cache.cache[package].mark_install(auto_fix=True)
+            except SystemError:
+                # Either we raise a DependencyNotSatisfied error
+                # if some packages are broken, or we raise the original
+                # error if there was another cause
+                check_no_broken_packages()
+                raise
+            # Check that nothing was broken, even if mark_install didn't
+            # raise SystemError, just to make sure.
+            check_no_broken_packages()
         self._filter_ignored(fetched)
         if not download_content:
+            self.cache.cache.clear()
             return fetched.values()
         acq = apt_pkg.Acquire(DummyProgress())
         acqfiles = []
         for package in self.cache.cache.get_changes():
+            if (package.marked_delete or package.marked_keep):
+                continue
             logger.debug("Fetching %s ..." % package)
             candidate = package.candidate
             base = os.path.basename(candidate.filename)

=== modified file 'linaro_image_tools/hwpack/tests/test_packages.py'
--- linaro_image_tools/hwpack/tests/test_packages.py	2011-04-05 21:31:29 +0000
+++ linaro_image_tools/hwpack/tests/test_packages.py	2011-05-25 20:55:24 +0000
@@ -1114,6 +1114,38 @@ 
         fetcher.fetch_packages(["foo"])
         self.assertEqual([], list(fetcher.cache.cache.get_changes()))
 
+    def test_fetch_packages_without_content_leaves_no_marked_changes(self):
+        wanted_package = DummyFetchedPackage("foo", "1.0")
+        source = self.useFixture(AptSourceFixture([wanted_package]))
+        fetcher = self.get_fetcher([source])
+        fetcher.fetch_packages(["foo"], download_content=False)
+        self.assertEqual([], list(fetcher.cache.cache.get_changes()))
+
+    def test_fetch_packages_can_remove_package(self):
+        """Check that removed packages aren't included in the hwpack
+
+        When installing the hwpack would cause an "assume-installed" package
+        to be removed the hwpack shouldn't contain that package.
+        """
+        wanted_package = DummyFetchedPackage(
+            "foo", "1.0", conflicts="provided", provides="provided",
+            depends="zoo", replaces="provided")
+        top_package = DummyFetchedPackage(
+            "top", "1.0", recommends="bar, baz")
+        dep_package = DummyFetchedPackage(
+            "bar", "1.0", depends="baz")
+        conflict_package = DummyFetchedPackage(
+            "baz", "1.0", recommends="bar", provides="provided",
+            conflicts="provided", replaces="provided")
+        extra_package = DummyFetchedPackage("zoo", "1.0")
+        source = self.useFixture(AptSourceFixture(
+            [wanted_package, dep_package, conflict_package, extra_package,
+                top_package]))
+        fetcher = self.get_fetcher([source])
+        fetcher.ignore_packages(["top"])
+        fetched = fetcher.fetch_packages(["foo"])
+        self.assertEqual([wanted_package, extra_package], fetched)
+
     def test_ignore_with_provides(self):
         ignored_package = DummyFetchedPackage(
             "ubuntu-minimal", "1.0", depends="apt-utils")