1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-10 12:22:27 +03:00

EDMC.py: import re, fix version compare and report

* I neglected to `import re` when I changed the Journal file name check.
* `map` isn't comparable in Python 3.7, need to `list()` it as well.
* Just print the full `appversion`.  The old code was assuming that none of
  A, B, C, D in A.B.C.D would be two or more digits.

close #566
This commit is contained in:
Athanasius 2020-07-07 19:00:06 +01:00
parent 98227b7af0
commit 3ff77c3c54

12
EDMC.py
View File

@ -11,6 +11,7 @@ import os
from os.path import dirname, getmtime, join 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 l10n import l10n
l10n.Translations.install_dummy() l10n.Translations.install_dummy()
@ -36,7 +37,7 @@ EXIT_SUCCESS, EXIT_SERVER, EXIT_CREDENTIALS, EXIT_VERIFICATION, EXIT_LAGGING, EX
# quick and dirty version comparison assuming "strict" numeric only version numbers # quick and dirty version comparison assuming "strict" numeric only version numbers
def versioncmp(versionstring): def versioncmp(versionstring):
return map(int, versionstring.split('.')) return list(map(int, versionstring.split('.')))
try: try:
@ -67,9 +68,10 @@ try:
lastversion = sorted(items, key=versioncmp)[-1] lastversion = sorted(items, key=versioncmp)[-1]
if versioncmp(lastversion) > versioncmp(appversion): if versioncmp(lastversion) > versioncmp(appversion):
latest = ' (%s is available)' % items[lastversion] latest = ' (%s is available)' % items[lastversion]
except: except Exception as e:
pass # Quietly suppress timeouts etc. sys.stderr.write('Exception in version check: {}'.format(str(e)))
print('%.2f%s' % (float(''.join(appversion.split('.')[:3])) / 100, latest)) # just first three digits #pass # Quietly suppress timeouts etc.
print(appversion)
sys.exit(EXIT_SUCCESS) sys.exit(EXIT_SUCCESS)
if args.j: if args.j:
@ -91,7 +93,7 @@ try:
if __debug__: if __debug__:
print('Invalid journal entry "%s"' % repr(line)) print('Invalid journal entry "%s"' % repr(line))
except Exception as e: except Exception as e:
sys.stderr.write("Can't read Journal file: %s\n" % str(e).encode('ascii', 'replace')) sys.stderr.write("Can't read Journal file: {}\n".format(str(e)))
sys.exit(EXIT_SYS_ERR) sys.exit(EXIT_SYS_ERR)
if not monitor.cmdr: if not monitor.cmdr: