From 8e5232076f049170ce9698a2739c2d9f3430997e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Mon, 29 Jul 2019 17:39:51 +0200 Subject: [PATCH] do not delete yml metadata when raumel not installed --- fdroidserver/metadata.py | 13 +++++++++---- tests/rewritemeta.TestCase | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 33c2f5af..d34b824e 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -27,6 +27,7 @@ import logging import textwrap import io import yaml +import importlib from collections import OrderedDict import fdroidserver.common @@ -1584,11 +1585,15 @@ def write_metadata(metadatapath, app): warn_or_exception(_('Cannot write "{path}", not an accepted format, use: {formats}') .format(path=metadatapath, formats=', '.join(accepted))) - with open(metadatapath, 'w') as mf: - if ext == 'txt': + if ext == 'txt': + with open(metadatapath, 'w') as mf: return write_txt(mf, app) - elif ext == 'yml': - return write_yaml(mf, app) + elif ext == 'yml': + if importlib.util.find_spec('ruamel.yaml'): + with open(metadatapath, 'w') as mf: + return write_yaml(mf, app) + else: + raise FDroidException('ruamel.yaml not installed, can not write metadata.') warn_or_exception(_('Unknown metadata format: %s') % metadatapath) diff --git a/tests/rewritemeta.TestCase b/tests/rewritemeta.TestCase index 128c3d9d..664f3c78 100755 --- a/tests/rewritemeta.TestCase +++ b/tests/rewritemeta.TestCase @@ -110,8 +110,8 @@ class RewriteMetaTest(unittest.TestCase): with open('metadata/a.txt', 'w') as f: f.write('Auto Name:a') - def boom(mf, app): - raise FDroidException() + def boom(*args): + raise FDroidException(' '.join((str(x) for x in args))) with mock.patch('fdroidserver.metadata.write_yaml', boom): with self.assertRaises(FDroidException): @@ -128,10 +128,10 @@ class RewriteMetaTest(unittest.TestCase): with open('metadata/a.yml', 'w') as f: f.write('AutoName: a') - def boom(mf, app): - raise FDroidException() + def boom(*args): + raise FDroidException(' '.join((str(x) for x in args))) - with mock.patch('fdroidserver.metadata.write_yaml', boom): + with mock.patch('importlib.util.find_spec', boom): with self.assertRaises(FDroidException): rewritemeta.main()