8 from dedup.compression import decompress
10 def fetchiter(cursor):
11 rows = cursor.fetchmany()
14 rows = cursor.fetchmany()
16 def open_compressed_mirror_url(url, extensions=(".xz", ".gz", "")):
17 """Fetch the given url. Try appending each of the given compression
18 schemes and move on in case it doesn't exist. Decompress the resulting
20 @returns: a file-like with the decompressed contents
22 for ext in extensions:
24 handle = urllib.request.urlopen(url + ext)
25 except urllib.error.HTTPError as error:
28 except urllib.error.URLError as error:
29 if not hasattr(error.reason, "errno"):
31 if error.reason.errno != errno.ENOENT:
34 return decompress(handle, ext)
35 raise OSError(errno.ENOENT, "No such file or directory")
37 def iterate_packages(mirror, architecture, distribution="sid", section="main"):
38 """Download the relevant binary package list and generate
39 debian.deb822.Packages objects per listed package."""
40 url = "%s/dists/%s/%s/binary-%s/Packages" % \
41 (mirror, distribution, section, architecture)
42 with contextlib.closing(open_compressed_mirror_url(url)) as pkglist:
43 yield from debian.deb822.Packages.iter_paragraphs(pkglist)