Merge pull request #7 from CMDR-Kiel42/updater

Updater
This commit is contained in:
CMDR-Kiel42 2019-07-28 20:00:18 +02:00 committed by GitHub
commit 913b94cb1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 34 deletions

View File

@ -27,10 +27,15 @@ class AutoCompleter(Entry, PlaceHolder):
self.bind("<Any-Key>", self.keypressed)
self.bind('<Control-KeyRelease-a>', self.select_all)
self.bind('<Button-3>', self.paste)
self.lb.bind("<Double-Button-1>", self.selection)
self.update_me()
def paste(self, event):
self.foc_in()
self.insert(0, self.clipboard_get())
def keypressed(self, event):
key=event.keysym
if key == 'Down':

View File

@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
## 2.1.0
- Automatically download and install updates
- Right clicking on a System input now pastes what's in your clipboard
## 2.0.1
- Add an error prompt when things go wrong while plotting a route

View File

@ -24,6 +24,10 @@ If you close EDMC, the plugin will save your progress. The next time you run EDM
Fly dangerous! o7
## Updates
When a new update is available, it will automatically be downloaded. You'll just have to restart EDMC to install it.
## Known Issues
At the moment, plotting a route while the game is running, and which begins from the system you're currently in, doesn't update your "next waypoint". If you're in that situation, a couple of solutions are available:

76
load.py
View File

@ -8,16 +8,15 @@ import json
import webbrowser
import requests
import traceback
import subprocess
from updater import SpanshUpdater
from time import sleep
from AutoCompleter import AutoCompleter
from PlaceHolderEntry import PlaceHolderEntry
if sys.platform.startswith('linux'):
import subprocess
this = sys.modules[__name__]
this.plugin_version = "2.0.1"
this.plugin_version = "2.1.0"
this.update_available = False
this.next_stop = "No route planned"
this.route = []
@ -41,39 +40,42 @@ def plugin_start(plugin_dir):
if response.status_code == 200:
if this.plugin_version != response.content:
this.update_available = True
this.spansh_updater = SpanshUpdater(response.content, plugin_dir)
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])
this.next_stop = this.route[this.offset][0]
copy_waypoint()
except:
print("No previously saved route.")
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.")
def plugin_stop():
if this.route.__len__() != 0:
@ -91,6 +93,8 @@ def plugin_stop():
except:
print("No route to delete")
if this.update_available:
this.spansh_updater.install()
def show_error(error):
this.error_txt.set(error)
@ -172,13 +176,13 @@ def show_plot_gui(show=True):
show_route_gui(True)
def copy_waypoint(self=None):
if sys.platform == "win32":
if sys.platform == "linux" or sys.platform == "linux2":
command = subprocess.Popen(["echo", "-n", this.next_stop], stdout=subprocess.PIPE)
subprocess.Popen(["xclip", "-selection", "c"], stdin=command.stdout)
else:
this.parent.clipboard_clear()
this.parent.clipboard_append(this.next_stop)
this.parent.update()
else:
command = subprocess.Popen(["echo", "-n", this.next_stop], stdout=subprocess.PIPE)
subprocess.Popen(["xclip", "-selection", "c"], stdin=command.stdout)
def goto_next_waypoint(self=None):
if this.offset < this.route.__len__()-1:
@ -347,8 +351,10 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
elif entry['event'] == 'FSSDiscoveryScan' and entry['SystemName'] == this.next_stop:
update_route()
def goto_update_page(self=None):
webbrowser.open('https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases')
def goto_changelog_page(self=None):
changelog_url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/blob/master/CHANGELOG.md#'
changelog_url += this.spansh_updater.version.replace('.', '')
webbrowser.open(changelog_url)
def plugin_app(parent):
this.parent = parent
@ -414,7 +420,11 @@ def plugin_app(parent):
this.clear_route_btn.grid_remove()
if this.update_available:
this.update_btn = tk.Button(this.frame, text="SpanshRouter update available for download!", command=goto_update_page)
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.")
this.update_btn = tk.Button(this.frame, text=update_txt, command=lambda: this.update_btn.grid_forget())
this.update_btn.bind("<Button-3>", goto_changelog_page)
this.update_btn.grid(row=row, pady=5, columnspan=2)
row += 1

48
updater.py Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python2
import os
import requests
import zipfile
import sys
import traceback
class SpanshUpdater():
def __init__(self, version, plugin_dir):
self.version = version
self.zip_name = "EDMC_SpanshRouter_" + version.replace('.', '') + ".zip"
self.plugin_dir = plugin_dir
self.zip_path = os.path.join(self.plugin_dir, self.zip_name)
self.zip_downloaded = False
def download_zip(self):
url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases/download/v' + self.version + '/' + self.zip_name
try:
r = requests.get(url)
if r.status_code == 200:
with open(self.zip_path, 'wb') as f:
print("Downloading SpanshRouter to " + self.zip_path)
f.write(os.path.join(r.content))
self.zip_downloaded = True
else:
sys.stderr.write("Failed to fetch SpanchRouter update. Status code: " + str(r.status_code))
self.zip_downloaded = False
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))
self.zip_downloaded = False
finally:
return self.zip_downloaded
def install(self):
if self.zip_downloaded:
try:
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
zip_ref.extractall(self.plugin_dir)
os.remove(self.zip_path)
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))

View File

@ -1 +1 @@
2.0.1
2.1.0