Merge ~cjwatson/launchpad-buildd:apt-lists into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: b6064e3d6b54ebcfd133887298e1d48842e8aa10
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:apt-lists
Merge into: launchpad-buildd:master
Diff against target: 96 lines (+46/-21)
2 files modified
debian/changelog (+3/-0)
lpbuildd/binarypackage.py (+43/-21)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+383060@code.launchpad.net

Commit message

Use apt helpers to read Packages files

Description of the change

lpbuildd/binarypackage.py: Use "apt-get indextargets" and "apt-helper cat-file" where they exist to read Packages files, rather than looking in /var/lib/apt/lists/ directly.

The apt maintainers don't want other code poking around in /var/lib/apt/lists/ directly, not least because they might e.g. want to start lz4-compressing the package lists there in the near future. Use the recommended helpers where available to read Packages files for dep-wait analysis. We still need the old paths because these helpers are only available in rather recent versions of apt.

This is essentially the same as https://code.launchpad.net/~cjwatson/launchpad-buildd/apt-lists/+merge/286751, converted to git and rebased on master.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 26d4622..9e45fea 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -27,6 +27,9 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
27 * Fix LXD.run to not default to universal_newlines=True.27 * Fix LXD.run to not default to universal_newlines=True.
28 * Run on Python 3 when built for >= bionic.28 * Run on Python 3 when built for >= bionic.
29 * Add some notes on the production deployment.29 * Add some notes on the production deployment.
30 * lpbuildd/binarypackage.py: Use "apt-get indextargets" and "apt-helper
31 cat-file" where they exist to read Packages files, rather than looking
32 in /var/lib/apt/lists/ directly.
3033
31 [ Dimitri John Ledkov ]34 [ Dimitri John Ledkov ]
32 * lxd: Add riscv64 to arch table.35 * lxd: Add riscv64 to arch table.
diff --git a/lpbuildd/binarypackage.py b/lpbuildd/binarypackage.py
index 2111bbe..19daca7 100644
--- a/lpbuildd/binarypackage.py
+++ b/lpbuildd/binarypackage.py
@@ -177,6 +177,34 @@ class BinaryPackageBuildManager(DebianBuildManager):
177 env["DEB_BUILD_OPTIONS"] = "noautodbgsym"177 env["DEB_BUILD_OPTIONS"] = "noautodbgsym"
178 self.runSubProcess(self._sbuildpath, args, env=env)178 self.runSubProcess(self._sbuildpath, args, env=env)
179179
180 def getAptLists(self):
181 """Yield each of apt's Packages files in turn as a file object."""
182 apt_helper = "/usr/lib/apt/apt-helper"
183 if os.path.exists(os.path.join(self.chroot_path, apt_helper[1:])):
184 paths = subprocess.check_output(
185 ["sudo", "chroot", self.chroot_path,
186 "apt-get", "indextargets", "--format", "$(FILENAME)",
187 "Created-By: Packages"],
188 universal_newlines=True).splitlines()
189 for path in paths:
190 helper = subprocess.Popen(
191 ["sudo", "chroot", self.chroot_path,
192 apt_helper, "cat-file", path],
193 stdout=subprocess.PIPE)
194 try:
195 yield helper.stdout
196 finally:
197 helper.stdout.read()
198 helper.wait()
199 else:
200 apt_lists = os.path.join(
201 self.chroot_path, "var", "lib", "apt", "lists")
202 for name in sorted(os.listdir(apt_lists)):
203 if name.endswith("_Packages"):
204 path = os.path.join(apt_lists, name)
205 with open(path, "rb") as packages_file:
206 yield packages_file
207
180 def getAvailablePackages(self):208 def getAvailablePackages(self):
181 """Return the available binary packages in the chroot.209 """Return the available binary packages in the chroot.
182210
@@ -184,27 +212,21 @@ class BinaryPackageBuildManager(DebianBuildManager):
184 available versions of each package.212 available versions of each package.
185 """213 """
186 available = defaultdict(set)214 available = defaultdict(set)
187 apt_lists = os.path.join(215 for packages_file in self.getAptLists():
188 self.chroot_path, "var", "lib", "apt", "lists")216 for section in apt_pkg.TagFile(packages_file):
189 for name in sorted(os.listdir(apt_lists)):217 available[section["package"]].add(section["version"])
190 if name.endswith("_Packages"):218 if "provides" in section:
191 path = os.path.join(apt_lists, name)219 provides = apt_pkg.parse_depends(section["provides"])
192 with open(path, "rb") as packages_file:220 for provide in provides:
193 for section in apt_pkg.TagFile(packages_file):221 # Disjunctions are currently undefined here.
194 available[section["package"]].add(section["version"])222 if len(provide) > 1:
195 if "provides" in section:223 continue
196 provides = apt_pkg.parse_depends(224 # Virtual packages may only provide an exact version
197 section["provides"])225 # or none.
198 for provide in provides:226 if provide[0][1] and provide[0][2] != "=":
199 # Disjunctions are currently undefined here.227 continue
200 if len(provide) > 1:228 available[provide[0][0]].add(
201 continue229 provide[0][1] if provide[0][1] else None)
202 # Virtual packages may only provide an exact
203 # version or none.
204 if provide[0][1] and provide[0][2] != "=":
205 continue
206 available[provide[0][0]].add(
207 provide[0][1] if provide[0][1] else None)
208 return available230 return available
209231
210 def getBuildDepends(self, dscpath, arch_indep):232 def getBuildDepends(self, dscpath, arch_indep):

Subscribers

People subscribed via source and target branches