Merge ~mwhudson/germinate:apt-config-archive into germinate:master

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: 959a1849805339fe65794b64bd6033d29db43242
Proposed branch: ~mwhudson/germinate:apt-config-archive
Merge into: germinate:master
Diff against target: 156 lines (+72/-11)
6 files modified
bin/germinate (+1/-1)
debian/changelog (+1/-0)
germinate/archive.py (+46/-0)
germinate/scripts/germinate_main.py (+13/-9)
man/germinate.1 (+10/-0)
setup.cfg (+1/-1)
Reviewer Review Type Date Requested Status
Julian Andres Klode Needs Fixing
Review via email: mp+456723@code.launchpad.net

Commit message

add a way to use an apt config file to find the indices

Description of the change

This was surprisingly straightforward. The man page changes are a total guess!

To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

From the apt side I feel like you'd want to directly pass a sources.list and otherwise initialise stuff with Dir::Etc set to /dev/null, that is create a config on the fly that sets

Dir::Etc::sourceslist "argument";
Dir::Etc "/dev/null";

From the germinate side of things, I'd like to hear more about the use case. Germinate is quite critical and used in very weird places and it's an explicit design decision to not use any apt bits in it, so it's a bit concerning.

review: Needs Information
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

So as mentioned out of band, the motivation for this is this ubuntu-cdimage change: https://code.launchpad.net/~mwhudson/ubuntu-cdimage/+git/ubuntu-cdimage-1/+merge/457014.

Passing just the .sources file would be OK, I guess, but would mean redundantly downloading the lists and require a separate configuration of a proxy and so on. Nothing very interesting but not ideal.

I didn't realise germinate had a policy of not relying on apt. I'm not sure having germinate know the layout of apt repositories independently of apt is worth this but well. At least this change should be a noop in the case that the new argument is not used.

Revision history for this message
Colin Watson (cjwatson) wrote :

While it's true that germinate tries to be independent of apt, I don't think calling `apt-get indextargets` in an optional code path should be a showstopper. (It would be a problem if it were mandatory, or if it unconditionally imported python-apt, or something like that.)

