From: Ciaran Gultnieks Date: Tue, 1 Oct 2013 14:06:02 +0000 (+0100) Subject: Improve http update check mode X-Git-Tag: 0.1~388 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=381bbb60ace34235b65991f204f59987c4a2b01d;p=fdroidserver.git Improve http update check mode --- diff --git a/docs/fdroid.texi b/docs/fdroid.texi index 771b5d9f..3571a162 100644 --- a/docs/fdroid.texi +++ b/docs/fdroid.texi @@ -1084,13 +1084,19 @@ 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}. +@code{HTTP} - HTTP requests are used to determine the current version code and +version name. This is controlled by the @code{Update Check Data} field, which +is of the form @code{urlcode|excode|urlver|exver}. + +Firstly, if @code{urlcode} is non-empty, the document from that URL is +retrieved, and matched against the regular expression @code{excode}, with the +first group becoming the version code. + +Secondly, if @code{urlver} is non-empty, the document from that URL is +retrieved, and matched against the regular expression @code{exver}, with the +first group becoming the version name. The @code{urlver} field can be set to +simply '.' which says to use the same document returned for the version code +again, rather than retrieving a different one. @end itemize @node Update Check Data diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 2a88a516..53a29c75 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -43,27 +43,30 @@ def check_http(app): if not 'Update Check Data' in app: raise Exception('Missing Update Check Data') - url, verex, codeex = app['Update Check Data'].split('|') + urlcode, codeex, urlver, verex = 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 = "??" + vercode = "99999999" + if len(urlcode) > 0: + req = urllib2.Request(urlcode, None) + resp = urllib2.urlopen(req, None, 20) + page = resp.read() - 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" + + version = "??" + if len(urlver) > 0: + if urlver != '.': + req = urllib2.Request(urlver, None) + resp = urllib2.urlopen(req, None, 20) + page = resp.read() + + m = re.search(verex, page) + if not m: + raise Exception("No RE match for version") + version = m.group(1) return (version, vercode)