From 1cefdb9a2459d46c2629745a2b68e472c1efc3e4 Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 3 Jul 2019 18:13:45 +0200 Subject: [PATCH] possible fix crash if no internet connection --- platformcode/updater.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/platformcode/updater.py b/platformcode/updater.py index 5dea857a..08ba2fe0 100644 --- a/platformcode/updater.py +++ b/platformcode/updater.py @@ -25,9 +25,17 @@ trackingFile = "last_commit.txt" def loadCommits(page=1): apiLink = 'https://api.github.com/repos/' + user + '/' + repo + '/commits?sha=' + branch + "&page=" + str(page) - commitsLink = httptools.downloadpage(apiLink).data logger.info(apiLink) - return json.loads(commitsLink) + # riprova ogni secondo finchè non riesce (ad esempio per mancanza di connessione) + while True: + try: + commitsLink = httptools.downloadpage(apiLink).data + ret = json.loads(commitsLink) + break + except: + xbmc.sleep(1000) + + return ret def check_addon_init(): @@ -238,7 +246,7 @@ def updateFromZip(): def fixZipGetHash(zipFile): f = open(zipFile, 'r+b') data = f.read() - pos = data.find('\x50\x4b\x05\x06') # End of central directory signature + pos = data.find(b'\x50\x4b\x05\x06') # End of central directory signature hash = '' if pos > 0: f.seek(pos + 20) # +20: see secion V.I in 'ZIP format' link above. @@ -246,10 +254,12 @@ def fixZipGetHash(zipFile): f.seek(pos + 20) f.truncate() f.write( - '\x00\x00') # Zip file comment length: 0 byte length; tell zip applications to stop reading. + b'\x00\x00') # Zip file comment length: 0 byte length; tell zip applications to stop reading. f.seek(0) - return hash + f.close() + + return str(hash) class ziptools: