mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-16 07:12:17 +03:00
Re-engineering of EDMC.py version update check
* Uses semantic_version. * Filters on sparkle:os. * Catches specific exceptions.
This commit is contained in:
parent
af1c313dc3
commit
1ee8756983
48
EDMC.py
48
EDMC.py
@ -16,6 +16,7 @@ from os.path import dirname, getmtime, join
|
|||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
import re
|
import re
|
||||||
|
import semantic_version
|
||||||
|
|
||||||
import l10n
|
import l10n
|
||||||
l10n.Translations.install_dummy()
|
l10n.Translations.install_dummy()
|
||||||
@ -62,21 +63,42 @@ try:
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
latest = ''
|
newversion = None
|
||||||
try:
|
try:
|
||||||
# Copied from update.py - probably should refactor
|
update_feed = 'https://ed.miggy.org/misc/semvertest-appcast.xml'
|
||||||
r = requests.get(update_feed, timeout = 10)
|
r = requests.get(update_feed, timeout = 10)
|
||||||
feed = ElementTree.fromstring(r.text)
|
except requests.RequestException as ex:
|
||||||
items = dict([(item.find('enclosure').attrib.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}version'),
|
sys.stderr.write('Error retrieving update_feed file: {}\n'.format(str(ex)))
|
||||||
item.find('title').text) for item in feed.findall('channel/item')])
|
else:
|
||||||
lastversion = sorted(items, key=versioncmp)[-1]
|
try:
|
||||||
if versioncmp(lastversion) > versioncmp(appversion):
|
feed = ElementTree.fromstring(r.text)
|
||||||
latest = items[lastversion]
|
except SyntaxError as ex:
|
||||||
except Exception as e:
|
sys.stderr.write('Syntax error in update_feed file: {}\n'.format(str(ex)))
|
||||||
sys.stderr.write('Exception in version check: {}'.format(str(e)))
|
else:
|
||||||
#pass # Quietly suppress timeouts etc.
|
# Want to make items['<version>'] = {'os': '...', 'title': '...' }
|
||||||
if latest:
|
items = dict(
|
||||||
print('{CURRENT} ({UPDATE} is available)'.format(CURRENT=appversion, UPDATE=latest))
|
[
|
||||||
|
(
|
||||||
|
item.find('enclosure').attrib.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}version'),
|
||||||
|
{'title': item.find('title').text,
|
||||||
|
'os': item.find('enclosure').attrib.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}os'),
|
||||||
|
}
|
||||||
|
) for item in feed.findall('channel/item')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Filter on the sparkle:os attribute
|
||||||
|
os_map = {'darwin': 'macos', 'win32': 'windows', 'linux': 'linux'} # Map sys.platform to sparkle:os
|
||||||
|
items = { k:v for (k,v) in items.items() if v['os'] == os_map[sys.platform]}
|
||||||
|
|
||||||
|
# Look for any remaining version greater than appversion
|
||||||
|
simple_spec = semantic_version.SimpleSpec('>' + appversion)
|
||||||
|
newversion = simple_spec.select([semantic_version.Version.coerce(x) for x in items])
|
||||||
|
|
||||||
|
if newversion:
|
||||||
|
print('{CURRENT} ("{UPDATE}" is available)'.format(
|
||||||
|
CURRENT=appversion,
|
||||||
|
UPDATE=items[str(newversion)]['title']))
|
||||||
else:
|
else:
|
||||||
print(appversion)
|
print(appversion)
|
||||||
sys.exit(EXIT_SUCCESS)
|
sys.exit(EXIT_SUCCESS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user