1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-07-04 16:30:12 +02:00

fdroid update uses datetime instances for timestamps

Using datetime instances as the internal format makes it much easier to
convert between the formats needed for index.xml and index-v1.  apkcache
still uses time tuples and known_apks.txt still uses the ISO date.
This commit is contained in:
Hans-Christoph Steiner 2016-11-28 21:10:58 +01:00
parent c9aa26d89e
commit fcb7a0feb4
3 changed files with 23 additions and 13 deletions

View File

@ -247,7 +247,8 @@ The repository of older versions of applications from the main demo repository.
# Only set this to true when running a repository where you want to generate
# stats, and only then on the master build servers, not a development
# machine.
# machine. If you want to keep the "added" and "last updated" dates for each
# app and APK in your repo, then you should enable this.
# update_stats = True
# When used with stats, this is a list of IP addresses that are ignored for

View File

@ -36,6 +36,7 @@ import socket
import base64
import xml.etree.ElementTree as XMLElementTree
from datetime import datetime
from distutils.version import LooseVersion
from queue import Queue
from zipfile import ZipFile
@ -1624,7 +1625,7 @@ class KnownApks:
if len(t) == 2:
self.apks[t[0]] = (t[1], None)
else:
self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d'))
self.apks[t[0]] = (t[1], datetime.strptime(t[2], '%Y-%m-%d'))
self.changed = False
def writeifchanged(self):
@ -1639,19 +1640,21 @@ class KnownApks:
appid, added = app
line = apk + ' ' + appid
if added:
line += ' ' + time.strftime('%Y-%m-%d', added)
line += ' ' + added.strftime('%Y-%m-%d')
lst.append(line)
with open(self.path, 'w', encoding='utf8') as f:
for line in sorted(lst, key=natural_key):
f.write(line + '\n')
# Record an apk (if it's new, otherwise does nothing)
# Returns the date it was added.
def recordapk(self, apk, app, default_date=None):
'''
Record an apk (if it's new, otherwise does nothing)
Returns the date it was added as a datetime instance
'''
if apk not in self.apks:
if default_date is None:
default_date = time.gmtime(time.time())
default_date = datetime.utcnow()
self.apks[apk] = (app, default_date)
self.changed = True
_, added = self.apks[apk]

View File

@ -35,7 +35,6 @@ import urllib.parse
from datetime import datetime, timedelta
from xml.dom.minidom import Document
from argparse import ArgumentParser
import time
import collections
from pyasn1.error import PyAsn1Error
@ -117,8 +116,8 @@ def update_wiki(apps, sortedids, apks):
wikidata += '{{App|id=%s|name=%s|added=%s|lastupdated=%s|source=%s|tracker=%s|web=%s|changelog=%s|donate=%s|flattr=%s|bitcoin=%s|litecoin=%s|license=%s|root=%s|author=%s|email=%s}}\n' % (
appid,
app.Name,
time.strftime('%Y-%m-%d', app.added) if app.added else '',
time.strftime('%Y-%m-%d', app.lastUpdated) if app.lastUpdated else '',
app.added.strftime('%Y-%m-%d') if app.added else '',
app.lastUpdated.strftime('%Y-%m-%d') if app.lastUpdated else '',
app.SourceCode,
app.IssueTracker,
app.WebSite,
@ -566,6 +565,13 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
usecache = False
if name in apkcache:
repo_file = apkcache[name]
# added time is cached as tuple but used here as datetime instance
if 'added' in repo_file:
a = repo_file['added']
if isinstance(a, datetime):
repo_file['added'] = a
else:
repo_file['added'] = datetime(*a[:6])
if repo_file['sha256'] == shasum:
logging.debug("Reading " + name + " from cache")
usecache = True
@ -926,7 +932,7 @@ def scan_apks(apkcache, repodir, knownapks, use_date_from_apk=False):
os.path.join(get_icon_dir(repodir, '0'), iconfilename))
if use_date_from_apk and manifest.date_time[1] != 0:
default_date_param = datetime(*manifest.date_time).utctimetuple()
default_date_param = datetime(*manifest.date_time)
else:
default_date_param = None
@ -1258,9 +1264,9 @@ def make_index_v0(apps, apks, repodir, repodict):
addElement('id', app.id, doc, apel)
if app.added:
addElement('added', time.strftime('%Y-%m-%d', app.added), doc, apel)
addElement('added', app.added.strftime('%Y-%m-%d'), doc, apel)
if app.lastUpdated:
addElement('lastupdated', time.strftime('%Y-%m-%d', app.lastUpdated), doc, apel)
addElement('lastupdated', app.lastUpdated.strftime('%Y-%m-%d'), doc, apel)
addElement('name', app.Name, doc, apel)
addElement('summary', app.Summary, doc, apel)
if app.icon:
@ -1356,7 +1362,7 @@ def make_index_v0(apps, apks, repodir, repodict):
addElementIfInApk('obbPatchFileSha256', apk,
'obbPatchFileSha256', doc, apkel)
if 'added' in apk:
addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel)
addElement('added', apk['added'].strftime('%Y-%m-%d'), doc, apkel)
if file_extension == 'apk': # sig is required for APKs, but only APKs
addElement('sig', apk['sig'], doc, apkel)