From 950d891b53a9fcf3c0b94047371c0937680d33d6 Mon Sep 17 00:00:00 2001 From: Hou Tianze Date: Thu, 22 Mar 2018 02:32:40 +0800 Subject: [PATCH] - Close #437: Ensure cache loading/saving failures won't affect normal operations - Fix the bug that clean up code not called on exit - Version bump --- HISTORY.md | 1 + HISTORY.rst | 2 ++ bypy/bypy.py | 10 +++++++--- bypy/cached.py | 7 ++++--- bypy/const.py | 2 +- update/update.json | 4 ++-- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 62c4b5f..a2497d7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,6 @@ ### Version History: +- 1.6.1: Ensure cache loading/saving failures won't affect normal operations; Fix the bug that clean up code not called on exit - 1.6.0: Fix 1000 items limit for remote directory listing - 1.5.13: Fix multiprocess upload/syncup missing some files - 1.5.12: Add one more heroku server; Workaround "ValueError: unknown locale: UTF-8" on macOs (by xslidian) diff --git a/HISTORY.rst b/HISTORY.rst index 9ac039a..8b248b4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,8 @@ Version History: ~~~~~~~~~~~~~~~~ +- 1.6.1: Ensure cache loading/saving failures won't affect normal + operations; Fix the bug that clean up code not called on exit - 1.6.0: Fix 1000 items limit for remote directory listing - 1.5.13: Fix multiprocess upload/syncup missing some files - 1.5.12: Add one more heroku server; Workaround "ValueError: unknown diff --git a/bypy/bypy.py b/bypy/bypy.py index f7ed56b..096da96 100755 --- a/bypy/bypy.py +++ b/bypy/bypy.py @@ -381,6 +381,8 @@ class ByPy(object): # so if any code using this class can check the current verbose / debug level cached.verbose = self.verbose = verbose cached.debug = self.debug = debug + if not cached.usecache: + pinfo("Forced hash recaculation, hash cache won't be used") #TODO: SSL verification causes some much trouble for different Python version # I give up and disable it for good, or for bad @@ -491,7 +493,7 @@ class ByPy(object): "minimum required version is {}.\n" "Please run 'pip install -U bypy' to update and try again.".format( const.__version__, minver)) - quit(const.EUpdateNeeded) + self.quit(const.EUpdateNeeded) else: self.__setting[const.SettingKey_LastUpdateCheckTime] = nowsec self.savesetting() @@ -3561,6 +3563,7 @@ def clean_prog_files(cleanlevel, verbose, configdir = const.ConfigDir): def main(argv=None): # IGNORE:C0111 ''' Main Entry ''' + by = None reqres = check_requirements() if reqres == CheckResult.Error: perr("Requirement checking failed") @@ -3687,8 +3690,9 @@ def main(argv=None): # IGNORE:C0111 perr("Exception occurred:\n{}".format(formatex(ex))) pr("Abort") raise - - quit(result) + finally: + if by: + by.quit(result) if __name__ == "__main__": main() diff --git a/bypy/cached.py b/bypy/cached.py index 527dce9..c1ba32d 100644 --- a/bypy/cached.py +++ b/bypy/cached.py @@ -121,10 +121,10 @@ class cached(object): # periodically save to prevent loss in case of system crash now = time.time() if now - gvar.last_cache_save >= const.CacheSavePeriodInSec: + if cached.debug: + pdbg("Periodically saving Hash Cash") cached.savecache() gvar.last_cache_save = now - if cached.debug: - pdbg("Periodically saving Hash Cash") # merge the from 'fromc' cache into the 'to' cache. # 'keepto': @@ -197,7 +197,8 @@ class cached(object): cached.cacheloaded = True if cached.verbose: pr("Hash Cache File loaded.") - except (EOFError, TypeError, ValueError) as ex: + #except (EOFError, TypeError, ValueError, UnicodeDecodeError) as ex: + except Exception as ex: perr("Fail to load the Hash Cache, no caching.\n{}".format(formatex(ex))) cached.cache = existingcache else: diff --git a/bypy/const.py b/bypy/const.py index b874d6d..670b9db 100755 --- a/bypy/const.py +++ b/bypy/const.py @@ -12,7 +12,7 @@ import os # https://packaging.python.org/single_source_version/ __title__ = 'bypy' -__version__ = '1.6.0' +__version__ = '1.6.1' __author__ = 'Hou Tianze' __license__ = 'MIT' __desc__ = 'Python client for Baidu Yun (Personal Cloud Storage) 百度云/百度网盘 Python 客户端' diff --git a/update/update.json b/update/update.json index 149ae57..8b6b1b8 100644 --- a/update/update.json +++ b/update/update.json @@ -1,5 +1,5 @@ { "comment": "Update info", - "recommendedVersion": "1.6.0", - "minimumRequiredVersion": "1.6.0" + "recommendedVersion": "1.6.1", + "minimumRequiredVersion": "1.6.1" } -- GitLab