Merge ~brian-murray/ubuntu-archive-tools:generate-freeze into ubuntu-archive-tools:main

Proposed by Brian Murray
Status: Merged
Merge reported by: Brian Murray
Merged at revision: 1e8f4763d6035ff2c8babe8d21cf2546ddc3afc7
Proposed branch: ~brian-murray/ubuntu-archive-tools:generate-freeze
Merge into: ubuntu-archive-tools:main
Diff against target: 128 lines (+61/-9)
1 file modified
generate-freeze-block (+61/-9)
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+410148@code.launchpad.net

Description of the change

This modifies generate freeze to use a local apt cache, after adding sources.list entries for every architecture, to find packages which are seeded. Subsequently, packages like linux-firmware-raspi2 (only available on arm) are now added to the freeze-block.

Here's a diff of the packages in the block:
https://paste.ubuntu.com/p/dxJXDMD32f/

To post a comment you must log in.
f189b63... by Brian Murray

use variables in some more spots for the arches

Revision history for this message
Steve Langasek (vorlon) wrote :

Great! One thing I think must be fixed before landing (using proper tempdirs), and some suggestions for optimizations; comments inline.

review: Needs Fixing
6b301e1... by Brian Murray

only use the release pocket and don't add deb-src lines

8c6e20c... by Brian Murray

use ~/.cache/ for storing apt lists

Revision history for this message
Brian Murray (brian-murray) wrote :

I think I've addressed all the issues now.

Revision history for this message
Steve Langasek (vorlon) :
1e8f476... by Brian Murray

use the ubuntu-archive-tools cache_dir

Revision history for this message
Brian Murray (brian-murray) wrote :

I've gone ahead and put the freeze-block folder under ubuntu-archive-tools so if somebody is browsing their .cache directory it might be clearer what freeze-block is. I've kept it as a separate directory in case some other tool ends up needing an apt cache.

Revision history for this message
Steve Langasek (vorlon) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/generate-freeze-block b/generate-freeze-block
2index 0bb2862..ba841b4 100755
3--- a/generate-freeze-block
4+++ b/generate-freeze-block
5@@ -3,6 +3,7 @@
6
7 # Copyright (C) 2013 Canonical Ltd.
8 # Author: Iain Lane <iain.lane@canonical.com>
9+# Author: Brian Murray <brian.murray@canonical.com>
10
11 # This library is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU Lesser General Public
13@@ -20,6 +21,7 @@
14 # USA
15
16 import argparse
17+import apt
18 import apt_pkg
19 import gzip
20 import io
21@@ -27,12 +29,16 @@ import json
22 import logging
23 import os
24 import re
25-import urllib.request
26+import shutil
27 import sys
28+import urllib.request
29+
30+from launchpadlib.launchpad import Launchpad
31
32 PARSED_SEEDS_URL = \
33 'http://qa.ubuntuwire.org/ubuntu-seeded-packages/seeded.json.gz'
34 LOGGER = logging.getLogger(os.path.basename(sys.argv[0]))
35+CACHE_DIR = os.path.expanduser("~/.cache/ubuntu-archive-tools/freeze-block/")
36
37
38 class GetPackage():
39@@ -43,10 +49,47 @@ class GetPackage():
40 if not GetPackage.apt_cache_initialised:
41 apt_pkg.init()
42 GetPackage.apt_cache_initialised = True
43-
44- self.cache = apt_pkg.Cache(None)
45- self.pkgrecords = apt_pkg.PackageRecords(self.cache)
46- self.depcache = apt_pkg.DepCache(self.cache)
47+ try:
48+ os.makedirs("%s/apt/lists/partial" % CACHE_DIR, exist_ok=True)
49+ except OSError:
50+ pass
51+ apt_pkg.config.set("Dir::state", "%s/apt/" % CACHE_DIR)
52+ apt_pkg.config.set("Dir::Etc", "%s./apt" % CACHE_DIR)
53+
54+ lp = Launchpad.login_anonymously('generate-freeze-block',
55+ 'production',
56+ version='devel')
57+ ubuntu = lp.distributions['ubuntu']
58+ series = ubuntu.current_series.name
59+ self.all_arches = [a.architecture_tag
60+ for a in ubuntu.current_series.architectures]
61+ main_arches = ("amd64", "i386")
62+ port_arches = set(self.all_arches) - set(main_arches)
63+
64+ comps = ("main", "restricted", "universe", "multiverse")
65+ for arch in main_arches:
66+ url = "http://archive.ubuntu.com/ubuntu"
67+ line = "deb [arch=%s] %s %s %s\n" % \
68+ (arch, url, series, " ".join(comps))
69+ with open("%s/apt/sources.list" % CACHE_DIR, "a") as sources_list:
70+ sources_list.write(line)
71+ for arch in port_arches:
72+ url = "http://ports.ubuntu.com/ubuntu-ports"
73+ line = "deb [arch=%s] %s %s %s\n" % \
74+ (arch, url, series, " ".join(comps))
75+ with open("%s/apt/sources.list" % CACHE_DIR, "a") as sources_list:
76+ sources_list.write(line)
77+ apt_pkg.config.set("APT::Architecture", "amd64")
78+ apt_pkg.config.set("APT::Architectures",
79+ "%s" % " ".join(self.all_arches))
80+ self.cache = apt.Cache(None)
81+ keyring = "/usr/share/keyrings/ubuntu-archive-keyring.gpg"
82+ apt_pkg.config.set("Dir::Etc::Trusted", keyring)
83+ self.cache.update(None)
84+ self.cache.open()
85+ self.ap_cache = apt_pkg.Cache(None)
86+ self.pkgrecords = apt_pkg.PackageRecords(self.ap_cache)
87+ self.depcache = apt_pkg.DepCache(self.ap_cache)
88
89 # Download & parse the seeds
90 response = urllib.request.urlopen(PARSED_SEEDS_URL)
91@@ -58,9 +101,15 @@ class GetPackage():
92
93 def getsourcepackage(self, pkg):
94 pkg = re.sub(':.*', '', pkg)
95- try:
96- candidate = self.depcache.get_candidate_ver(self.cache[pkg])
97- except KeyError: # no package found (arch specific?)
98+ candidate = ''
99+ for arch in self.all_arches:
100+ try:
101+ candidate = self.depcache.get_candidate_ver(self.ap_cache[pkg, arch])
102+ except KeyError:
103+ pass
104+ if candidate:
105+ break
106+ if not candidate:
107 return
108 try:
109 self.pkgrecords.lookup(candidate.file_list[0])
110@@ -78,7 +127,7 @@ def main():
111 help='Block only packages unique to FLAVOURS')
112 parser.add_argument('--debug', '-d', action='store_true',
113 help='Output some extra debugging')
114- parser.add_argument('--not-unique','-n', action='store_true',
115+ parser.add_argument('--not-unique', '-n', action='store_true',
116 help='Block only packages also seeded outside of FLAVOURS')
117 args = parser.parse_args()
118
119@@ -130,6 +179,9 @@ def main():
120 output.add(source_pkg)
121
122 print ("block", " ".join(sorted(output)))
123+ # only cleanup the sources.list file in case more arches are added
124+ if os.path.exists("%s/apt/sources.list" % CACHE_DIR):
125+ os.remove("%s/apt/sources.list" % CACHE_DIR)
126
127
128 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches