1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 17:00:12 +01:00

Cache apk info to speed up updates

This commit is contained in:
Ciaran Gultnieks 2012-09-03 11:48:18 +01:00
parent a7a966a837
commit 2f5417e589

View File

@ -25,6 +25,7 @@ import subprocess
import re import re
import zipfile import zipfile
import hashlib import hashlib
import pickle
from xml.dom.minidom import Document from xml.dom.minidom import Document
from optparse import OptionParser from optparse import OptionParser
import time import time
@ -217,7 +218,15 @@ def main():
# Read known apks data (will be updated and written back when we've finished) # Read known apks data (will be updated and written back when we've finished)
knownapks = common.KnownApks() knownapks = common.KnownApks()
# Gather information about all the apk files in the repo directory... # Gather information about all the apk files in the repo directory, using
# cached data if possible.
apkcachefile = os.path.join('tmp', 'apkcache')
if os.path.exists(apkcachefile):
with open(apkcachefile, 'rb') as cf:
apkcache = pickle.load(cf)
else:
apkcache = {}
cachechanged = False
apks = [] apks = []
for apkfile in glob.glob(os.path.join('repo','*.apk')): for apkfile in glob.glob(os.path.join('repo','*.apk')):
@ -227,6 +236,13 @@ def main():
sys.exit(1) sys.exit(1)
srcfilename = apkfilename[:-4] + "_src.tar.gz" srcfilename = apkfilename[:-4] + "_src.tar.gz"
if apkcache.has_key(apkfilename):
if options.verbose:
print "Reading " + apkfilename + " from cache"
thisinfo = apkcache[apkfilename]
else:
if not options.quiet: if not options.quiet:
print "Processing " + apkfilename print "Processing " + apkfilename
thisinfo = {} thisinfo = {}
@ -288,7 +304,7 @@ def main():
# Calculate the md5 and sha256... # Calculate the md5 and sha256...
m = hashlib.md5() m = hashlib.md5()
sha = hashlib.sha256() sha = hashlib.sha256()
f = open(apkfile, 'rb') with open(apkfile, 'rb') as f:
while True: while True:
t = f.read(1024) t = f.read(1024)
if len(t) == 0: if len(t) == 0:
@ -297,7 +313,6 @@ def main():
sha.update(t) sha.update(t)
thisinfo['md5'] = m.hexdigest() thisinfo['md5'] = m.hexdigest()
thisinfo['sha256'] = sha.hexdigest() thisinfo['sha256'] = sha.hexdigest()
f.close()
# Get the signature (or md5 of, to be precise)... # Get the signature (or md5 of, to be precise)...
p = subprocess.Popen(['java', 'getsig', p = subprocess.Popen(['java', 'getsig',
@ -331,8 +346,15 @@ def main():
if added: if added:
thisinfo['added'] = added thisinfo['added'] = added
apkcache[apkfilename] = thisinfo
cachechanged = True
apks.append(thisinfo) apks.append(thisinfo)
if cachechanged:
with open(apkcachefile, 'wb') as cf:
pickle.dump(apkcache, cf)
# Some information from the apks needs to be applied up to the application # Some information from the apks needs to be applied up to the application
# level. When doing this, we use the info from the most recent version's apk. # level. When doing this, we use the info from the most recent version's apk.
# We deal with figuring out when the app was added and last updated at the # We deal with figuring out when the app was added and last updated at the