Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'blenderkit/download.py')
-rw-r--r--blenderkit/download.py44
1 files changed, 23 insertions, 21 deletions
diff --git a/blenderkit/download.py b/blenderkit/download.py
index 0e5cdc0a..e0d05833 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -36,6 +36,8 @@ import requests
import shutil, sys, os
import uuid
import copy
+import logging
+bk_logger = logging.getLogger('blenderkit')
import bpy
from bpy.props import (
@@ -241,7 +243,7 @@ def report_usages():
scene['assets reported'] = assets_reported
if new_assets_count == 0:
- utils.p('no new assets were added')
+ bk_logger.debug('no new assets were added')
return;
usage_report = {
'scene': sid,
@@ -513,10 +515,10 @@ def replace_resolution_linked(file_paths, asset_data):
if not l['asset_data']['assetBaseId'] == asset_data['assetBaseId']:
continue;
- utils.p('try to re-link library')
+ bk_logger.debug('try to re-link library')
if not os.path.isfile(file_paths[-1]):
- utils.p('library file doesnt exist')
+ bk_logger.debug('library file doesnt exist')
break;
l.filepath = os.path.join(os.path.dirname(l.filepath), file_name)
l.name = file_name
@@ -549,7 +551,7 @@ def replace_resolution_appended(file_paths, asset_data, resolution):
if not os.path.exists(fpabs):
# this currently handles .png's that have been swapped to .jpg's during resolution generation process.
# should probably also handle .exr's and similar others.
- # utils.p('need to find a replacement')
+ # bk_logger.debug('need to find a replacement')
base, ext = os.path.splitext(fp)
if resolution == 'blend' and i.get('original_extension'):
fp = base + i.get('original_extension')
@@ -572,7 +574,7 @@ def timer_update():
Finished downloads are processed and linked/appended to scene.
'''
global download_threads
- # utils.p('timer download')
+ # bk_logger.debug('timer download')
if len(download_threads) == 0:
return 2.0
@@ -601,7 +603,7 @@ def timer_update():
file_paths = paths.get_download_filepaths(asset_data, tcom.passargs['resolution'])
if len(file_paths) == 0:
- utils.p('library names not found in asset data after download')
+ bk_logger.debug('library names not found in asset data after download')
download_threads.remove(threaddata)
break;
@@ -620,7 +622,7 @@ def timer_update():
utils.copy_asset(file_paths[0], file_paths[1])
# shutil.copyfile(file_paths[0], file_paths[1])
- utils.p('appending asset')
+ bk_logger.debug('appending asset')
# progress bars:
# we need to check if mouse isn't down, which means an operator can be running.
@@ -660,7 +662,7 @@ def timer_update():
if asset_data['id'] == sres['id']:
sres['downloaded'] = 100
- utils.p('finished download thread')
+ bk_logger.debug('finished download thread')
return .5
@@ -691,7 +693,7 @@ def download_file(asset_data, resolution='blend'):
if check_existing(asset_data, resolution=resolution):
# this sends the thread for processing, where another check should occur, since the file might be corrupted.
- utils.p('not downloading, already in db')
+ bk_logger.debug('not downloading, already in db')
return file_name
preferences = bpy.context.preferences.addons['blenderkit'].preferences
api_key = preferences.api_key
@@ -776,19 +778,19 @@ class Downloader(threading.Thread):
if check_existing(asset_data, resolution=self.resolution) and not tcom.passargs.get('delete'):
# this sends the thread for processing, where another check should occur, since the file might be corrupted.
tcom.downloaded = 100
- utils.p('not downloading, trying to append again')
+ bk_logger.debug('not downloading, trying to append again')
return
file_name = paths.get_download_filepaths(asset_data, self.resolution)[0] # prefer global dir if possible.
# for k in asset_data:
# print(asset_data[k])
if self.stopped():
- utils.p('stopping download: ' + asset_data['name'])
+ bk_logger.debug('stopping download: ' + asset_data['name'])
return
download_canceled = False
with open(file_name, "wb") as f:
- utils.p("Downloading %s" % file_name)
+ bk_logger.debug("Downloading %s" % file_name)
headers = utils.get_headers(api_key)
res_file_info, self.resolution = paths.get_res_file(asset_data, self.resolution)
response = requests.get(res_file_info['url'], stream=True)
@@ -799,7 +801,7 @@ class Downloader(threading.Thread):
tcom.report = response.content
download_canceled = True
else:
- # utils.p(total_length)
+ # bk_logger.debug(total_length)
if int(total_length) < 1000: # means probably no file returned.
tasks_queue.add_task((ui.add_report, (response.content, 20, colors.RED)))
@@ -822,7 +824,7 @@ class Downloader(threading.Thread):
tcom.progress = int(100 * tcom.downloaded / tcom.file_size)
f.write(data)
if self.stopped():
- utils.p('stopping download: ' + asset_data['name'])
+ bk_logger.debug('stopping download: ' + asset_data['name'])
download_canceled = True
break
@@ -862,7 +864,7 @@ def download(asset_data, **kwargs):
sprops.report = report
ui.add_report(report, 5, colors.RED)
- utils.p(sprops.report)
+ bk_logger.debug(sprops.report)
return
# incoming data can be either directly dict from python, or blender id property
@@ -908,7 +910,7 @@ def check_existing(asset_data, resolution='blend', can_return_others=False):
file_names = paths.get_download_filepaths(asset_data, resolution, can_return_others=can_return_others)
- utils.p('check if file already exists', file_names)
+ bk_logger.debug('check if file already exists'+ str( file_names))
if len(file_names) == 2:
# TODO this should check also for failed or running downloads.
# If download is running, assign just the running thread. if download isn't running but the file is wrong size,
@@ -929,7 +931,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_filepaths(asset_data, kwargs['resolution'])
done = False
- utils.p('try to append already existing asset')
+ bk_logger.debug('try to append already existing asset')
if len(file_names) > 0:
if os.path.isfile(file_names[-1]):
kwargs['name'] = asset_data['name']
@@ -991,7 +993,7 @@ def duplicate_asset(source, **kwargs):
Duplicate asset when it's already appended in the scene,
so that blender's append doesn't create duplicated data.
'''
- utils.p('duplicate asset instead')
+ bk_logger.debug('duplicate asset instead')
# we need to save selection
sel = utils.selection_get()
bpy.ops.object.select_all(action='DESELECT')
@@ -1129,7 +1131,7 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None, resolution='blend
tcom.error = True
elif r.status_code >= 500:
- # utils.p(r.text)
+ # bk_logger.debug(r.text)
if tcom is not None:
tcom.report = 'Server error'
tcom.error = True
@@ -1156,8 +1158,8 @@ def start_download(asset_data, **kwargs):
# check if there are files already. This check happens 2x once here(for free assets),
# once in thread(for non-free)
fexists = check_existing(asset_data, resolution=kwargs['resolution'])
- utils.p('does file exist?', fexists)
- utils.p('asset is in scene', ain)
+ bk_logger.debug('does file exist?'+ str( fexists))
+ bk_logger.debug('asset is in scene' + str(ain))
if ain and not kwargs.get('replace_resolution'):
# this goes to appending asset - where it should duplicate the original asset already in scene.
done = try_finished_append(asset_data, **kwargs)