From b429d4871ea964ce74c5cc3e2112542323b46fa4 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 9 Mar 2014 10:23:41 +0100 Subject: [PATCH] Factor write_sources into its own function Signed-off-by: Niels Thykier --- britney.py | 12 +++--------- britney_util.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/britney.py b/britney.py index 40f808a..9a6d509 100755 --- a/britney.py +++ b/britney.py @@ -216,7 +216,7 @@ from britney_util import (old_libraries_format, same_source, undo_changes, register_reverses, compute_reverse_tree, read_nuninst, write_nuninst, write_heidi, eval_uninst, newly_uninst, make_migrationitem, - write_excuses, write_heidi_delta) + write_excuses, write_heidi_delta, write_sources) from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC, SOURCE, SOURCEVER, ARCHITECTURE, DEPENDS, CONFLICTS, PROVIDES, RDEPENDS, RCONFLICTS, MULTIARCH, ESSENTIAL) @@ -911,14 +911,8 @@ class Britney(object): f.close() filename = os.path.join(basedir, 'Sources') - f = open(filename, 'w') - for src in sources: - output = "Package: %s\n" % src - for key, k in ((VERSION, 'Version'), (SECTION, 'Section'), (MAINTAINER, 'Maintainer')): - if not sources[src][key]: continue - output += (k + ": " + sources[src][key] + "\n") - f.write(output + "\n") - f.close() + write_sources(sources, filename) + # Utility methods for package analysis # ------------------------------------ diff --git a/britney_util.py b/britney_util.py index b23f7cf..b8327b1 100644 --- a/britney_util.py +++ b/britney_util.py @@ -33,7 +33,7 @@ from migrationitem import MigrationItem, UnversionnedMigrationItem from consts import (VERSION, BINARIES, PROVIDES, DEPENDS, CONFLICTS, RDEPENDS, RCONFLICTS, ARCHITECTURE, SECTION, - SOURCE, SOURCEVER) + SOURCE, SOURCEVER, MAINTAINER) binnmu_re = re.compile(r'^(.*)\+b\d+$') @@ -475,3 +475,21 @@ def write_excuses(excuses, dest_file, output_format="yaml"): else: raise ValueError('Output format must be either "yaml or "legacy-html"') + +def write_sources(sources_s, filename): + """Write a sources file from Britney's state for a given suite + + Britney discards fields she does not care about, so the resulting + file omitts a lot of regular fields. + """ + + key_pairs = ((VERSION, 'Version'), (SECTION, 'Section'), + (MAINTAINER, 'Maintainer')) + + with open(filename, 'w') as f: + for src in sources_s: + src_data = sources_s[src] + output = "Package: %s\n" % src + output += "\n".join(k + ": "+ src_data[key] + for key, k in key_pairs if src_data[key]) + f.write(output + "\n\n")