Merge lp:~lool/xdeb/dont-load-apt-cache-on-import into lp:xdeb

Proposed by Loïc Minier
Status: Needs review
Proposed branch: lp:~lool/xdeb/dont-load-apt-cache-on-import
Merge into: lp:xdeb
Diff against target: 90 lines (+20/-1)
2 files modified
aptutils.py (+16/-1)
xdeb.py (+4/-0)
To merge this branch: bzr merge lp:~lool/xdeb/dont-load-apt-cache-on-import
Reviewer Review Type Date Requested Status
xdeb-team Pending
Review via email: mp+79820@code.launchpad.net

Description of the change

This speeds up importing aptutils.py and xdeb.py by deferring the cache = apt.Cache() in aptutils, which also speeds up running the testsutie; I've also added some progress messages for this step.

It's a bit ugly that xdeb.py functions have to call init_pkg_cache() (NB: the init_cache() name is used in another function in xdeb already), but I couldn't implement __get__()-style hooks here as "aptutils.cache" isn't in a class. We could either move to an aptutils.get_cache() method or move progressively to something like a XdebContext class which would hold things like an apt.Cache() and other globals, and which could use __get__ tricks.

To post a comment you must log in.

Unmerged revisions

300. By Loïc Minier

Add progress message when rebuilding package cache.

299. By Loïc Minier

Defer building cache = apt.Cache() in aptutils as this is lengthy; call sites
need to init_pkg_cache() first.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'aptutils.py'
2--- aptutils.py 2011-09-26 16:48:55 +0000
3+++ aptutils.py 2011-10-19 13:59:23 +0000
4@@ -20,7 +20,7 @@
5 import utils
6
7
8-cache = apt.Cache()
9+cache = None
10
11 srcrec = None
12 pkgsrc = None
13@@ -51,12 +51,14 @@
14
15
16 def reopen_cache():
17+ print "Rebuilding package cache ..."
18 cache.open()
19
20
21 def update_destdir(options):
22 # We can't use this until we've stopped using apt-get to install
23 # build-dependencies.
24+ #init_pkg_cache()
25 #cache.update(sources_list='%s.destdir' % sources_list_path(options))
26 command = ['apt-get']
27 command.extend(apt_options(options))
28@@ -155,6 +157,16 @@
29 update_apt_repository(options)
30
31
32+def init_pkg_cache():
33+ """Build package cache."""
34+ global cache
35+ if cache is not None:
36+ return
37+
38+ print "Building package cache ..."
39+ cache = apt.Cache()
40+
41+
42 def init_src_cache():
43 """Build a source package cache."""
44 global srcrec, pkgsrc
45@@ -224,6 +236,7 @@
46
47 def get_real_pkg(pkg):
48 """Get the real name of binary package pkg, resolving Provides."""
49+ init_pkg_cache()
50 if pkg in cache and cache[pkg].versions:
51 return pkg
52 elif pkg in seen_providers:
53@@ -279,6 +292,7 @@
54
55 def get_pkg_record(pkg):
56 """Return a parsed binary package record for binary package pkg."""
57+ init_pkg_cache()
58 return deb822.Packages(str(cache[pkg].candidate.record))
59
60
61@@ -292,6 +306,7 @@
62
63 def get_src_binaries(src):
64 """Return all the binaries produced by source package src."""
65+ init_pkg_cache()
66 record = get_src_record(src)
67 if record is not None:
68 bins = [b[0]['name'] for b in record.relations['binary']]
69
70=== modified file 'xdeb.py'
71--- xdeb.py 2011-10-05 15:19:38 +0000
72+++ xdeb.py 2011-10-19 13:59:23 +0000
73@@ -418,6 +418,8 @@
74 re_deb_filename = re.compile(r"(.+?)_(.+?)_(.+)\.deb$")
75
76 def install_build_depends(options, srcs):
77+ aptutils.init_pkg_cache()
78+
79 available_builddeps = set()
80 if options.architecture != build_arch:
81 if ('binutils-multiarch' in aptutils.cache and
82@@ -699,6 +701,8 @@
83
84 aptutils.update_apt_repository(options, force_rebuild=previously_built)
85
86+ aptutils.init_apt_cache()
87+
88 if previously_built:
89 # We'll need to install all these again.
90 command = ['apt-get', '-y']

Subscribers

People subscribed via source and target branches