Refactor _read_binaries to reduce its complexity a bit

Signed-off-by: Niels Thykier <niels@thykier.net>
ubuntu/rebased
Niels Thykier 6 years ago
parent f547fb20b1
commit 0099c34d93
No known key found for this signature in database
GPG Key ID: A65B78DBE67C7AAC

@ -183,6 +183,12 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader):
return sources return sources
@staticmethod
def merge_fields(get_field, *field_names, separator=', '):
"""Merge two or more fields (filtering out empty fields; returning None if all are empty)
"""
return separator.join(filter(None, (get_field(x) for x in field_names))) or None
def _read_packages_file(self, filename, arch, srcdist, packages=None, intern=sys.intern): def _read_packages_file(self, filename, arch, srcdist, packages=None, intern=sys.intern):
self.logger.info("Loading binary packages from %s", filename) self.logger.info("Loading binary packages from %s", filename)
@ -226,25 +232,13 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader):
# Merge Pre-Depends with Depends and Conflicts with # Merge Pre-Depends with Depends and Conflicts with
# Breaks. Britney is not interested in the "finer # Breaks. Britney is not interested in the "finer
# semantic differences" of these fields anyway. # semantic differences" of these fields anyway.
pdeps = get_field('Pre-Depends') deps = DebMirrorLikeSuiteContentLoader.merge_fields(get_field, 'Pre-Depends', 'Depends')
deps = get_field('Depends') conflicts = DebMirrorLikeSuiteContentLoader.merge_fields(get_field, 'Conflicts', 'Breaks')
if deps and pdeps:
deps = pdeps + ', ' + deps
elif pdeps:
deps = pdeps
ess = False ess = False
if get_field('Essential', 'no') == 'yes': if get_field('Essential', 'no') == 'yes':
ess = True ess = True
final_conflicts_list = []
conflicts = get_field('Conflicts')
if conflicts:
final_conflicts_list.append(conflicts)
breaks = get_field('Breaks')
if breaks:
final_conflicts_list.append(breaks)
source = pkg source = pkg
source_version = version source_version = version
# retrieve the name and the version of the source package # retrieve the name and the version of the source package
@ -272,7 +266,7 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader):
raw_arch, raw_arch,
get_field('Multi-Arch'), get_field('Multi-Arch'),
deps, deps,
', '.join(final_conflicts_list) or None, conflicts,
provides, provides,
ess, ess,
pkg_id, pkg_id,

Loading…
Cancel
Save