1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-03 17:50:11 +02:00

Improve http update check mode

This commit is contained in:
Ciaran Gultnieks 2013-10-01 15:06:02 +01:00
parent 057c1f06e4
commit 381bbb60ac
2 changed files with 30 additions and 21 deletions

View File

@ -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.
@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}.
The @code{Update Check Data} field is used to provide the url and the two
regular expressions, in the form @code{url|ex1|ex2}.
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

View File

@ -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()
vercode = "99999999"
if len(urlcode) > 0:
req = urllib2.Request(urlcode, 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"
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)