From e9aff5f31dd1e906003938d340b0416ada6e0a2f Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Tue, 1 Oct 2013 10:19:17 +0100 Subject: [PATCH] Add HTTP update check mode --- docs/fdroid.texi | 15 ++++++++++++++ fdroidserver/checkupdates.py | 39 ++++++++++++++++++++++++++++++++++++ fdroidserver/common.py | 2 ++ 3 files changed, 56 insertions(+) diff --git a/docs/fdroid.texi b/docs/fdroid.texi index 9a29c6fb..1712fe56 100644 --- a/docs/fdroid.texi +++ b/docs/fdroid.texi @@ -1082,8 +1082,23 @@ Despite these caveats, it is the often the favourite update check mode. It currently only works for git, hg and git-svn repositories. In the case of the latter, the repo URL must encode the path to the trunk and tags or else no tags will be found. +@item +@code{HTTP} - An HTTP request is performed, and the resulting document is +scanned for two regular expressions, the first specifying the version name +and the second the version code. The expression for the version name can be +blank, but the version code must always be correct. + +The @code{Update Check Data} field is used to provide the url and the two +regular expressions, in the form @code{url|ex1|ex2}. @end itemize +@node Update Check Data +@section Update Check Data + +@cindex Update Check Data + +Used in conjunction with @code{Update Check Mode} for certain modes. + @node Auto Update Mode @section Auto Update Mode diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 9a5b82d0..2a88a516 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -33,6 +33,43 @@ from common import BuildException from common import VCSException +# Check for a new version by looking at a document retrieved via HTTP. +# The app's Update Check Data field is used to provide the information +# required. +def check_http(app): + + try: + + if not 'Update Check Data' in app: + raise Exception('Missing Update Check Data') + + url, verex, codeex = app['Update Check Data'].split('|') + + req = urllib2.Request(url, None) + resp = urllib2.urlopen(req, None, 20) + page = resp.read() + + if len(verex) > 0: + m = re.search(verex, page) + if not m: + raise Exception("No RE match for version") + version = m.group(1) + else: + version = "??" + + if len(codeex) > 0: + m = re.search(codeex, page) + if not m: + raise Exception("No RE match for version code") + vercode = m.group(1) + else: + vercode = "99999999" + + return (version, vercode) + + except Exception: + msg = "Could not complete http check for app %s due to unknown error: %s" % (app['id'], traceback.format_exc()) + return (None, msg) # Check for a new version by looking at the tags in the source repo. # Whether this can be used reliably or not depends on @@ -272,6 +309,8 @@ def main(): (version, vercode) = check_repomanifest(app, sdk_path) elif mode.startswith('RepoManifest/'): (version, vercode) = check_repomanifest(app, sdk_path, mode[13:]) + elif mode == 'HTTP': + (version, vercode) = check_http(app) elif mode == 'Static': version = None vercode = 'Checking disabled' diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 4ef3c990..ad49d4aa 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -661,6 +661,8 @@ def write_metadata(dest, app): mf.write('\n') writefield('Auto Update Mode') writefield('Update Check Mode') + if 'Update Check Data' in app: + writefield('Update Check Data') if len(app['Current Version']) > 0: writefield('Current Version') writefield('Current Version Code') -- 2.30.2