From c9d45ecb2b20301729ad74da99f1df85d8450ecb Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Wed, 17 Jun 2020 10:39:33 +0100 Subject: [PATCH] Support writing excuses YAML to xz and gz files --- britney2/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/britney2/utils.py b/britney2/utils.py index dfe18e4..afb07dd 100644 --- a/britney2/utils.py +++ b/britney2/utils.py @@ -311,7 +311,14 @@ def write_excuses(excuses, dest_file, output_format="yaml"): excuselist = sorted(excuses.values(), key=lambda x: x.sortkey()) if output_format == "yaml": os.makedirs(os.path.dirname(dest_file), exist_ok=True) - with open(dest_file, 'w', encoding='utf-8') as f: + opener = open + if dest_file.endswith('.xz'): + import lzma + opener = lzma.open + elif dest_file.endswith('.gz'): + import gzip + opener = gzip.open + with opener(dest_file, 'wt', encoding='utf-8') as f: edatalist = [e.excusedata(excuses) for e in excuselist] excusesdata = { 'sources': edatalist,