|
13 | 13 | import logging
|
14 | 14 | import platform
|
15 | 15 |
|
16 |
| -from six.moves.urllib.request import urlopen |
| 16 | +from urllib.request import urlopen |
| 17 | +from urllib.error import URLError |
| 18 | + |
17 | 19 | import json
|
18 |
| -from .__init__ import __version__ as ipwbVersion |
| 20 | +from .__init__ import __version__ as ipwb_version |
19 | 21 |
|
20 | 22 | from ipfshttpclient.exceptions import ConnectionError, AddressError
|
21 | 23 | from multiaddr.exceptions import StringParseError
|
@@ -314,22 +316,23 @@ def unsurt(surt):
|
314 | 316 | return surt
|
315 | 317 |
|
316 | 318 |
|
317 |
| -def compareCurrentAndLatestIPWBVersions(): |
| 319 | +def get_latest_version(): |
318 | 320 | 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 |
327 | 325 |
|
328 |
| -def checkForUpdate(_): |
329 |
| - (current, latest) = compareCurrentAndLatestIPWBVersions() |
330 | 326 |
|
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