From d742701efc267d80273210797fec5a53ba75460d Mon Sep 17 00:00:00 2001 From: CMDR-Kiel42 Date: Sun, 28 Jul 2019 00:07:16 +0200 Subject: [PATCH] Fixed plugin crash when update download failed --- load.py | 46 ++++++++++++++++++++++++---------------------- updater.py | 3 +++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/load.py b/load.py index cd45793..c64434e 100644 --- a/load.py +++ b/load.py @@ -41,39 +41,41 @@ def plugin_start(plugin_dir): if this.plugin_version != response.content: this.update_available = True this.spansh_updater = SpanshUpdater(response.content) - this.spansh_updater.download_zip() + + if not this.spansh_updater.download_zip(): + sys.stderr.write("Error when downloading the latest SpanshRouter update") else: - sys.stderr.write("Could not query latest version from GitHub: " + str(response.status_code) + response.text) + sys.stderr.write("Could not query latest SpanshRouter version: " + str(response.status_code) + response.text) except NameError: exc_type, exc_value, exc_traceback = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_traceback) sys.stderr.write(''.join('!! ' + line for line in lines)) + finally: + this.save_route_path = os.path.join(plugin_dir, 'route.csv') + this.offset_file_path = os.path.join(plugin_dir, 'offset') - this.save_route_path = os.path.join(plugin_dir, 'route.csv') - this.offset_file_path = os.path.join(plugin_dir, 'offset') + try: + # Open the last saved route + with open(this.save_route_path, 'r') as csvfile: + route_reader = csv.reader(csvfile) - try: - # Open the last saved route - with open(this.save_route_path, 'r') as csvfile: - route_reader = csv.reader(csvfile) + for row in route_reader: + this.route.append(row) - for row in route_reader: - this.route.append(row) + try: + with open(this.offset_file_path, 'r') as offset_fh: + this.offset = int(offset_fh.readline()) - try: - with open(this.offset_file_path, 'r') as offset_fh: - this.offset = int(offset_fh.readline()) + except: + this.offset = 0 - except: - this.offset = 0 + for row in this.route[this.offset:]: + this.jumps_left += int(row[1]) - for row in this.route[this.offset:]: - this.jumps_left += int(row[1]) - - this.next_stop = this.route[this.offset][0] - copy_waypoint() - except: - print("No previously saved route.") + this.next_stop = this.route[this.offset][0] + copy_waypoint() + except: + print("No previously saved route.") def plugin_stop(): if this.route.__len__() != 0: diff --git a/updater.py b/updater.py index 33d8050..8b7062a 100755 --- a/updater.py +++ b/updater.py @@ -27,6 +27,9 @@ class SpanshUpdater(): lines = traceback.format_exception(exc_type, exc_value, exc_traceback) sys.stderr.write(''.join('!! ' + line for line in lines)) self.zip_downloaded = False + finally: + return self.zip_downloaded + def install(self): if self.zip_downloaded: