Skip to content

Commit 9334ace

Browse files
authored
Merge pull request #701 from oduwsdl/issue-700
2 parents e059aed + fa94066 commit 9334ace

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

ipwb/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def checkArgs(argsIn):
149149
action='store_true',
150150
help='Check whether an updated version of ipwb is available'
151151
)
152-
parser.set_defaults(func=util.checkForUpdate)
152+
parser.set_defaults(func=util.check_for_update)
153153

154154
argCount = len(argsIn)
155155
cmdList = ['index', 'replay']

ipwb/util.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import logging
1414
import platform
1515

16-
from six.moves.urllib.request import urlopen
16+
from urllib.request import urlopen
17+
from urllib.error import URLError
18+
1719
import json
18-
from .__init__ import __version__ as ipwbVersion
20+
from .__init__ import __version__ as ipwb_version
1921

2022
from ipfshttpclient.exceptions import ConnectionError, AddressError
2123
from multiaddr.exceptions import StringParseError
@@ -314,22 +316,23 @@ def unsurt(surt):
314316
return surt
315317

316318

317-
def compareCurrentAndLatestIPWBVersions():
319+
def get_latest_version():
318320
try:
319-
resp = urlopen('https://pypi.python.org/pypi/ipwb/json')
320-
jResp = json.loads(resp.read())
321-
latestVersion = jResp['info']['version']
322-
currentVersion = re.sub(r'\.0+', '.', ipwbVersion)
323-
return (currentVersion, latestVersion)
324-
except Exception as e:
325-
return (None, None)
326-
321+
resp = urlopen('https://pypi.org/pypi/ipwb/json')
322+
return json.loads(resp.read())['info']['version']
323+
except Exception:
324+
return None
327325

328-
def checkForUpdate(_):
329-
(current, latest) = compareCurrentAndLatestIPWBVersions()
330326

331-
if current != latest and current is not None:
332-
print('This version of ipwb is outdated.'
333-
' Please run pip install --upgrade ipwb.')
334-
print(f'* Latest version: {latest}')
335-
print(f'* Installed version: {current}')
327+
def check_for_update(_):
328+
latest = get_latest_version()
329+
if not latest:
330+
print("Failed to check for the latest version.")
331+
return
332+
current = re.sub(r'\.0+', '.', ipwb_version)
333+
if latest == current:
334+
print(f"Installed version {current} is up to date.")
335+
else:
336+
print("The installed version of ipwb is outdated.")
337+
print(f"* Installed: {current}\n* Latest: {latest}")
338+
print("Please run `pip install --upgrade ipwb` to upgrade.")

0 commit comments

Comments
 (0)