Use GitHub releases API for update checks.
This commit is contained in:
parent
a41574e31a
commit
81827f83bc
1 changed files with 9 additions and 15 deletions
|
@ -4,19 +4,13 @@ Function to check for updates.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import dosagelib
|
import dosagelib
|
||||||
|
from dosagelib import configuration
|
||||||
from .util import urlopen
|
from .util import urlopen
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Use the Freecode submit file as source since that file gets updated
|
|
||||||
# only when releasing a new version.
|
|
||||||
UPDATE_URL = "https://raw.github.com/wummel/dosage/master/dosage.freecode"
|
|
||||||
VERSION_TAG = 'Version:'
|
|
||||||
if os.name == 'nt':
|
|
||||||
URL_TAG = 'Windows-installer-URL:'
|
|
||||||
else:
|
|
||||||
URL_TAG = 'Source-Package-URL:'
|
|
||||||
|
|
||||||
|
UPDATE_URL = "https://api.github.com/repos/webcomics/dosage/releases/latest"
|
||||||
|
|
||||||
def check_update ():
|
def check_update ():
|
||||||
"""Return the following values:
|
"""Return the following values:
|
||||||
|
@ -42,14 +36,14 @@ def check_update ():
|
||||||
def get_online_version ():
|
def get_online_version ():
|
||||||
"""Download update info and parse it."""
|
"""Download update info and parse it."""
|
||||||
session = requests.session()
|
session = requests.session()
|
||||||
page = urlopen(UPDATE_URL, session)
|
page = urlopen(UPDATE_URL, session).json()
|
||||||
version, url = None, None
|
version, url = None, None
|
||||||
for line in page.text.splitlines():
|
version = page['tag_name']
|
||||||
if line.startswith(VERSION_TAG):
|
|
||||||
version = line.split(':', 1)[1].strip()
|
if os.name == 'nt':
|
||||||
elif line.startswith(URL_TAG):
|
url = next((x['browser_download_url'] for x in page['assets'] if x['content_type'] == 'application/x-msdos-program'), configuration.Url)
|
||||||
url = line.split(':', 1)[1].strip()
|
else:
|
||||||
url = url.replace('${version}', version)
|
url = page['tarball_url']
|
||||||
return version, url
|
return version, url
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue