From 24e15111b80a8a0a334eb48ddbd8962d8ef1fc2b Mon Sep 17 00:00:00 2001 From: Kiel42 Date: Tue, 29 Oct 2019 00:23:20 +0100 Subject: [PATCH 1/4] Fetch the changelogs and display them in a popup asking if we should install --- SpanshRouter/SpanshRouter.py | 24 ++++++++++++++---------- SpanshRouter/updater.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/SpanshRouter/SpanshRouter.py b/SpanshRouter/SpanshRouter.py index 319491b..5e86fc9 100755 --- a/SpanshRouter/SpanshRouter.py +++ b/SpanshRouter/SpanshRouter.py @@ -108,14 +108,15 @@ class SpanshRouter(): self.clear_route_btn.grid_remove() if self.update_available: - update_txt = ("A SpanshRouter update is available.\n" - "It will be installed next time you start EDMC.\n" - "Click to dismiss this message, right click to see what's new.") - self.update_btn = tk.Button(self.frame, text=update_txt, command=lambda: self.update_btn.grid_forget()) - self.update_btn.bind("", self.goto_changelog_page) - self.update_btn.grid(row=row, pady=5, columnspan=2) - row += 1 + update_txt = "New Spansh update available!\n" + update_txt += "If you choose to install it, you will have to restart EDMC for it to take effect.\n\n" + update_txt += self.spansh_updater.changelogs + update_txt += "Install?" + install_update = confirmDialog.askyesno("SpanshRouter", update_txt) + if install_update: + confirmDialog.showinfo("SpanshRouter", "The update will be installed as soon as you close EDMC.") + self.update_gui() return self.frame @@ -560,17 +561,20 @@ class SpanshRouter(): def check_for_update(self): self.cleanup_old_version() - url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/version.json" + version_url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/version.json" try: - response = requests.get(url, timeout=2) + response = requests.get(version_url, timeout=2) if response.status_code == 200: if self.plugin_version != response.content: self.update_available = True self.spansh_updater = SpanshUpdater(response.content, self.plugin_dir) - if not self.spansh_updater.download_zip(): + if self.spansh_updater.download_zip(): + self.spansh_updater.get_changelog() + else: sys.stderr.write("Error when downloading the latest SpanshRouter update") + else: sys.stderr.write("Could not query latest SpanshRouter version: " + str(response.status_code) + response.text) except: diff --git a/SpanshRouter/updater.py b/SpanshRouter/updater.py index 5c7f2a2..4a9c20c 100755 --- a/SpanshRouter/updater.py +++ b/SpanshRouter/updater.py @@ -13,6 +13,7 @@ class SpanshUpdater(): self.plugin_dir = plugin_dir self.zip_path = os.path.join(self.plugin_dir, self.zip_name) self.zip_downloaded = False + self.changelogs = "" def download_zip(self): url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases/download/v' + self.version + '/' + self.zip_name @@ -46,3 +47,17 @@ class SpanshUpdater(): 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)) + + def get_changelog(self): + url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/CHANGELOG.md" + try: + r = requests.get(url, timeout=2) + + if r.status_code == 200: + start_index = r.content.find("## " + self.version) + stop_index = r.content.find("##", start_index + 2) + self.changelogs = r.content[start_index: stop_index:] + except: + 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)) \ No newline at end of file From 7875825f57f67d82d0a3700b7fa7b8547f13d63f Mon Sep 17 00:00:00 2001 From: CMDR-Kiel42 Date: Tue, 29 Oct 2019 21:36:11 +0100 Subject: [PATCH 2/4] Use the Git API to get the changelog instead of parsing the whole .md file --- SpanshRouter/updater.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SpanshRouter/updater.py b/SpanshRouter/updater.py index 4a9c20c..061fc77 100755 --- a/SpanshRouter/updater.py +++ b/SpanshRouter/updater.py @@ -5,6 +5,7 @@ import requests import zipfile import sys import traceback +import json class SpanshUpdater(): def __init__(self, version, plugin_dir): @@ -49,14 +50,16 @@ class SpanshUpdater(): sys.stderr.write(''.join('!! ' + line for line in lines)) def get_changelog(self): - url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/CHANGELOG.md" + url = "https://api.github.com/repos/CMDR-Kiel42/EDMC_SpanshRouter/releases/latest" try: r = requests.get(url, timeout=2) if r.status_code == 200: - start_index = r.content.find("## " + self.version) - stop_index = r.content.find("##", start_index + 2) - self.changelogs = r.content[start_index: stop_index:] + # Get the changelog and replace all breaklines with simple ones + self.changelogs = json.loads(r.content)["body"] + self.changelogs = "\n".join(self.changelogs.splitlines()) + pass + except: exc_type, exc_value, exc_traceback = sys.exc_info() lines = traceback.format_exception(exc_type, exc_value, exc_traceback) From cee1a15193a1eaf107d96ffdfe63ff9854f8be69 Mon Sep 17 00:00:00 2001 From: CMDR-Kiel42 Date: Tue, 29 Oct 2019 21:47:04 +0100 Subject: [PATCH 3/4] Download and install the update according to what the user chose --- SpanshRouter/SpanshRouter.py | 11 ++++------- SpanshRouter/updater.py | 12 +++++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/SpanshRouter/SpanshRouter.py b/SpanshRouter/SpanshRouter.py index 5e86fc9..5ef75b8 100755 --- a/SpanshRouter/SpanshRouter.py +++ b/SpanshRouter/SpanshRouter.py @@ -111,11 +111,13 @@ class SpanshRouter(): update_txt = "New Spansh update available!\n" update_txt += "If you choose to install it, you will have to restart EDMC for it to take effect.\n\n" update_txt += self.spansh_updater.changelogs - update_txt += "Install?" + update_txt += "\n\nInstall?" install_update = confirmDialog.askyesno("SpanshRouter", update_txt) if install_update: - confirmDialog.showinfo("SpanshRouter", "The update will be installed as soon as you close EDMC.") + confirmDialog.showinfo("SpanshRouter", "The update will be installed as soon as you quit EDMC.") + else: + self.update_available = False self.update_gui() @@ -570,11 +572,6 @@ class SpanshRouter(): self.update_available = True self.spansh_updater = SpanshUpdater(response.content, self.plugin_dir) - if self.spansh_updater.download_zip(): - self.spansh_updater.get_changelog() - else: - sys.stderr.write("Error when downloading the latest SpanshRouter update") - else: sys.stderr.write("Could not query latest SpanshRouter version: " + str(response.status_code) + response.text) except: diff --git a/SpanshRouter/updater.py b/SpanshRouter/updater.py index 061fc77..535f9cd 100755 --- a/SpanshRouter/updater.py +++ b/SpanshRouter/updater.py @@ -14,7 +14,7 @@ class SpanshUpdater(): self.plugin_dir = plugin_dir self.zip_path = os.path.join(self.plugin_dir, self.zip_name) self.zip_downloaded = False - self.changelogs = "" + self.changelogs = self.get_changelog() def download_zip(self): url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases/download/v' + self.version + '/' + self.zip_name @@ -38,7 +38,7 @@ class SpanshUpdater(): return self.zip_downloaded def install(self): - if self.zip_downloaded: + if self.download_zip(): try: with zipfile.ZipFile(self.zip_path, 'r') as zip_ref: zip_ref.extractall(self.plugin_dir) @@ -48,6 +48,8 @@ class SpanshUpdater(): 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)) + else: + sys.stderr.write("Error when downloading the latest SpanshRouter update") def get_changelog(self): url = "https://api.github.com/repos/CMDR-Kiel42/EDMC_SpanshRouter/releases/latest" @@ -56,9 +58,9 @@ class SpanshUpdater(): if r.status_code == 200: # Get the changelog and replace all breaklines with simple ones - self.changelogs = json.loads(r.content)["body"] - self.changelogs = "\n".join(self.changelogs.splitlines()) - pass + changelogs = json.loads(r.content)["body"] + changelogs = "\n".join(changelogs.splitlines()) + return changelogs except: exc_type, exc_value, exc_traceback = sys.exc_info() From a7335d2116e3534b3916e71a6a32d261e6a46697 Mon Sep 17 00:00:00 2001 From: Kiel42 Date: Tue, 19 Nov 2019 23:25:28 +0100 Subject: [PATCH 4/4] Changelog and version updates --- CHANGELOG.md | 4 ++++ version.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c318d72..0f5103e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 2.2.1 + +- Changes from updates now appear in a popup so the user can choose wether they want to install it or not. + ## 2.2.0 - Now supports any CSV having columns named "System Name" and "Jumps". The "Jumps" column is optional diff --git a/version.json b/version.json index e3a4f19..fae692e 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -2.2.0 \ No newline at end of file +2.2.1 \ No newline at end of file