Various minor improvements to update checking

This commit is contained in:
Ciaran Gultnieks 2013-02-11 15:24:01 +00:00
parent 5829d455f9
commit 80808133d4

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# checkupdates.py - part of the FDroid server tools # checkupdates.py - part of the FDroid server tools
# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com # Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -21,8 +21,9 @@ import sys
import os import os
import shutil import shutil
import re import re
import urllib import urllib2
import time import time
import subprocess
from optparse import OptionParser from optparse import OptionParser
import traceback import traceback
import HTMLParser import HTMLParser
@ -68,7 +69,7 @@ def check_tags(app, sdk_path):
version, vercode, package = common.parse_androidmanifest(manifest) version, vercode, package = common.parse_androidmanifest(manifest)
if package and package == app['id'] and version and vercode: if package and package == app['id'] and version and vercode:
if int(vercode) > int(hcode): if int(vercode) > int(hcode):
hcode = vercode hcode = str(int(vercode))
hver = version hver = version
if hver: if hver:
@ -122,7 +123,7 @@ def check_repomanifest(app, sdk_path):
if not vercode: if not vercode:
return (None,"Couldn't find latest version code") return (None,"Couldn't find latest version code")
return (version, vercode) return (version, str(int(vercode)))
except BuildException as be: except BuildException as be:
msg = "Could not scan app %s due to BuildException: %s" % (app['id'], be) msg = "Could not scan app %s due to BuildException: %s" % (app['id'], be)
@ -139,14 +140,21 @@ def check_repomanifest(app, sdk_path):
# Returns (None, "a message") if this didn't work, or (version, vercode) for # Returns (None, "a message") if this didn't work, or (version, vercode) for
# the details of the current version. # the details of the current version.
def check_market(app): def check_market(app):
time.sleep(10) time.sleep(15)
url = 'http://market.android.com/details?id=' + app['id'] url = 'https://play.google.com/store/apps/details?id=' + app['id']
req = urllib.urlopen(url) headers = {'User-Agent' : 'Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0'}
if req.getcode() == 404: req = urllib2.Request(url, None, headers)
return (None, 'Not in market') try:
elif req.getcode() != 200: resp = urllib2.urlopen(req)
return (None, 'Return code ' + str(req.getcode())) except urllib2.HTTPError, e:
page = req.read() if e.code == 404:
return (None, 'Not in market')
elif e.code == 503:
print "Whoops"
sys.exit(1)
else:
return (None, 'Failed with HTTP status' + str(req.getcode()))
page = resp.read()
version = None version = None
vercode = None vercode = None
@ -167,7 +175,7 @@ def check_market(app):
return (None, "Couldn't find version code") return (None, "Couldn't find version code")
if not version: if not version:
return (None, "Couldn't find version") return (None, "Couldn't find version")
return (version, vercode) return (version, str(int(vercode)))
@ -184,6 +192,8 @@ def main():
help="Check only the specified package") help="Check only the specified package")
parser.add_option("--auto", action="store_true", default=False, parser.add_option("--auto", action="store_true", default=False,
help="Process auto-updates") help="Process auto-updates")
parser.add_option("--commit", action="store_true", default=False,
help="Commit changes")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
# Get all apps... # Get all apps...
@ -200,6 +210,7 @@ def main():
print "Processing " + app['id'] + '...' print "Processing " + app['id'] + '...'
writeit = False writeit = False
logmsg = None
mode = app['Update Check Mode'] mode = app['Update Check Mode']
if mode == 'Market': if mode == 'Market':
@ -224,6 +235,7 @@ def main():
app['Current Version'] = version app['Current Version'] = version
app['Current Version Code'] = str(int(vercode)) app['Current Version Code'] = str(int(vercode))
writeit = True writeit = True
logmsg = "Update current version of " + app['id'] + " to " + version
if options.auto: if options.auto:
mode = app['Auto Update Mode'] mode = app['Auto Update Mode']
@ -255,12 +267,20 @@ def main():
newbuild['commit'] = commit newbuild['commit'] = commit
app['builds'].append(newbuild) app['builds'].append(newbuild)
writeit = True writeit = True
logmsg = "Update " + app['id'] + " to " + newbuild['version']
else: else:
print 'Invalid auto update mode' print 'Invalid auto update mode'
if writeit: if writeit:
metafile = os.path.join('metadata', app['id'] + '.txt') metafile = os.path.join('metadata', app['id'] + '.txt')
common.write_metadata(metafile, app) common.write_metadata(metafile, app)
if options.commit:
if subprocess.call("git add " + metafile, shell=True) != 0:
print "Git add failed"
sys.exit(1)
if subprocess.call('git commit -m \"' + logmsg + '\"', shell=True) != 0:
print "Git commit failed"
sys.exit(1)
print "Finished." print "Finished."