Skip to content

Commit

Permalink
Remove upload progress on combination failure; Tidy setup.py, release…
Browse files Browse the repository at this point in the history
….sh a bit; Add in new test token
  • Loading branch information
houtianze committed Jun 4, 2016
1 parent 77a6ec5 commit 8ea705f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
13 changes: 11 additions & 2 deletions bypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
EFatal = -1 # No way to continue
# internal errors
IEMD5NotFound = 31079 # File md5 not found, you should use upload API to upload the whole file.
IESuperfileCreationFailed = 31081 # superfile create failed

def bannerwarn(msg):
print('!' * 160)
Expand Down Expand Up @@ -1689,7 +1690,7 @@ def __request_work(self, url, pars, act, method, actargs = None, addtoken = True
self.pd("MD5 not found, rapidupload failed")
result = ec
# superfile create failed
elif ec == 31081: # and sc == 404:
elif ec == IESuperfileCreationFailed: # and sc == 404:
self.pd("Failed to combine files from MD5 slices (superfile create failed)")
result = ec
# errors that make retrying meaningless
Expand Down Expand Up @@ -2382,6 +2383,11 @@ def __upload_file_slices(self, localpath, remotepath, ondup = 'overwrite'):
cm = hashlib.md5(cslice)
if (binascii.hexlify(cm.digest()) == md):
self.pd("{} verified".format(md))
# TODO: a more rigorous check would be also verifying
# slices exist at Baidu Yun as well (rapidupload test?)
# but that's a bit complex. for now, we don't check
# this but simply delete the progress entry if later
# we got error combining the slices.
self.__slice_md5s.append(md)
else:
break
Expand Down Expand Up @@ -2428,7 +2434,10 @@ def __upload_file_slices(self, localpath, remotepath, ondup = 'overwrite'):
#self.pd("Sleep 2 seconds before combining, just to be safer.")
#time.sleep(2)
ec = self.__combine_file(remotepath, ondup = 'overwrite')
if ec == ENoError:
if ec == ENoError or ec == IESuperfileCreationFailed:
# we delete the upload progress entry also when we can't combine
# the file, as it might be caused by the slices uploaded
# has expired / become invalid
self.__delete_progress_entry(fullpath)
return ec

Expand Down
23 changes: 20 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/sh

set -o errexit
#set -x

py2venv="$HOME/Documents/t/venv27"
py3venv="$HOME/Documents/t/venv34"
if [ ! -d "$py2venv" ]
then
python2 -m virtualenv "$py2venv"
fi

if [ ! -d "$py3venv" ]
then
python3 -m venv "$py3venv"
fi

actual=0
build=0
Expand Down Expand Up @@ -54,7 +67,7 @@ fi
if [ "$build" -eq 1 ]
then
rm -Rf dist/*
python3 setup.py sdist bdist_wheel
python3 setup.py sdist # bdist_wheel
fi

uploadcmd="twine upload dist/* $repoopt"
Expand All @@ -67,12 +80,16 @@ fi

if [ "$install" -eq 1 ]
then
. ~/Documents/t/venv27/bin/activate
. "$py2venv/bin/activate"
pip install requests
pip install pypandoc
pip install -U bypy $indexopt
bypy -V
bypy quota
deactivate
. ~/Documents/t/venv34/bin/activate
. "$py3venv/bin/activate"
pip install requests
pip install pypandoc
pip install -U bypy $indexopt
bypy -V
bypy quota
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
download_url='https://github.com/houtianze/bypy/tarball/' + bypy.__version__,
packages=find_packages(),
scripts=['bypy', 'bypy.py', 'bypy.py', 'bypygui.pyw'],
package_data = {
'' : ['*.md']
},
keywords = ['bypy', 'bypy.py', 'baidu pcs', 'baidu yun', 'baidu pan', 'baidu netdisk',
'baidu cloud storage', 'baidu personal cloud storage',
'百度云', '百度云盘', '百度网盘', '百度个人云存储'],
Expand All @@ -41,6 +44,7 @@
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: Python',
'Topic :: Utilities',
'Topic :: Internet :: WWW/HTTP'],
Expand Down
8 changes: 4 additions & 4 deletions test/bypy.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"access_token": "21.06c2e563282c46974ad61951683be021.2592000.1455905234.2844184044-1572671",
"access_token": "21.e31ccb672f0684d5c6998caccac0f070.2592000.1467363468.2844184044-1572671",
"expires_in": 2592000,
"refresh_token": "22.7fe013049a3c92f394510939cf8fd082.315360000.1768673234.2844184044-1572671",
"refresh_token": "22.0d8af250129188a534a5d69db70c6036.315360000.1780131468.2844184044-1572671",
"scope": "basic netdisk",
"session_key": "9mnRdL2RvPCBzq5w/scHBXyoVPfInIVxg8Emvx5kX3ehUNVm8cyak0RwgYLQbE++Egi7SsPQVaWNvW8o2JlrgMvZ30YAu6f4fg==",
"session_secret": "62da2548407f1d4370582f3a31ce19e6"
"session_key": "9mnRIQGoss/MDrBOxXIrAK30k/Iz00STS+0QIdSGDsvMS9ZI9O7iotGImQMj6yXoXkfytw5q9Th+D8fdfNdIs51Yy9nJmc01fA==",
"session_secret": "1325d06d0508db7df06a14425d066c72"
}

0 comments on commit 8ea705f

Please sign in to comment.