From 0099c34d934c61882759cb48df1c62acdc9e1117 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 16 Dec 2018 10:50:35 +0000 Subject: [PATCH] Refactor _read_binaries to reduce its complexity a bit Signed-off-by: Niels Thykier --- britney2/inputs/suiteloader.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/britney2/inputs/suiteloader.py b/britney2/inputs/suiteloader.py index 9fa15af..4c56222 100644 --- a/britney2/inputs/suiteloader.py +++ b/britney2/inputs/suiteloader.py @@ -183,6 +183,12 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader): 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): self.logger.info("Loading binary packages from %s", filename) @@ -226,25 +232,13 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader): # Merge Pre-Depends with Depends and Conflicts with # Breaks. Britney is not interested in the "finer # semantic differences" of these fields anyway. - pdeps = get_field('Pre-Depends') - deps = get_field('Depends') - if deps and pdeps: - deps = pdeps + ', ' + deps - elif pdeps: - deps = pdeps + deps = DebMirrorLikeSuiteContentLoader.merge_fields(get_field, 'Pre-Depends', 'Depends') + conflicts = DebMirrorLikeSuiteContentLoader.merge_fields(get_field, 'Conflicts', 'Breaks') ess = False if get_field('Essential', 'no') == 'yes': 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_version = version # retrieve the name and the version of the source package @@ -272,7 +266,7 @@ class DebMirrorLikeSuiteContentLoader(SuiteContentLoader): raw_arch, get_field('Multi-Arch'), deps, - ', '.join(final_conflicts_list) or None, + conflicts, provides, ess, pkg_id,