Skip to content

Commit

Permalink
Add packaging requirement, and use it's PEP 440 version parsing for v…
Browse files Browse the repository at this point in the history
…ersion comparisons.
  • Loading branch information
blitzmann committed Feb 10, 2018
1 parent 9c355d8 commit 50dd74d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions gui/mainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def __init__(self, title="pyfa"):
self.titleTimer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.updateTitle, self.titleTimer)

def ShowUpdateBox(self, release):
dlg = UpdateDialog(self, release)
def ShowUpdateBox(self, release, version):
dlg = UpdateDialog(self, release, version)
dlg.ShowModal()

def LoadPreviousOpenFits(self):
Expand Down
11 changes: 6 additions & 5 deletions gui/updateDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@
<style>
body {{ padding: 10px; font-size:0.87em }}
p , li {{ text-align: justify; }}
h2, h3 {{ text-align: center; }}
hr {{ margin-top: -10px; border: #000 1px solid; }}
h2 {{ text-align: center; margin: 0; }}
.date {{ text-align: right; }}
hr {{ border: #000 1px solid; }}
</style>
<h2>pyfa {0}</h2>
<h3>{1}</h3>
<div class="date"><small>{1}</small></div>
<hr>
{2}
{3}
"""


class UpdateDialog(wx.Dialog):
def __init__(self, parent, release):
def __init__(self, parent, release, version):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title="pyfa Update Available", pos=wx.DefaultPosition,
size=wx.Size(550, 450), style=wx.DEFAULT_DIALOG_STYLE)

Expand All @@ -72,7 +73,7 @@ def __init__(self, parent, release):
self.browser.SetPage(html_tmpl.format(
self.releaseInfo['tag_name'],
releaseDate.strftime('%B %d, %Y'),
"<p class='text-danger'><b>This is a pre-release, be prepared for unstable features</b></p>" if self.releaseInfo['prerelease'] else "",
"<p class='text-danger'><b>This is a pre-release, be prepared for unstable features</b></p>" if version.is_prerelease else "",
markdowner.convert(self.releaseInfo['body'])
),"")

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ matplotlib >= 2.0.0
python-dateutil
requests >= 2.0.0
sqlalchemy >= 1.0.5
markdown2
markdown2
packaging
30 changes: 10 additions & 20 deletions service/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from service.network import Network
from service.settings import UpdateSettings
from logbook import Logger
from packaging.version import Version


pyfalog = Logger(__name__)

Expand All @@ -46,16 +48,19 @@ def run(self):
network = Network.getInstance()

try:
response = network.request('https://api.github.com/repos/pyfa-org/Pyfa/releases', network.UPDATE)
response = network.request('https://api.github.com/repos/blitzmann/Pyfa/releases', network.UPDATE)
jsonResponse = json.loads(response.read())
jsonResponse.sort(
key=lambda x: calendar.timegm(dateutil.parser.parse(x['published_at']).utctimetuple()),
reverse=True
)

for release in jsonResponse:
rVersion = Version(release['tag_name'])
cVersion = Version(config.version)

# Suppress pre releases
if release['prerelease'] and self.settings.get('prerelease'):
if rVersion.is_prerelease and self.settings.get('prerelease'):
continue

# Handle use-case of updating to suppressed version
Expand All @@ -66,24 +71,9 @@ def run(self):
if release['tag_name'] == self.settings.get('version'):
break

# Set the release version that we will be comparing with.
if release['prerelease']:
rVersion = release['tag_name'].replace('singularity-', '', 1)
else:
rVersion = release['tag_name'].replace('v', '', 1)

if config.tag is 'git' and \
not release['prerelease'] and \
self.versiontuple(rVersion) >= self.versiontuple(config.version):
wx.CallAfter(self.callback, release) # git (dev/Singularity) -> Stable
elif config.expansionName is not "Singularity":
if release['prerelease']:
wx.CallAfter(self.callback, release) # Stable -> Singularity
elif self.versiontuple(rVersion) > self.versiontuple(config.version):
wx.CallAfter(self.callback, release) # Stable -> Stable
else:
if release['prerelease'] and rVersion > config.expansionVersion:
wx.CallAfter(self.callback, release) # Singularity -> Singularity
if rVersion > cVersion:
wx.CallAfter(self.callback, release, rVersion)

break
except Exception as e:
pyfalog.error("Caught exception in run")
Expand Down

0 comments on commit 50dd74d

Please sign in to comment.