chiark / gitweb /
Add HTTP update check mode
authorCiaran Gultnieks <ciaran@ciarang.com>
Tue, 1 Oct 2013 09:19:17 +0000 (10:19 +0100)
committerCiaran Gultnieks <ciaran@ciarang.com>
Tue, 1 Oct 2013 09:19:17 +0000 (10:19 +0100)
docs/fdroid.texi
fdroidserver/checkupdates.py
fdroidserver/common.py

index 9a29c6fbff51cf3691f504a8a454d7b0a3707089..1712fe562d74714a56a6deedcbdd9cef174d68ee 100644 (file)
@@ -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
 
index 9a5b82d0baa3ff134f41d01eb26504a37a0fe5b8..2a88a516f52b791cbb0abeba49b15a93a2984041 100644 (file)
@@ -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'
index 4ef3c990d65d3326a87aa9b889b140d09e53ae7a..ad49d4aad7b29999b9d3197d360f6800a22b21bc 100644 (file)
@@ -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')