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
=== modified file 'backends/packaging-apt-dpkg.py'
--- backends/packaging-apt-dpkg.py 2013-11-18 07:08:25 +0000
+++ backends/packaging-apt-dpkg.py 2014-01-21 22:47:21 +0000
@@ -836,44 +836,55 @@
836 release = self.get_distro_codename()836 release = self.get_distro_codename()
837 else:837 else:
838 release = self._distro_release_to_codename(release)838 release = self._distro_release_to_codename(release)
839839 not_found = False
840 map = os.path.join(dir, '%s-Contents-%s.gz' % (release, arch))840 for pocket in ['updates', 'security', 'proposed', '']:
841841 if pocket == '':
842 # check if map exists and is younger than a day; if not, we need to842 map = os.path.join(dir, '%s-Contents-%s.gz' % (release, arch))
843 # refresh it843 else:
844 try:844 map = os.path.join(dir, '%s-%s-Contents-%s.gz' % (release, pocket, arch))
845 st = os.stat(map)845
846 age = int(time.time() - st.st_mtime)846 # check if map exists and is younger than a day; if not, we need to
847 except OSError:847 # refresh it
848 age = None848 try:
849849 st = os.stat(map)
850 if age is None or age >= 86400:850 age = int(time.time() - st.st_mtime)
851 url = '%s/dists/%s/Contents-%s.gz' % (self._get_mirror(), release, arch)851 except OSError:
852852 age = None
853 src = urlopen(url)853
854 with open(map, 'wb') as f:854 if age is None or age >= 86400:
855 while True:855 if pocket == '':
856 data = src.read(1000000)856 url = '%s/dists/%s/Contents-%s.gz' % (self._get_mirror(), release, arch)
857 if not data:857 else:
858 break858 url = '%s/dists/%s-%s/Contents-%s.gz' % (self._get_mirror(), release, pocket, arch)
859 f.write(data)859
860 src.close()860 src = urlopen(url)
861 assert os.path.exists(map)861 with open(map, 'wb') as f:
862862 while True:
863 if file.startswith('/'):863 data = src.read(1000000)
864 file = file[1:]864 if not data:
865865 break
866 # zgrep is magnitudes faster than a 'gzip.open/split() loop'866 f.write(data)
867 package = None867 src.close()
868 zgrep = subprocess.Popen(['zgrep', '-m1', '^%s[[:space:]]' % file, map],868 assert os.path.exists(map)
869 stdout=subprocess.PIPE, stderr=subprocess.PIPE)869
870 out = zgrep.communicate()[0].decode('UTF-8')870 if file.startswith('/'):
871 # we do not check the return code, since zgrep -m1 often errors out871 file = file[1:]
872 # with 'stdout: broken pipe'872
873 if out:873 # zgrep is magnitudes faster than a 'gzip.open/split() loop'
874 package = out.split()[1].split(',')[0].split('/')[-1]874 package = None
875875 zgrep = subprocess.Popen(['zgrep', '-m1', '^%s[[:space:]]' % file, map],
876 return package876 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
877 out = zgrep.communicate()[0].decode('UTF-8')
878 # we do not check the return code, since zgrep -m1 often errors out
879 # with 'stdout: broken pipe'
880 if out:
881 package = out.split()[1].split(',')[0].split('/')[-1]
882 if not package:
883 not_found = True
884 else:
885 return package
886 if not_found:
887 return None
877888
878 @classmethod889 @classmethod
879 def _build_apt_sandbox(klass, apt_root, apt_sources):890 def _build_apt_sandbox(klass, apt_root, apt_sources):

Subscribers

People subscribed via source and target branches