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
1diff --git a/bin/germinate b/bin/germinate
2index 4bc397a..5a6e9ad 100755
3--- a/bin/germinate
4+++ b/bin/germinate
5@@ -1,4 +1,4 @@
6-#! /usr/bin/env python
7+#! /usr/bin/env python3
8 """Expand dependencies in a list of seed packages."""
9
10 # Copyright (C) 2012 Canonical Ltd.
11diff --git a/debian/changelog b/debian/changelog
12index f0ffaec..f928e59 100644
13--- a/debian/changelog
14+++ b/debian/changelog
15@@ -2,6 +2,7 @@ germinate (2.43) UNRELEASED; urgency=medium
16
17 [ Michael Hudson-Doyle ]
18 * Perform shallow clones of seed repos.
19+ * Add a way to use an apt config file to locate the indices.
20
21 -- Colin Watson <cjwatson@debian.org> Mon, 20 Nov 2023 09:24:27 +0000
22
23diff --git a/germinate/archive.py b/germinate/archive.py
24index 222e97e..7532aa2 100644
25--- a/germinate/archive.py
26+++ b/germinate/archive.py
27@@ -21,6 +21,7 @@
28 import logging
29 import os
30 import shutil
31+import subprocess
32 import tempfile
33 from contextlib import closing
34 from urllib.parse import quote
35@@ -271,3 +272,48 @@ class TagFile(Archive):
36 finally:
37 if self._cleanup:
38 shutil.rmtree(dirname)
39+
40+
41+class AptArchive(Archive):
42+ def __init__(self, config_path):
43+ self.config_path = config_path
44+
45+ def _get_files(self, identifier):
46+ env = dict(os.environ, APT_CONFIG=self.config_path)
47+ cmd = [
48+ "apt-get",
49+ "indextargets",
50+ "--format",
51+ "$(FILENAME)",
52+ "Identifier: " + identifier,
53+ ]
54+ cp = subprocess.run(
55+ cmd,
56+ env=env,
57+ capture_output=True,
58+ encoding="utf-8",
59+ check=True,
60+ )
61+ return cp.stdout.splitlines()
62+
63+ def sections(self):
64+ for filename in self._get_files("Packages"):
65+ _progress(
66+ "processing packages file %s ...",
67+ filename,
68+ )
69+ with open(
70+ filename, encoding="UTF-8", errors="replace"
71+ ) as file_obj:
72+ for section in apt_pkg.TagFile(file_obj):
73+ yield (IndexType.PACKAGES, section)
74+ for filename in self._get_files("Sources"):
75+ _progress(
76+ "processing sources file %s ...",
77+ filename,
78+ )
79+ with open(
80+ filename, encoding="UTF-8", errors="replace"
81+ ) as file_obj:
82+ for section in apt_pkg.TagFile(file_obj):
83+ yield (IndexType.SOURCES, section)
84diff --git a/germinate/scripts/germinate_main.py b/germinate/scripts/germinate_main.py
85index e6b9fa2..c6be0af 100644
86--- a/germinate/scripts/germinate_main.py
87+++ b/germinate/scripts/germinate_main.py
88@@ -125,6 +125,7 @@ def parse_options(argv):
89 metavar="COMPS",
90 help="operate on components COMPS (default: %default)",
91 )
92+ parser.add_option("-C", "--apt-config", dest="apt_config")
93 parser.add_option(
94 "--vcs",
95 dest="vcs",
96@@ -211,15 +212,18 @@ def main(argv):
97 g = Germinator(options.arch)
98 g._always_follow_build_depends = options.always_follow_build_depends
99
100- archive = germinate.archive.TagFile(
101- options.dist,
102- options.components,
103- options.arch,
104- options.mirrors,
105- source_mirrors=options.source_mirrors,
106- installer_packages=options.installer,
107- cleanup=options.cleanup,
108- )
109+ if options.apt_config:
110+ archive = germinate.archive.AptArchive(options.apt_config)
111+ else:
112+ archive = germinate.archive.TagFile(
113+ options.dist,
114+ options.components,
115+ options.arch,
116+ options.mirrors,
117+ source_mirrors=options.source_mirrors,
118+ installer_packages=options.installer,
119+ cleanup=options.cleanup,
120+ )
121 g.parse_archive(archive)
122
123 if os.path.isfile("hints"):
124diff --git a/man/germinate.1 b/man/germinate.1
125index f1adc23..25e44d9 100644
126--- a/man/germinate.1
127+++ b/man/germinate.1
128@@ -303,6 +303,16 @@ The default is
129 Operate on the specified components.
130 The default is
131 .Li main .
132+.It Xo Fl C ,
133+.Fl Fl apt-config Ar conf
134+.Xc
135+Use apt with APT_CONFIG set to the supplied value to find the
136+package and source indices to operate on. Overrides any values passed
137+for
138+.Fl Fl mirror ,
139+.Fl Fl source-mirror ,
140+.Fl Fl dist , or
141+.Fl Fl components .
142 .It Fl Fl vcs Ns = Ns Brq Li auto Ns | Ns Li bzr Ns | Ns Li git
143 Check out seeds from a version control system rather than fetching them
144 directly from a URL.
145diff --git a/setup.cfg b/setup.cfg
146index 1a20a71..ce0411d 100644
147--- a/setup.cfg
148+++ b/setup.cfg
149@@ -1,6 +1,6 @@
150 [metadata]
151 name = germinate
152-version = 2.41
153+version = 2.43
154 description = Expand dependencies in a list of seed packages
155 author = Scott James Remnant
156 author_email = scott@ubuntu.com

Subscribers

People subscribed via source and target branches