Skip to content

Commit

Permalink
Merge pull request #345 from PyPlanet/bugfix/336
Browse files Browse the repository at this point in the history
[TASK] Replace the version comparing for the version checking.
  • Loading branch information
tomvlk committed Jun 3, 2017
2 parents 48b08e1 + b4f5544 commit 88d1ab4
Show file tree
Hide file tree
Showing 2 changed files with 366 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pyplanet/utils/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import logging
import aiohttp

from . import semver


class _UpdateChecker: # pragma: no cover

def __init__(self):
self.latest = None
self.latest_name = None
self.current = None
self.instance = None

Expand Down Expand Up @@ -37,32 +38,30 @@ async def loop(self):

async def check(self, first_check=False):
from pyplanet import __version__ as current_version
from packaging import version

logging.debug('Checking for new versions...')

async with aiohttp.request('GET', self.url) as resp:
self.latest_name = (await resp.json())[0]['name']
self.latest = version.parse(self.latest_name)
self.current = version.parse(current_version)
self.latest = (await resp.json())[0]['name']
self.current = current_version

if first_check and self.latest > self.current:
logging.info('New version of PyPlanet available, consider updating: {}'.format(self.latest_name))
if first_check and self.update_available:
logging.info('New version of PyPlanet available, consider updating: {}'.format(self.latest))
await self.instance.chat(
'\uf1e6 $FD4$oPy$369Planet$z$s$fff \uf0e7 new version available: v{}. Consider updating!'.format(self.latest_name)
'\uf1e6 $FD4$oPy$369Planet$z$s$fff \uf0e7 new version available: v{}. Consider updating!'.format(self.latest)
)

@property
def update_available(self):
if self.latest is None or self.current is None:
return False
return self.latest > self.current
return semver.compare(self.latest, self.current) > 0

async def connect(self, player, **kwargs):
if player.level > 0 and self.update_available is not False:
await self.instance.gbx.multicall(
self.instance.chat(
'\uf1e6 $FD4$oPy$369Planet$z$s$fff \uf0e7 new version available: v{}. Consider updating!'.format(self.latest_name),
'\uf1e6 $FD4$oPy$369Planet$z$s$fff \uf0e7 new version available: v{}. Consider updating!'.format(self.latest),
player
),
self.instance.chat(
Expand Down

0 comments on commit 88d1ab4

Please sign in to comment.