Revision history for this message
Julian Andres Klode (juliank) :
review: Needs Fixing
Revision history for this message
Michael Hudson-Doyle (mwhudson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/germinate b/bin/germinate
index 4bc397a..5a6e9ad 100755
--- a/bin/germinate
+++ b/bin/germinate
@@ -1,4 +1,4 @@
1#! /usr/bin/env python1#! /usr/bin/env python3
2"""Expand dependencies in a list of seed packages."""2"""Expand dependencies in a list of seed packages."""
33
4# Copyright (C) 2012 Canonical Ltd.4# Copyright (C) 2012 Canonical Ltd.
diff --git a/debian/changelog b/debian/changelog
index f0ffaec..f928e59 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ germinate (2.43) UNRELEASED; urgency=medium
22
3 [ Michael Hudson-Doyle ]3 [ Michael Hudson-Doyle ]
4 * Perform shallow clones of seed repos.4 * Perform shallow clones of seed repos.
5 * Add a way to use an apt config file to locate the indices.
56
6 -- Colin Watson <cjwatson@debian.org> Mon, 20 Nov 2023 09:24:27 +00007 -- Colin Watson <cjwatson@debian.org> Mon, 20 Nov 2023 09:24:27 +0000
78
diff --git a/germinate/archive.py b/germinate/archive.py
index 222e97e..7532aa2 100644
--- a/germinate/archive.py
+++ b/germinate/archive.py
@@ -21,6 +21,7 @@
21import logging21import logging
22import os22import os
23import shutil23import shutil
24import subprocess
24import tempfile25import tempfile
25from contextlib import closing26from contextlib import closing
26from urllib.parse import quote27from urllib.parse import quote
@@ -271,3 +272,48 @@ class TagFile(Archive):
271 finally:272 finally:
272 if self._cleanup:273 if self._cleanup:
273 shutil.rmtree(dirname)274 shutil.rmtree(dirname)
275
276
277class AptArchive(Archive):
278 def __init__(self, config_path):
279 self.config_path = config_path
280
281 def _get_files(self, identifier):
282 env = dict(os.environ, APT_CONFIG=self.config_path)
283 cmd = [
284 "apt-get",
285 "indextargets",
286 "--format",
287 "$(FILENAME)",
288 "Identifier: " + identifier,
289 ]
290 cp = subprocess.run(
291 cmd,
292 env=env,
293 capture_output=True,
294 encoding="utf-8",
295 check=True,
296 )
297 return cp.stdout.splitlines()
298
299 def sections(self):
300 for filename in self._get_files("Packages"):
301 _progress(
302 "processing packages file %s ...",
303 filename,
304 )
305 with open(
306 filename, encoding="UTF-8", errors="replace"
307 ) as file_obj:
308 for section in apt_pkg.TagFile(file_obj):
309 yield (IndexType.PACKAGES, section)
310 for filename in self._get_files("Sources"):
311 _progress(
312 "processing sources file %s ...",
313 filename,
314 )
315 with open(
316 filename, encoding="UTF-8", errors="replace"
317 ) as file_obj:
318 for section in apt_pkg.TagFile(file_obj):
319 yield (IndexType.SOURCES, section)
diff --git a/germinate/scripts/germinate_main.py b/germinate/scripts/germinate_main.py
index e6b9fa2..c6be0af 100644
--- a/germinate/scripts/germinate_main.py
+++ b/germinate/scripts/germinate_main.py
@@ -125,6 +125,7 @@ def parse_options(argv):
125 metavar="COMPS",125 metavar="COMPS",
126 help="operate on components COMPS (default: %default)",126 help="operate on components COMPS (default: %default)",
127 )127 )
128 parser.add_option("-C", "--apt-config", dest="apt_config")
128 parser.add_option(129 parser.add_option(
129 "--vcs",130 "--vcs",
130 dest="vcs",131 dest="vcs",
@@ -211,15 +212,18 @@ def main(argv):
211 g = Germinator(options.arch)212 g = Germinator(options.arch)
212 g._always_follow_build_depends = options.always_follow_build_depends213 g._always_follow_build_depends = options.always_follow_build_depends
213214
214 archive = germinate.archive.TagFile(215 if options.apt_config:
215 options.dist,216 archive = germinate.archive.AptArchive(options.apt_config)
216 options.components,217 else:
217 options.arch,218 archive = germinate.archive.TagFile(
218 options.mirrors,219 options.dist,
219 source_mirrors=options.source_mirrors,220 options.components,
220 installer_packages=options.installer,221 options.arch,
221 cleanup=options.cleanup,222 options.mirrors,
222 )223 source_mirrors=options.source_mirrors,
224 installer_packages=options.installer,
225 cleanup=options.cleanup,
226 )
223 g.parse_archive(archive)227 g.parse_archive(archive)
224228
225 if os.path.isfile("hints"):229 if os.path.isfile("hints"):
diff --git a/man/germinate.1 b/man/germinate.1
index f1adc23..25e44d9 100644
--- a/man/germinate.1
+++ b/man/germinate.1
@@ -303,6 +303,16 @@ The default is
303Operate on the specified components.303Operate on the specified components.
304The default is304The default is
305.Li main .305.Li main .
306.It Xo Fl C ,
307.Fl Fl apt-config Ar conf
308.Xc
309Use apt with APT_CONFIG set to the supplied value to find the
310package and source indices to operate on. Overrides any values passed
311for
312.Fl Fl mirror ,
313.Fl Fl source-mirror ,
314.Fl Fl dist , or
315.Fl Fl components .
306.It Fl Fl vcs Ns = Ns Brq Li auto Ns | Ns Li bzr Ns | Ns Li git316.It Fl Fl vcs Ns = Ns Brq Li auto Ns | Ns Li bzr Ns | Ns Li git
307Check out seeds from a version control system rather than fetching them317Check out seeds from a version control system rather than fetching them
308directly from a URL.318directly from a URL.
diff --git a/setup.cfg b/setup.cfg
index 1a20a71..ce0411d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
1[metadata]1[metadata]
2name = germinate2name = germinate
3version = 2.413version = 2.43
4description = Expand dependencies in a list of seed packages4description = Expand dependencies in a list of seed packages
5author = Scott James Remnant5author = Scott James Remnant
6author_email = scott@ubuntu.com6author_email = scott@ubuntu.com

Subscribers

People subscribed via source and target branches