mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-18 20:50:10 +01:00
metadata: keep manually added NoSourceSince in AntiFeatures
If the metadata file contains NoSourceSince:, it is added to the collection of Anti-Features. When rewriting the .yml file, NoSourceSince should only be written into the AntiFeatures: collection if there are manual changes, e.g. the user had provided translations.
This commit is contained in:
parent
7c1d7fb4b3
commit
784bebfee9
@ -1033,6 +1033,17 @@ def post_parse_yaml_metadata(yamldata):
|
||||
}
|
||||
|
||||
|
||||
def _del_duplicated_NoSourceSince(app):
|
||||
# noqa: D403 NoSourceSince is the word.
|
||||
"""NoSourceSince gets auto-added to AntiFeatures, but can also be manually added."""
|
||||
key = 'NoSourceSince'
|
||||
if key in app:
|
||||
no_source_since = app.get(key)
|
||||
af_no_source_since = app.get('AntiFeatures', dict()).get(key)
|
||||
if af_no_source_since == {common.DEFAULT_LOCALE: no_source_since}:
|
||||
del app['AntiFeatures'][key]
|
||||
|
||||
|
||||
def write_yaml(mf, app):
|
||||
"""Write metadata in yaml format.
|
||||
|
||||
@ -1123,6 +1134,7 @@ def write_yaml(mf, app):
|
||||
|
||||
return builds
|
||||
|
||||
_del_duplicated_NoSourceSince(app)
|
||||
yaml_app = _app_to_yaml(app)
|
||||
yaml = ruamel.yaml.YAML()
|
||||
yaml.indent(mapping=4, sequence=4, offset=2)
|
||||
|
@ -1613,6 +1613,77 @@ class MetadataTest(unittest.TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
build.ndk_path()
|
||||
|
||||
def test_del_duplicated_NoSourceSince(self):
|
||||
app = {
|
||||
'AntiFeatures': {'Ads': {}, 'NoSourceSince': {DEFAULT_LOCALE: '1.0'}},
|
||||
'NoSourceSince': '1.0',
|
||||
}
|
||||
metadata._del_duplicated_NoSourceSince(app)
|
||||
self.assertEqual(app, {'AntiFeatures': {'Ads': {}}, 'NoSourceSince': '1.0'})
|
||||
|
||||
def test_check_manually_extended_NoSourceSince(self):
|
||||
app = {
|
||||
'AntiFeatures': {'NoSourceSince': {DEFAULT_LOCALE: '1.0', 'de': '1,0'}},
|
||||
'NoSourceSince': '1.0',
|
||||
}
|
||||
metadata._del_duplicated_NoSourceSince(app)
|
||||
self.assertEqual(
|
||||
app,
|
||||
{
|
||||
'AntiFeatures': {'NoSourceSince': {DEFAULT_LOCALE: '1.0', 'de': '1,0'}},
|
||||
'NoSourceSince': '1.0',
|
||||
},
|
||||
)
|
||||
|
||||
def test_make_sure_nosourcesince_does_not_get_written(self):
|
||||
appid = 'com.politedroid'
|
||||
app = metadata.read_metadata({appid: -1})[appid]
|
||||
builds = app['Builds']
|
||||
app['Builds'] = [copy.deepcopy(builds[0])]
|
||||
mf = io.StringIO()
|
||||
metadata.write_yaml(mf, app)
|
||||
mf.seek(0)
|
||||
self.maxDiff = None
|
||||
self.assertEqual(
|
||||
mf.read(),
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
AntiFeatures:
|
||||
NonFreeNet: {}
|
||||
Categories:
|
||||
- Time
|
||||
License: GPL-3.0-only
|
||||
SourceCode: https://github.com/miguelvps/PoliteDroid
|
||||
IssueTracker: https://github.com/miguelvps/PoliteDroid/issues
|
||||
|
||||
AutoName: Polite Droid
|
||||
Summary: Calendar tool
|
||||
Description: Activates silent mode during calendar events.
|
||||
|
||||
RepoType: git
|
||||
Repo: https://github.com/miguelvps/PoliteDroid.git
|
||||
|
||||
Builds:
|
||||
- versionName: '1.2'
|
||||
versionCode: 3
|
||||
commit: 6a548e4b19
|
||||
target: android-10
|
||||
antifeatures:
|
||||
KnownVuln: {}
|
||||
UpstreamNonFree: {}
|
||||
NonFreeAssets: {}
|
||||
|
||||
ArchivePolicy: 4 versions
|
||||
AutoUpdateMode: Version v%v
|
||||
UpdateCheckMode: Tags
|
||||
CurrentVersion: '1.5'
|
||||
CurrentVersionCode: 6
|
||||
|
||||
NoSourceSince: '1.5'
|
||||
"""
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class PostMetadataParseTest(unittest.TestCase):
|
||||
"""Test the functions that post process the YAML input.
|
||||
|
Loading…
Reference in New Issue
Block a user