Merge lp:~smoser/curtin/trunk.no-translations into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 289
Proposed branch: lp:~smoser/curtin/trunk.no-translations
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 58 lines (+37/-7)
1 file modified
curtin/util.py (+37/-7)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.no-translations
Reviewer Review Type Date Requested Status
curtin developers Pending
Review via email: mp+275451@code.launchpad.net

Commit message

apt-get update: do not download translation files and source files

getting translation files and source index files is simply waste in
an installer environment.

Additionally, Translation files are everybody's favorite source of
Hash Sum Mismatch errors.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

apt-get update: do not download translation files and source files

getting translation files and source index files is simply waste in
an installer environment.

Additionally, Translation files are everybody's favorite source of
Hash Sum Mismatch errors.

Revision history for this message
Ryan Harper (raharper) wrote :

man, where is the dpkg/apt flag to ignore src instead of modifying *every* apt source file?

Revision history for this message
Ryan Harper (raharper) wrote :

would a sed -i.curtin -e "s,deb-src,#deb-src,g" /etc/apt/sources.list /etc/apt/sources.d/*.list

be faster?

Revision history for this message
Scott Moser (smoser) wrote :

wrt faster for the sed. possibly, although it would incur overhead of 'sed' fork.
the bigger issue is it is lossy. a sources.list file might have some 'deb-src' lines commented out and others not (in fact base cloud image does have that). so my saving of a copy is safer in that regard.

with regard to translations, though, the option is probably a better path.

apt-get -o 'Acquire::Languages=none'

seems to do the trick. I had previously believed (maybe it was true at some point) that you had to remove the files in /var/lib/apt/cache also, or you'd get them despite your config.

So, i'll fix that part. that is less temporary files.

287. By Scott Moser

use apt-get option for no translations

Rather than a temporary config file, use the apt-get option to disable
translations. It really should be both more effective and more temporary.

288. By Scott Moser

remove the deletes as not necessary

Revision history for this message
Ryan Harper (raharper) wrote :

> wrt faster for the sed. possibly, although it would incur overhead of 'sed'
> fork.
> the bigger issue is it is lossy. a sources.list file might have some 'deb-src'
> lines commented out and others not (in fact base cloud image does have that).
> so my saving of a copy is safer in that regard.

This a moot point now, but sed -i<suffix> would retain the original, so we wouldn't be lossy; just messy with additional files and IO.

289. By Scott Moser

simplify a bit. only use one temp file

Revision history for this message
Scott Moser (smoser) wrote :
Download full text (3.8 KiB)

To show the improvement here, just run a test. Note, this is on
a cloud with a local mirror, so bandwidth is high and latency low.

The difference shown below is:
download: 1023 kB -> 1881 kB
time: 4.7s -> 6.6s
http connections: 11 -> 25 (both GET and stat)
http GET: 3 -> 7

We basically clean out to clean out all '-updates' things in
/var/lib/apt/lists/. This is reasonable, versus a full 'apt-get clean', as
during the life of a stable release, the 'trusty' pocket wont change, but
at any point after initial media create, you're probably out of date
on the trusty-updates things. Note, a full 'apt-get clean' would mean
we'd download the 'trusty' pocket things again, so both cases would just
have additional number of downloads.

## make sure you're up to date lists on everything, then clean out updates
% clean() { for f in /var/lib/apt/lists/*; do case "$f" in (*-updates*) rm -f "$f";; esac; done; }
% reset() { apt-get update --quiet >/dev/null 2>&1; clean; }

% reset; time python -c 'from curtin.util import apt_update; apt_update(target="/", force=True)'
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:1 http://nova.clouds.archive.ubuntu.com trusty-updates InRelease [64.4 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:2 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [635 kB]
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [323 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security InRelease
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Fetched 1,023 kB in 2s (495 kB/s)
Reading package lists...

real 0m4.731s
user 0m2.670s
sys 0m0.194s

% reset; time apt-get update --quiet
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:1 http://nova.clouds.archive.ubuntu.com trusty-updates InRelease [64.4 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:2 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [240 kB]Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [140 kB]
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [635 kB]
Hit http://security.ubuntu.com trusty-security InRelease
Get:5 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [323 kB]
Get:6 http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en [308 kB]
Get:7 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en [170 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.arch...

Read more...

290. By Scott Moser

minor cleanups / remove print / fix comments

291. By Scott Moser

fix usage of os.path.join

os.path.join("/target", "/etc/sources.list") returns "/etc/sources.list"

Fix that usage, and only get 'listfiles' once.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/util.py'
2--- curtin/util.py 2015-09-21 13:23:20 +0000
3+++ curtin/util.py 2015-10-26 18:04:10 +0000
4@@ -473,17 +473,47 @@
5
6 marker = os.path.join(target, marker)
7 # if marker exists, check if there are files that would make it obsolete
8+ listfiles = [os.path.join(target, "etc/apt/sources.list")]
9+ listfiles += glob.glob(
10+ os.path.join(target, "etc/apt/sources.list.d/*.list"))
11+
12 if os.path.exists(marker) and not force:
13- listfiles = [os.path.join(target, "/etc/apt/sources.list")]
14- listfiles += glob.glob(
15- os.path.join(target, "/etc/apt/sources.list.d/*.list"))
16 if len(find_newer(marker, listfiles)) == 0:
17 return
18
19- # we're not using 'run_apt_command' so we can use 'retries' to subp
20- apt_update = ['apt-get', 'update', '--quiet']
21- with RunInChroot(target, allow_daemons=True) as inchroot:
22- inchroot(apt_update, env=env, retries=retries)
23+ abs_tmpdir = tempfile.mkdtemp(dir=os.path.join(target, 'tmp'))
24+ try:
25+ abs_slist = abs_tmpdir + "/sources.list"
26+ abs_slistd = abs_tmpdir + "/sources.list.d"
27+ ch_tmpdir = "/tmp/" + os.path.basename(abs_tmpdir)
28+ ch_slist = ch_tmpdir + "/sources.list"
29+ ch_slistd = ch_tmpdir + "/sources.list.d"
30+
31+ # create tmpdir/sources.list with all lines other than deb-src
32+ # avoid apt complaining by using existing and empty dir for sourceparts
33+ os.mkdir(abs_slistd)
34+ with open(abs_slist, "w") as sfp:
35+ for sfile in listfiles:
36+ with open(sfile, "r") as fp:
37+ contents = fp.read()
38+ for line in contents.splitlines():
39+ line = line.lstrip()
40+ if not line.startswith("deb-src"):
41+ sfp.write(line + "\n")
42+
43+ update_cmd = [
44+ 'apt-get', '--quiet',
45+ '--option=Acquire::Languages=none',
46+ '--option=Dir::Etc::sourcelist=%s' % ch_slist,
47+ '--option=Dir::Etc::sourceparts=%s' % ch_slistd,
48+ 'update']
49+
50+ # do not using 'run_apt_command' so we can use 'retries' to subp
51+ with RunInChroot(target, allow_daemons=True) as inchroot:
52+ inchroot(update_cmd, env=env, retries=retries)
53+ finally:
54+ if abs_tmpdir:
55+ shutil.rmtree(abs_tmpdir)
56
57 with open(marker, "w") as fp:
58 fp.write(comment + "\n")

Subscribers

People subscribed via source and target branches