mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 15:02:51 +03:00
Merge branch 'dump_internal_metadata_format' into 'master'
Cleanup tests/dump_internal_metadata_format.py See merge request fdroid/fdroidserver!1184
This commit is contained in:
commit
a3b7ba4eed
2 changed files with 23 additions and 59 deletions
|
@ -248,6 +248,7 @@ black:
|
||||||
setup.py
|
setup.py
|
||||||
tests/build.TestCase
|
tests/build.TestCase
|
||||||
tests/deploy.TestCase
|
tests/deploy.TestCase
|
||||||
|
tests/dump_internal_metadata_format.py
|
||||||
tests/exception.TestCase
|
tests/exception.TestCase
|
||||||
tests/import_subcommand.TestCase
|
tests/import_subcommand.TestCase
|
||||||
tests/init.TestCase
|
tests/init.TestCase
|
||||||
|
|
|
@ -9,27 +9,28 @@
|
||||||
# The idea is to test changes using all of the files in
|
# The idea is to test changes using all of the files in
|
||||||
# fdroiddata.git. To run it, do:
|
# fdroiddata.git. To run it, do:
|
||||||
#
|
#
|
||||||
# cd fdroidserver/tests
|
# cd fdroidserver
|
||||||
# cp dump_internal_metadata_format.py dump.py # since this isn't in old commits
|
# git checkout <latest tag>
|
||||||
# git checkout 0.7.0 # or any old commit of your choosing
|
# cd ../fdroiddata
|
||||||
# cd ../../fdroiddata
|
# ../fdroidserver/tests/dump_internal_metadata_format.py
|
||||||
# ../fdroidserver/tests/dump.py
|
|
||||||
# mv metadata/dump metadata/dump_0.7.0
|
|
||||||
# cd ../fdroidserver
|
# cd ../fdroidserver
|
||||||
# git checkout master
|
# git checkout master
|
||||||
# cd ../fdroiddata
|
# cd ../fdroiddata
|
||||||
# ../fdroidserver/tests/dump.py
|
# ../fdroidserver/tests/dump_internal_metadata_format.py
|
||||||
# meld metadata/dump_0.7.0 metadata/dump_0.7.0-179-ge85486a/
|
# diff -uw metadata/dump_*
|
||||||
|
|
||||||
import git
|
|
||||||
import inspect
|
import inspect
|
||||||
import optparse
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
import git
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
localmodule = os.path.realpath(
|
localmodule = os.path.realpath(
|
||||||
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
|
||||||
|
)
|
||||||
if localmodule not in sys.path:
|
if localmodule not in sys.path:
|
||||||
sys.path.insert(0, localmodule)
|
sys.path.insert(0, localmodule)
|
||||||
|
|
||||||
|
@ -38,47 +39,21 @@ import fdroidserver.metadata # noqa
|
||||||
|
|
||||||
|
|
||||||
def _build_yaml_representer(dumper, data):
|
def _build_yaml_representer(dumper, data):
|
||||||
'''Creates a YAML representation of a Build instance'''
|
"""Create a YAML representation of a Build instance."""
|
||||||
if hasattr(data, 'append_flag'):
|
return dumper.represent_dict(data)
|
||||||
# for 0.7.0 and earlier, before https://gitlab.com/fdroid/fdroidserver/merge_requests/210
|
|
||||||
del(data._modified)
|
|
||||||
readdict = data.__dict__
|
|
||||||
else:
|
|
||||||
readdict = data
|
|
||||||
|
|
||||||
# these key names were all renamed in
|
|
||||||
# https://gitlab.com/fdroid/fdroidserver/merge_requests/210
|
|
||||||
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
|
|
||||||
else:
|
|
||||||
output[k] = v
|
|
||||||
|
|
||||||
return dumper.represent_dict(output)
|
|
||||||
|
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
parser = ArgumentParser()
|
||||||
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
fdroidserver.common.setup_global_opts(parser)
|
||||||
help="Spew out even more information than normal")
|
fdroidserver.metadata.add_metadata_arguments(parser)
|
||||||
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
options = parser.parse_args()
|
||||||
|
fdroidserver.metadata.warnings_action = options.W
|
||||||
|
fdroidserver.common.read_config(None)
|
||||||
|
|
||||||
if not os.path.isdir('metadata'):
|
if not os.path.isdir('metadata'):
|
||||||
print("This script must be run in an F-Droid data folder with a 'metadata' subdir!")
|
print("This script must be run in an F-Droid data folder with a 'metadata' subdir!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# these need to be set to prevent code running on None, only
|
|
||||||
# 'accepted_formats' is actually used in metadata.py
|
|
||||||
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)
|
repo = git.Repo(localmodule)
|
||||||
savedir = os.path.join('metadata', 'dump_' + repo.git.describe())
|
savedir = os.path.join('metadata', 'dump_' + repo.git.describe())
|
||||||
if not os.path.isdir(savedir):
|
if not os.path.isdir(savedir):
|
||||||
|
@ -87,20 +62,8 @@ if not os.path.isdir(savedir):
|
||||||
apps = fdroidserver.metadata.read_metadata()
|
apps = fdroidserver.metadata.read_metadata()
|
||||||
for appid, app in apps.items():
|
for appid, app in apps.items():
|
||||||
savepath = os.path.join(savedir, appid + '.yaml')
|
savepath = os.path.join(savedir, appid + '.yaml')
|
||||||
if hasattr(app, 'attr_to_field'):
|
|
||||||
# for 0.7.0 and earlier, before https://gitlab.com/fdroid/fdroidserver/merge_requests/210
|
|
||||||
app.__dict__['lastUpdated'] = app.__dict__['lastupdated']
|
|
||||||
del(app.__dict__['lastupdated'])
|
|
||||||
del(app._modified)
|
|
||||||
frommeta = dict(app.__dict__)
|
|
||||||
else:
|
|
||||||
frommeta = dict(app)
|
frommeta = dict(app)
|
||||||
|
|
||||||
with open(savepath, 'w') as f:
|
with open(savepath, "w", encoding="utf-8") as f:
|
||||||
yaml.add_representer(fdroidserver.metadata.Build, _build_yaml_representer)
|
yaml.add_representer(fdroidserver.metadata.Build, _build_yaml_representer)
|
||||||
yaml.dump(frommeta, f, default_flow_style=False)
|
yaml.dump(frommeta, f, default_flow_style=False)
|
||||||
|
|
||||||
# if appid == 'at.tomtasche.reader':
|
|
||||||
# import pprint
|
|
||||||
# pprint.pprint(app)
|
|
||||||
# sys.exit(1)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue