You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.5 KiB

#!/usr/bin/env python3
# Test that the parsing of the .yml metadata format didn't change from last
# released version. This uses the commit ID of the release tags,
# rather than the release tag itself so that contributor forks do not
# need to include the tags in them for this test to work.
# This is for running manual tests when changing the metadata format.
# The idea is to test changes using all of the files in
# fdroiddata.git. To run it, do:
# cd fdroidserver/tests
# cp # since this isn't in old commits
# git checkout 0.7.0 # or any old commit of your choosing
# cd ../../fdroiddata
# ../fdroidserver/tests/
# mv metadata/dump metadata/dump_0.7.0
# cd ../fdroidserver
# git checkout master
# cd ../fdroiddata
# ../fdroidserver/tests/
# meld metadata/dump_0.7.0 metadata/dump_0.7.0-179-ge85486a/
import git
import inspect
import optparse
import os
import sys
import yaml
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
if localmodule not in sys.path:
sys.path.insert(0, localmodule)
import fdroidserver.common # noqa
import fdroidserver.metadata # noqa
def _build_yaml_representer(dumper, data):
'''Creates a YAML representation of a Build instance'''
if hasattr(data, 'append_flag'):
# for 0.7.0 and earlier, before
readdict = data.__dict__
readdict = data
# these key names were all renamed in
output = dict()
for k, v in readdict.items():
if k == 'vercode':
output['versionCode'] = v
elif k == 'version':
output['versionName'] = v
elif k == 'update':
output['androidupdate'] = v
output[k] = v
return dumper.represent_dict(output)
parser = optparse.OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
if not os.path.isdir('metadata'):
print("This script must be run in an F-Droid data folder with a 'metadata' subdir!")
# these need to be set to prevent code running on None, only
# 'accepted_formats' is actually used in
config = dict()
config['sdk_path'] = os.getenv('ANDROID_HOME') or '/opt/android-sdk'
config['ndk_paths'] = dict()
config['accepted_formats'] = ['yml']
fdroidserver.common.config = config
repo = git.Repo(localmodule)
savedir = os.path.join('metadata', 'dump_' + repo.git.describe())
if not os.path.isdir(savedir):
apps = fdroidserver.metadata.read_metadata(xref=True)
for appid, app in apps.items():
savepath = os.path.join(savedir, appid + '.yaml')
if hasattr(app, 'attr_to_field'):
# for 0.7.0 and earlier, before
app.__dict__['lastUpdated'] = app.__dict__['lastupdated']
frommeta = dict(app.__dict__)
frommeta = dict(app)
with open(savepath, 'w') as f:
yaml.add_representer(fdroidserver.metadata.Build, _build_yaml_representer)
yaml.dump(frommeta, f, default_flow_style=False)
# if appid == 'at.tomtasche.reader':
# import pprint
# pprint.pprint(app)
# sys.exit(1)