use OrderedDict for localization data in index-v1

This commit is contained in:
Michael Pöhn 2017-09-04 02:23:17 +02:00
parent 26192a00e2
commit 89d9d0c45b
2 changed files with 20 additions and 4 deletions

View File

@ -169,6 +169,11 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
# Java prefers milliseconds
# we also need to accound for time zone/daylight saving time
return int(calendar.timegm(obj.timetuple()) * 1000)
if isinstance(obj, dict):
d = collections.OrderedDict()
for key in sorted(obj.keys()):
d[key] = obj[key]
return d
raise TypeError(repr(obj) + " is not JSON serializable")
output = collections.OrderedDict()
@ -208,6 +213,17 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
k = k[:1].lower() + k[1:]
d[k] = v
# establish sort order in localized dicts
for app in output['apps']:
localized = app.get('localized')
if localized:
lordered = collections.OrderedDict()
for lkey, lvalue in sorted(localized.items()):
lordered[lkey] = collections.OrderedDict()
for ikey, iname in sorted(lvalue.items()):
lordered[lkey][ikey] = iname
app['localized'] = lordered
output_packages = collections.OrderedDict()
output['packages'] = output_packages
for package in packages:

View File

@ -133,12 +133,12 @@
"lastUpdated": 1466640000000,
"localized": {
"en-US": {
"name": "title\n",
"summary": "short description\n",
"video": "video\n",
"description": "full description\n",
"featureGraphic": "featureGraphic.png",
"icon": "icon.png"
"icon": "icon.png",
"name": "title\n",
"summary": "short description\n",
"video": "video\n"
}
}
}