Skip to content

Commit

Permalink
Merge pull request #151 from GliderGeek/47-latest-version
Browse files Browse the repository at this point in the history
47 latest version
  • Loading branch information
GliderGeek authored May 31, 2019
2 parents 292e59f + dbf81f0 commit db53b51
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Master

[unreleased]
- check on version during startup

v0.58.0
- use wxpython instead of tkinter for GUI

Expand Down
51 changes: 40 additions & 11 deletions PySoar/main_pysoar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import subprocess
import os
import sys
import json
import requests

import wx

Expand Down Expand Up @@ -50,16 +52,21 @@ def get_url_source(url):


class MyFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='PySoar (%s)' % settings.version)
def __init__(self, current_version, latest_version):
super().__init__(parent=None, title='PySoar: %s' % current_version)
panel = wx.Panel(self)

complete_sizer = wx.BoxSizer(wx.VERTICAL)

if latest_version and latest_version.lstrip('v') != current_version:
version_status = wx.StaticText(panel, label="Latest version: %s" % latest_version)
version_status.SetForegroundColour((255, 0, 0))
complete_sizer.Add(version_status, 0, wx.CENTER)

my_sizer = wx.BoxSizer(wx.VERTICAL)

text = wx.StaticText(panel, label="Fill in URL:")
my_sizer.Add(text, 0, wx.ALL | wx.CENTER, 5)
my_sizer.Add(text, 0, wx.ALL, 5)
self.url_input = wx.TextCtrl(panel)
my_sizer.Add(self.url_input, 0, wx.ALL | wx.EXPAND, 5)

Expand Down Expand Up @@ -151,13 +158,25 @@ def on_press(self, event):
self.open_spreadsheet.Enable()


def start_gui():
def get_latest_version():
github_user = "GliderGeek"
github_repo = "PySoar"
url_latest_version = "https://api.github.com/repos/%s/%s/releases" % (github_user, github_repo)

r = requests.get(url_latest_version)
parsed_json = json.loads(r.text)

latest_version = parsed_json[0]['tag_name']
return latest_version


def start_gui(current_version, latest_version):
app = wx.App()
frame = MyFrame()
MyFrame(current_version, latest_version)
app.MainLoop()


def run_commandline_program(sys_argv):
def run_commandline_program(sys_argv, current_version, latest_version):

def print_help():
print('There are two options for running PySoar from the commandline:\n'
Expand All @@ -181,11 +200,14 @@ def analysis_handle(new, total=None):
analysis_str = 'Analyzed: %s' % new
print(analysis_str)

if len(sys.argv) == 2:
if sys.argv[1] == '--help':
if latest_version and latest_version.lstrip('v') != current_version:
print('Latest version is %s! Current: %s' % (latest_version, current_version))

if len(sys_argv) == 2:
if sys_argv[1] == '--help':
print_help()
else:
url = sys.argv[1]
url = sys_argv[1]
correct = url_format_correct(url, status_handle)
if correct:
source = get_url_source(url)
Expand All @@ -195,10 +217,17 @@ def analysis_handle(new, total=None):


if __name__ == '__main__':

current_version = settings.version
try:
latest_version = get_latest_version()
except Exception:
latest_version = ''

if len(sys.argv) == 1:
start_gui()
start_gui(current_version, latest_version)
else:
run_commandline_program(sys.argv)
run_commandline_program(sys.argv, current_version, latest_version)

############################# LICENSE #####################################

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pyinstaller==3.3.1
aerofiles==0.4.1
opensoar==0.1.3
wxpython==4.0.6
requests

0 comments on commit db53b51

Please sign in to comment.