mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +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:
parent
c9aa26d89e
commit
fcb7a0feb4
@ -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
|
# 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
|
# 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
|
# update_stats = True
|
||||||
|
|
||||||
# When used with stats, this is a list of IP addresses that are ignored for
|
# When used with stats, this is a list of IP addresses that are ignored for
|
||||||
|
@ -36,6 +36,7 @@ import socket
|
|||||||
import base64
|
import base64
|
||||||
import xml.etree.ElementTree as XMLElementTree
|
import xml.etree.ElementTree as XMLElementTree
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
@ -1624,7 +1625,7 @@ class KnownApks:
|
|||||||
if len(t) == 2:
|
if len(t) == 2:
|
||||||
self.apks[t[0]] = (t[1], None)
|
self.apks[t[0]] = (t[1], None)
|
||||||
else:
|
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
|
self.changed = False
|
||||||
|
|
||||||
def writeifchanged(self):
|
def writeifchanged(self):
|
||||||
@ -1639,19 +1640,21 @@ class KnownApks:
|
|||||||
appid, added = app
|
appid, added = app
|
||||||
line = apk + ' ' + appid
|
line = apk + ' ' + appid
|
||||||
if added:
|
if added:
|
||||||
line += ' ' + time.strftime('%Y-%m-%d', added)
|
line += ' ' + added.strftime('%Y-%m-%d')
|
||||||
lst.append(line)
|
lst.append(line)
|
||||||
|
|
||||||
with open(self.path, 'w', encoding='utf8') as f:
|
with open(self.path, 'w', encoding='utf8') as f:
|
||||||
for line in sorted(lst, key=natural_key):
|
for line in sorted(lst, key=natural_key):
|
||||||
f.write(line + '\n')
|
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):
|
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 apk not in self.apks:
|
||||||
if default_date is None:
|
if default_date is None:
|
||||||
default_date = time.gmtime(time.time())
|
default_date = datetime.utcnow()
|
||||||
self.apks[apk] = (app, default_date)
|
self.apks[apk] = (app, default_date)
|
||||||
self.changed = True
|
self.changed = True
|
||||||
_, added = self.apks[apk]
|
_, added = self.apks[apk]
|
||||||
|
@ -35,7 +35,6 @@ import urllib.parse
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from xml.dom.minidom import Document
|
from xml.dom.minidom import Document
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import time
|
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
from pyasn1.error import PyAsn1Error
|
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' % (
|
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,
|
appid,
|
||||||
app.Name,
|
app.Name,
|
||||||
time.strftime('%Y-%m-%d', app.added) if app.added else '',
|
app.added.strftime('%Y-%m-%d') if app.added else '',
|
||||||
time.strftime('%Y-%m-%d', app.lastUpdated) if app.lastUpdated else '',
|
app.lastUpdated.strftime('%Y-%m-%d') if app.lastUpdated else '',
|
||||||
app.SourceCode,
|
app.SourceCode,
|
||||||
app.IssueTracker,
|
app.IssueTracker,
|
||||||
app.WebSite,
|
app.WebSite,
|
||||||
@ -566,6 +565,13 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
|
|||||||
usecache = False
|
usecache = False
|
||||||
if name in apkcache:
|
if name in apkcache:
|
||||||
repo_file = apkcache[name]
|
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:
|
if repo_file['sha256'] == shasum:
|
||||||
logging.debug("Reading " + name + " from cache")
|
logging.debug("Reading " + name + " from cache")
|
||||||
usecache = True
|
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))
|
os.path.join(get_icon_dir(repodir, '0'), iconfilename))
|
||||||
|
|
||||||
if use_date_from_apk and manifest.date_time[1] != 0:
|
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:
|
else:
|
||||||
default_date_param = None
|
default_date_param = None
|
||||||
|
|
||||||
@ -1258,9 +1264,9 @@ def make_index_v0(apps, apks, repodir, repodict):
|
|||||||
|
|
||||||
addElement('id', app.id, doc, apel)
|
addElement('id', app.id, doc, apel)
|
||||||
if app.added:
|
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:
|
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('name', app.Name, doc, apel)
|
||||||
addElement('summary', app.Summary, doc, apel)
|
addElement('summary', app.Summary, doc, apel)
|
||||||
if app.icon:
|
if app.icon:
|
||||||
@ -1356,7 +1362,7 @@ def make_index_v0(apps, apks, repodir, repodict):
|
|||||||
addElementIfInApk('obbPatchFileSha256', apk,
|
addElementIfInApk('obbPatchFileSha256', apk,
|
||||||
'obbPatchFileSha256', doc, apkel)
|
'obbPatchFileSha256', doc, apkel)
|
||||||
if 'added' in apk:
|
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
|
if file_extension == 'apk': # sig is required for APKs, but only APKs
|
||||||
addElement('sig', apk['sig'], doc, apkel)
|
addElement('sig', apk['sig'], doc, apkel)
|
||||||
|
Loading…
Reference in New Issue
Block a user