Merge lp:~brian-murray/apport/use-more-contents.gz into lp:~apport-hackers/apport/trunk

Proposed by Brian Murray
Status: Merged
Merged at revision: 2758
Proposed branch: lp:~brian-murray/apport/use-more-contents.gz
Merge into: lp:~apport-hackers/apport/trunk
Diff against target: 97 lines (+49/-38)
1 file modified
backends/packaging-apt-dpkg.py (+49/-38)
To merge this branch: bzr merge lp:~brian-murray/apport/use-more-contents.gz
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+202566@code.launchpad.net

Description of the change

Bug 1271258 has details regarding this change.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks! That's a good idea indeed. I'd like to make some changes to it, though:

 - Add a test case (backend_apt_dpkg.test_get_file_package_uninstalled)
 - The "not_found" logic is a bit hard to read, and unnecessary
 - This assumes that these additional pockets always exist, which isn't the case for e. g. Debian. So this would cause an URLError crash.

Revision history for this message
Martin Pitt (pitti) wrote :

I did the above changes, plus removing the need for the two new "if pocket == ''" conditions: http://bazaar.launchpad.net/~apport-hackers/apport/trunk/revision/2758

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'backends/packaging-apt-dpkg.py'
2--- backends/packaging-apt-dpkg.py 2013-11-18 07:08:25 +0000
3+++ backends/packaging-apt-dpkg.py 2014-01-21 22:47:21 +0000
4@@ -836,44 +836,55 @@
5 release = self.get_distro_codename()
6 else:
7 release = self._distro_release_to_codename(release)
8-
9- map = os.path.join(dir, '%s-Contents-%s.gz' % (release, arch))
10-
11- # check if map exists and is younger than a day; if not, we need to
12- # refresh it
13- try:
14- st = os.stat(map)
15- age = int(time.time() - st.st_mtime)
16- except OSError:
17- age = None
18-
19- if age is None or age >= 86400:
20- url = '%s/dists/%s/Contents-%s.gz' % (self._get_mirror(), release, arch)
21-
22- src = urlopen(url)
23- with open(map, 'wb') as f:
24- while True:
25- data = src.read(1000000)
26- if not data:
27- break
28- f.write(data)
29- src.close()
30- assert os.path.exists(map)
31-
32- if file.startswith('/'):
33- file = file[1:]
34-
35- # zgrep is magnitudes faster than a 'gzip.open/split() loop'
36- package = None
37- zgrep = subprocess.Popen(['zgrep', '-m1', '^%s[[:space:]]' % file, map],
38- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39- out = zgrep.communicate()[0].decode('UTF-8')
40- # we do not check the return code, since zgrep -m1 often errors out
41- # with 'stdout: broken pipe'
42- if out:
43- package = out.split()[1].split(',')[0].split('/')[-1]
44-
45- return package
46+ not_found = False
47+ for pocket in ['updates', 'security', 'proposed', '']:
48+ if pocket == '':
49+ map = os.path.join(dir, '%s-Contents-%s.gz' % (release, arch))
50+ else:
51+ map = os.path.join(dir, '%s-%s-Contents-%s.gz' % (release, pocket, arch))
52+
53+ # check if map exists and is younger than a day; if not, we need to
54+ # refresh it
55+ try:
56+ st = os.stat(map)
57+ age = int(time.time() - st.st_mtime)
58+ except OSError:
59+ age = None
60+
61+ if age is None or age >= 86400:
62+ if pocket == '':
63+ url = '%s/dists/%s/Contents-%s.gz' % (self._get_mirror(), release, arch)
64+ else:
65+ url = '%s/dists/%s-%s/Contents-%s.gz' % (self._get_mirror(), release, pocket, arch)
66+
67+ src = urlopen(url)
68+ with open(map, 'wb') as f:
69+ while True:
70+ data = src.read(1000000)
71+ if not data:
72+ break
73+ f.write(data)
74+ src.close()
75+ assert os.path.exists(map)
76+
77+ if file.startswith('/'):
78+ file = file[1:]
79+
80+ # zgrep is magnitudes faster than a 'gzip.open/split() loop'
81+ package = None
82+ zgrep = subprocess.Popen(['zgrep', '-m1', '^%s[[:space:]]' % file, map],
83+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
84+ out = zgrep.communicate()[0].decode('UTF-8')
85+ # we do not check the return code, since zgrep -m1 often errors out
86+ # with 'stdout: broken pipe'
87+ if out:
88+ package = out.split()[1].split(',')[0].split('/')[-1]
89+ if not package:
90+ not_found = True
91+ else:
92+ return package
93+ if not_found:
94+ return None
95
96 @classmethod
97 def _build_apt_sandbox(klass, apt_root, apt_sources):

Subscribers

People subscribed via source and target branches