Skip to content

Commit

Permalink
debmirror.py: support multiple compression formats for Sources
Browse files Browse the repository at this point in the history
Closes: #818324
  • Loading branch information
zacchiro committed Mar 17, 2016
1 parent 2ada35f commit 55f86dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
39 changes: 32 additions & 7 deletions debsources/debmirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
from debian import deb822
from debian.debian_support import version_compare

# supported compression formats for Sources files. Order does matter: formats
# appearing early in the list will be preferred to those appearing later
SOURCES_COMP_FMTS = ['gz', 'xz']


class DebmirrorError(RuntimeError):
"""runtime error when using a local Debian mirror"""
pass


class SourcePackage(deb822.Sources):
"""Debian source package, as it appears in a source mirror
Expand Down Expand Up @@ -201,15 +210,31 @@ def packages(self):
assert self._packages is not None
return self._packages

def __find_Sources_gz(self):
"""Find Sources.gz entries contained in the mirror
def __find_Sources(self):
"""Find Sources entries contained in the mirror, in various supported
compression formats
Return them as <suite, path> pairs. It will be up to client code to
recognize if they are compressed (e.g., based on file extension) and
uncompress them if needed
return them as <suite, path> pairs
"""
def choose_comp(base):
"""pick the preferred compressed variant of a given Sources file"""
variants = [base + '.' + fmt
for fmt in SOURCES_COMP_FMTS
if os.path.exists(base + '.' + fmt)]
if not variants:
raise DebmirrorError('no supported compressed variants of '
'Sources file: ' + base)
else:
return variants[0]

for root, dirs, files in os.walk(self._dists_dir):
src_indexes = [os.path.join(root, file)
for file in files
if file == "Sources.gz"]
src_bases = set([os.path.join(root, os.path.splitext(file)[0])
for file in files
if os.path.splitext(file)[0] == 'Sources'])
src_indexes = [choose_comp(b) for b in src_bases]
for f in src_indexes:
steps = f.split('/')
suite = steps[-4] # wheezy, jessie, sid, ...
Expand Down Expand Up @@ -245,7 +270,7 @@ def ls(self, suite=None):
self._suites = {}
self._packages = set()

for cursuite, src_index in self.__find_Sources_gz():
for cursuite, src_index in self.__find_Sources():
if suite is not None and cursuite != suite:
continue
with open(src_index) as i:
Expand Down
2 changes: 1 addition & 1 deletion testdata
Submodule testdata updated from c74112 to 43576d

0 comments on commit 55f86dd

Please sign in to comment.