diff options
author | Vilem Duha <vilem.duha@gmail.com> | 2019-05-22 03:59:23 +0300 |
---|---|---|
committer | Vilem Duha <vilem.duha@gmail.com> | 2019-05-23 15:47:17 +0300 |
commit | 464dd1a50b3a17bd8e9b6b1f7ec4bc0bc27e7ed5 (patch) | |
tree | d6c5035a1ea1aabb8f546ca833d652c722998dde | |
parent | 68639b4d94012e7351dcef92f5b2135cc6d43f58 (diff) |
set a maximum number of retries for downloads.
-rw-r--r-- | blenderkit/download.py | 25 | ||||
-rw-r--r-- | blenderkit/ui_panels.py | 6 |
2 files changed, 23 insertions, 8 deletions
diff --git a/blenderkit/download.py b/blenderkit/download.py index 7bc04481..3eaa4e51 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -475,12 +475,9 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not if len(file_names) == 2: # todo this should try to check if both files exist and are ok. shutil.copyfile(file_names[0], file_names[1]) - print('appending asset') + utils.p('appending asset') # progress bars: - if bpy.context.scene['search results'] is not None: - for sres in bpy.context.scene['search results']: - if asset_data['id'] == sres['id']: - sres['downloaded'] = 100 + # we need to check if mouse isn't down, which means an operator can be running. # Especially for sculpt mode, where appending a brush during a sculpt stroke causes crasehes # @@ -495,6 +492,7 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not done = try_finished_append(asset_data, **tcom.passargs) if not done: at = asset_data['asset_type'] + tcom.passargs['retry_counter'] = tcom.passargs.get('retry_counter',0) +1 if at in ('model', 'material'): download(asset_data, **tcom.passargs) elif asset_data['asset_type'] == 'material': @@ -503,7 +501,12 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff, not download(asset_data, **tcom.passargs) elif asset_data['asset_type'] == 'brush' or asset_data['asset_type'] == 'texture': download(asset_data, **tcom.passargs) - print('finished download thread') + if bpy.context.scene['search results'] is not None and done: + for sres in bpy.context.scene['search results']: + if asset_data['id'] == sres['id']: + sres['downloaded'] = 100 + + utils.p('finished download thread') return .2 @@ -590,9 +593,15 @@ def download(asset_data, **kwargs): scene_id = get_scene_id() tcom = ThreadCom() - tcom.passargs = kwargs + if kwargs.get('retry_counter',0) > 3: + sprops = utils.get_search_props() + sprops.report = f"Maximum retries exceeded for {asset_data['name']}" + utils.p(sprops.report) + return + + # incoming data can be either directly dict from python, or blender id property # (recovering failed downloads on reload) if type(asset_data) == dict: @@ -654,7 +663,7 @@ def try_finished_append(asset_data, **kwargs): # location=None, material_target This means probably wrong download, so download should restart''' file_names = paths.get_download_filenames(asset_data) done = False - print('try to append allready existing asset') + utils.p('try to append allready existing asset') if len(file_names) > 0: if os.path.isfile(file_names[-1]): kwargs['name'] = asset_data['name'] diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index 88d14386..1a4b2e76 100644 --- a/blenderkit/ui_panels.py +++ b/blenderkit/ui_panels.py @@ -802,6 +802,12 @@ class VIEW3D_PT_blenderkit_downloads(Panel): row.label(text=asset_data['name']) row.label(text=str(int(tcom.progress)) + ' %') row.operator('scene.blenderkit_download_kill', text='', icon='CANCEL') + if tcom.passargs.get('retry_counter',0)>0: + row = layout.row() + row.label(text = 'failed. retrying ... ', icon='ERROR') + row.label(text = str(tcom.passargs["retry_counter"])) + + layout.separator() classess = ( |