Skip to content

Commit

Permalink
Fix semver comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
houtianze committed Mar 27, 2017
1 parent 3131413 commit 37473b7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Version History:

- 1.4.0: Correct Refresh server list; Add in update check

- 1.3.9: Add in queue for capturing JSONs returned from PCS
- 1.3.8: Don't output Auth Server failures if no `-d` specified
- 1.3.7: Allow passing leading dash arguments to downloader
Expand All @@ -11,7 +13,6 @@
- 1.3.1: Fix setup.py failures
- 1.3.0: Major change: Make bypy a real Python package

---
- 1.2.22: Fix "TypeError: b'xxxxxx' is not JSON serializable" for cache
- 1.2.21: Support aria2 downloading resuming (disable preallocation)
- 1.2.20: Fix an error in upload resuming; Add in retries for aria2
Expand Down
4 changes: 2 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Version History:
~~~~~~~~~~~~~~~~

- 1.4.0: Correct Refresh server list; Add in update check

- 1.3.9: Add in queue for capturing JSONs returned from PCS
- 1.3.8: Don't output Auth Server failures if no ``-d`` specified
- 1.3.7: Allow passing leading dash arguments to downloader
Expand All @@ -13,8 +15,6 @@ Version History:
- 1.3.1: Fix setup.py failures
- 1.3.0: Major change: Make bypy a real Python package

--------------

- 1.2.22: Fix "TypeError: b'xxxxxx' is not JSON serializable" for cache
- 1.2.21: Support aria2 downloading resuming (disable preallocation)
- 1.2.20: Fix an error in upload resuming; Add in retries for aria2
Expand Down
8 changes: 4 additions & 4 deletions bypy/bypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
joinpath, get_pcs_path, print_pcs_list, str2bool, str2int,
human_size, interpret_size, ls_time, ls_type,
makedir, removedir, movefile, removefile, getfilesize,
comp_semver,
MyPrettyPrinter)
from .chkreq import (check_requirements, CheckResult)
from .requester import RequestsRequester
Expand Down Expand Up @@ -107,7 +108,6 @@
except:
perr("Something seems wrong with the urllib3 installation.\nQuitting")
sys.exit(const.EFatal)
import semver

# global instance for non-member function to access
gbypyinst = None
Expand Down Expand Up @@ -417,7 +417,7 @@ def __init__(self,
min_ver_key = 'minimumRequiredVersion'
if min_ver_key in j:
minver = j[min_ver_key]
if semver.compare(const.__version__, minver) < 0:
if comp_semver(const.__version__, minver) < 0:
perr("Your current version ({}) is too low, "
"Minimum required version is {}.\n"
"Please run 'pip install -U bypy' to update and try again.".format(
Expand All @@ -430,9 +430,9 @@ def __init__(self,
recommended_ver_key = 'recommendedVersion'
if recommended_ver_key in j:
recver = j[recommended_ver_key]
if semver.compare(const.__version__, recver) < 0:
if comp_semver(const__version__, recver) < 0:
pr("Your current version ({}) is low, "
"It's recommended to update to version {}.\n"
"It's recommended to update to version {}.\n"
"Please run 'pip install -U bypy' to update.".format(
const.__version__, recver))
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion bypy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# https://packaging.python.org/single_source_version/
__title__ = 'bypy'
__version__ = '1.3.9'
__version__ = '1.4.0'
__author__ = 'Hou Tianze'
__license__ = 'MIT'
__desc__ ='Python client for Baidu Yun (Personal Cloud Storage) 百度云/百度网盘 Python 客户端'
Expand Down
20 changes: 20 additions & 0 deletions bypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ def run(self):
def startthread(func):
NewThread(func).start()

def inc_list_size(li, size = 3, filler = 0):
i = len(li)
while (i < size):
li.append(filler)
i += 1

def comp_semver(v1, v2):
v1a = v1.split('.')
v2a = v2.split('.')
v1ia = [int(i) for i in v1a]
v2ia = [int(i) for i in v2a]
inc_list_size(v1ia, 3)
inc_list_size(v2ia, 3)
i = 0
while (i < 3):
if v1ia[i] != v2ia[i]:
return v1ia[i] - v2ia[i]
i += 1
return 0

# NOT in use, see deque
class FixedSizeQueue(object):
def __init__(self, size = 1024):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def getmeta(path, encoding = 'utf8'):
'Programming Language :: Python',
'Topic :: Utilities',
'Topic :: Internet :: WWW/HTTP'],
install_requires = ['requests>=2.10.0', 'semver>=2.7.1'],
install_requires = ['requests>=2.10.0'],
include_package_data = True,
**meta
)
Expand Down
4 changes: 2 additions & 2 deletions update/update.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"comment": "Update info",
"recommendedVersion": "1.3.8",
"minimumRequiredVersion": "1.3.8"
"recommendedVersion": "1.4.0",
"minimumRequiredVersion": "1.4.0"
}

0 comments on commit 37473b7

Please sign in to comment.