Merge branch 'new_updates_prompt'

This commit is contained in:
Kiel42 2019-11-19 23:30:19 +01:00
commit 4cfdedd7cb
4 changed files with 38 additions and 13 deletions

View File

@ -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

View File

@ -108,14 +108,17 @@ 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("<Button-3>", 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 += "\n\nInstall?"
install_update = confirmDialog.askyesno("SpanshRouter", update_txt)
if install_update:
confirmDialog.showinfo("SpanshRouter", "The update will be installed as soon as you quit EDMC.")
else:
self.update_available = False
self.update_gui()
return self.frame
@ -560,17 +563,15 @@ 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():
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:

View File

@ -5,6 +5,7 @@ import requests
import zipfile
import sys
import traceback
import json
class SpanshUpdater():
def __init__(self, version, plugin_dir):
@ -13,6 +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.get_changelog()
def download_zip(self):
url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases/download/v' + self.version + '/' + self.zip_name
@ -36,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)
@ -46,3 +48,21 @@ 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"
try:
r = requests.get(url, timeout=2)
if r.status_code == 200:
# Get the changelog and replace all breaklines with simple ones
changelogs = json.loads(r.content)["body"]
changelogs = "\n".join(changelogs.splitlines())
return changelogs
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))

View File

@ -1 +1 @@
2.2.0
2.2.1