update: calculate added date for an app over all apks

This was accidentally changed in !756 because the functionality was
hidden in `apply_info_from_latest_apk` which is a less than stellar name
for something that also applies infos from app->apk and in this case did
apply info from *oldest* apk->app.
So instead move that into a separate step.

Note: This restores the previous behaviour. There's discussion in #801
on further changes to make the added date also work for repos which
don't keep an archive at all.
This commit is contained in:
Marcus Hoffmann 2020-06-29 21:45:22 +02:00
parent a301a1ba93
commit a656be82ae
2 changed files with 26 additions and 7 deletions

View File

@ -134,7 +134,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
return sorted(list(obj))
if isinstance(obj, datetime):
# Java prefers milliseconds
# we also need to accound for time zone/daylight saving time
# we also need to account for time zone/daylight saving time
return int(calendar.timegm(obj.timetuple()) * 1000)
if isinstance(obj, dict):
d = collections.OrderedDict()

View File

@ -1974,12 +1974,6 @@ def apply_info_from_latest_apk(apps, apks):
if app.NoSourceSince:
apk['antiFeatures'].add('NoSourceSince')
if 'added' in apk:
if not app.added or apk['added'] < app.added:
app.added = apk['added']
if not app.lastUpdated or apk['added'] > app.lastUpdated:
app.lastUpdated = apk['added']
if not app.added:
logging.debug("Don't know when " + appid + " was added")
if not app.lastUpdated:
@ -2166,6 +2160,27 @@ def create_metadata_from_template(apk):
logging.info(_("Generated skeleton metadata for {appid}").format(appid=apk['packageName']))
def read_added_date_from_all_apks(apps, apks):
"""
Added dates come from the stats/known_apks.txt file but are
read when scanning apks and thus need to be applied form apk
level to app level for _all_ apps and not only form non-archived
ones
TODO: read the added dates directly from known_apks.txt instead of
going through apks that way it also works for for repos that
don't keep an archive of apks.
"""
for appid, app in apps.items():
for apk in apks:
if apk['packageName'] == appid:
if 'added' in apk:
if not app.added or apk['added'] < app.added:
app.added = apk['added']
if not app.lastUpdated or apk['added'] > app.lastUpdated:
app.lastUpdated = apk['added']
def read_names_from_apks(apps, apks):
"""This is a stripped down copy of apply_info_from_latest_apk that only parses app names"""
for appid, app in apps.items():
@ -2384,6 +2399,10 @@ def main():
# This will be done again (as part of apply_info_from_latest_apk) for repo and archive
# separately later on, but it's fairly cheap anyway.
read_names_from_apks(apps, apks + archapks)
# The added date currently comes from the oldest apk which might be in the archive.
# So we need this populated at app level before continuing with only processing /repo
# or /archive
read_added_date_from_all_apks(apps, apks + archapks)
if len(repodirs) > 1:
archive_old_apks(apps, apks, archapks, repodirs[0], repodirs[1], config['archive_older'])