diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2020-12-30 21:25:56 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2020-12-30 21:25:56 +0300 |
commit | ac2ae65989f10a03f7a1009ddccddef07e8a9bac (patch) | |
tree | c5635a93159317b38b47961931500de7fdde3cef /blenderkit | |
parent | 4ad2e16b22b6cf93c26a1ee8f3fad336983d2385 (diff) |
BlenderKit: make HDR and Scene assets not experimental
correct links to tutorials for these 2 assets
free only becomes free first
A lot of logging calls instead of utils.p()
Diffstat (limited to 'blenderkit')
-rw-r--r-- | blenderkit/__init__.py | 58 | ||||
-rw-r--r-- | blenderkit/bkit_oauth.py | 6 | ||||
-rw-r--r-- | blenderkit/categories.py | 12 | ||||
-rw-r--r-- | blenderkit/download.py | 44 | ||||
-rw-r--r-- | blenderkit/paths.py | 4 | ||||
-rw-r--r-- | blenderkit/ratings.py | 4 | ||||
-rw-r--r-- | blenderkit/search.py | 25 | ||||
-rw-r--r-- | blenderkit/tasks_queue.py | 6 | ||||
-rw-r--r-- | blenderkit/ui.py | 2 | ||||
-rw-r--r-- | blenderkit/ui_panels.py | 2 | ||||
-rw-r--r-- | blenderkit/utils.py | 18 |
11 files changed, 91 insertions, 90 deletions
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py index 84cabcfe..6c690553 100644 --- a/blenderkit/__init__.py +++ b/blenderkit/__init__.py @@ -247,42 +247,26 @@ def asset_type_callback(self, context): ''' user_preferences = bpy.context.preferences.addons['blenderkit'].preferences - if user_preferences.experimental_features: - if self.down_up == 'SEARCH': - items = ( - ('MODEL', 'Models', 'Find models in the BlenderKit online database', 'OBJECT_DATAMODE', 0), - ('MATERIAL', 'Materials', 'Find materials in the BlenderKit online database', 'MATERIAL', 2), - # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), - ('SCENE', 'Scenes', 'Browse scenes', 'SCENE_DATA', 3), - ('HDR', 'Hdrs', 'Browse hdrs', 'WORLD', 4), - ('BRUSH', 'Brushes', 'Find brushes in the BlenderKit online database', 'BRUSH_DATA', 5) - ) - else: - items = ( - ('MODEL', 'Model', 'Upload a model to BlenderKit', 'OBJECT_DATAMODE', 0), - # ('SCENE', 'SCENE', 'Browse scenes', 'SCENE_DATA', 1), - ('MATERIAL', 'Material', 'Upload a material to BlenderKit', 'MATERIAL', 2), - # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), - ('SCENE', 'Scenes', 'Browse scenes', 'SCENE_DATA', 3), - ('HDR', 'Hdrs', 'Browse hdrs', 'WORLD', 4), - ('BRUSH', 'Brush', 'Upload a brush to BlenderKit', 'BRUSH_DATA', 5) - ) + if self.down_up == 'SEARCH': + items = ( + ('MODEL', 'Models', 'Find models in the BlenderKit online database', 'OBJECT_DATAMODE', 0), + ('MATERIAL', 'Materials', 'Find materials in the BlenderKit online database', 'MATERIAL', 2), + # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), + ('SCENE', 'Scenes', 'Browse scenes', 'SCENE_DATA', 3), + ('HDR', 'Hdrs', 'Browse hdrs', 'WORLD', 4), + ('BRUSH', 'Brushes', 'Find brushes in the BlenderKit online database', 'BRUSH_DATA', 5) + ) else: - if self.down_up == 'SEARCH': - items = ( - ('MODEL', 'Models', 'Find models in the BlenderKit online database', 'OBJECT_DATAMODE', 0), - ('MATERIAL', 'Materials', 'Find materials in the BlenderKit online database', 'MATERIAL', 2), - # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), - ('BRUSH', 'Brushes', 'Find brushes in the BlenderKit online database', 'BRUSH_DATA', 5) - ) - else: - items = ( - ('MODEL', 'Model', 'Upload a model to BlenderKit', 'OBJECT_DATAMODE', 0), - # ('SCENE', 'SCENE', 'Browse scenes', 'SCENE_DATA', 1), - ('MATERIAL', 'Material', 'Upload a material to BlenderKit', 'MATERIAL', 2), - # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), - ('BRUSH', 'Brush', 'Upload a brush to BlenderKit', 'BRUSH_DATA', 5) - ) + items = ( + ('MODEL', 'Model', 'Upload a model to BlenderKit', 'OBJECT_DATAMODE', 0), + # ('SCENE', 'SCENE', 'Browse scenes', 'SCENE_DATA', 1), + ('MATERIAL', 'Material', 'Upload a material to BlenderKit', 'MATERIAL', 2), + # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3), + ('SCENE', 'Scenes', 'Browse scenes', 'SCENE_DATA', 3), + ('HDR', 'Hdrs', 'Browse hdrs', 'WORLD', 4), + ('BRUSH', 'Brush', 'Upload a brush to BlenderKit', 'BRUSH_DATA', 5) + ) + return items @@ -525,6 +509,8 @@ class BlenderKitCommonSearchProps(object): ), default='1024', ) + free_only: BoolProperty(name="Free first", description="Show free models first", + default=False, update=search.search_update) unpack_files: BoolProperty(name="Unpack Files", description="Unpack files after download", @@ -1326,8 +1312,6 @@ class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps): update=search.search_update ) - free_only: BoolProperty(name="Free only", description="Show only free models", - default=False, update=search.search_update) # CONDITION search_condition: EnumProperty( diff --git a/blenderkit/bkit_oauth.py b/blenderkit/bkit_oauth.py index 59ed6c8b..6658244c 100644 --- a/blenderkit/bkit_oauth.py +++ b/blenderkit/bkit_oauth.py @@ -35,6 +35,8 @@ import bpy import threading import requests import time +import logging +bk_logger = logging.getLogger('blenderkit') from bpy.props import ( BoolProperty, @@ -59,7 +61,7 @@ def login_thread(signup=False): def login(signup, url, r_url, authenticator): auth_token, refresh_token, oauth_response = authenticator.get_new_token(register=signup, redirect_url=r_url) - utils.p('tokens retrieved') + bk_logger.debug('tokens retrieved') tasks_queue.add_task((write_tokens, (auth_token, refresh_token, oauth_response))) @@ -83,7 +85,7 @@ def refresh_token(api_key_refresh, url): def write_tokens(auth_token, refresh_token, oauth_response): - utils.p('writing tokens') + bk_logger.debug('writing tokens') preferences = bpy.context.preferences.addons['blenderkit'].preferences preferences.api_key_refresh = refresh_token preferences.api_key = auth_token diff --git a/blenderkit/categories.py b/blenderkit/categories.py index 81d9fd0b..a8f11bd2 100644 --- a/blenderkit/categories.py +++ b/blenderkit/categories.py @@ -34,6 +34,8 @@ import time import shutil import threading +import logging +bk_logger = logging.getLogger('blenderkit') def count_to_parent(parent): @@ -201,12 +203,12 @@ def fetch_categories(API_key, force = False): # global catfetch_counter # catfetch_counter += 1 - # utils.p('fetching categories: ', catfetch_counter) - # utils.p('age of cat file', catfile_age) + # bk_logger.debug('fetching categories: ', catfetch_counter) + # bk_logger.debug('age of cat file', catfile_age) try: # read categories only once per day maximum, or when forced to do so. if catfile_age > 86400 or force: - utils.p('requesting categories') + bk_logger.debug('requesting categories') r = rerequests.get(url, headers=headers) rdata = r.json() categories = rdata['results'] @@ -216,8 +218,8 @@ def fetch_categories(API_key, force = False): json.dump(categories, s, indent=4) tasks_queue.add_task((load_categories, ())) except Exception as e: - utils.p('category fetching failed') - utils.p(e) + bk_logger.debug('category fetching failed') + bk_logger.exception(e) if not os.path.exists(categories_filepath): source_path = paths.get_addon_file(subpath='data' + os.sep + 'categories.json') shutil.copy(source_path, categories_filepath) 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) diff --git a/blenderkit/paths.py b/blenderkit/paths.py index 95c5fd93..2a133064 100644 --- a/blenderkit/paths.py +++ b/blenderkit/paths.py @@ -31,8 +31,8 @@ BLENDERKIT_MANUAL = "https://youtu.be/1hVgcQhIAo8" BLENDERKIT_MODEL_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/upload/" BLENDERKIT_MATERIAL_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-material/" BLENDERKIT_BRUSH_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-brush/" -BLENDERKIT_HDR_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-brush/" -BLENDERKIT_SCENE_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-brush/" +BLENDERKIT_HDR_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-hdr/" +BLENDERKIT_SCENE_UPLOAD_INSTRUCTIONS_URL = "https://www.blenderkit.com/docs/uploading-scene/" BLENDERKIT_LOGIN_URL = "https://www.blenderkit.com/accounts/login" BLENDERKIT_OAUTH_LANDING_URL = "/oauth-landing/" BLENDERKIT_SIGNUP_URL = "https://www.blenderkit.com/accounts/register" diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py index 57c38087..3705f820 100644 --- a/blenderkit/ratings.py +++ b/blenderkit/ratings.py @@ -28,6 +28,8 @@ else: import bpy import requests, threading +import logging +bk_logger = logging.getLogger('blenderkit') from bpy.props import ( IntProperty, @@ -57,7 +59,7 @@ def pretty_print_POST(req): def upload_rating_thread(url, ratings, headers): ''' Upload rating thread function / disconnected from blender data.''' - utils.p('upload rating', url, ratings) + bk_logger.debug('upload rating', url, ratings) for rating_name, score in ratings: if (score != -1 and score != 0): rating_url = url + rating_name + '/' diff --git a/blenderkit/search.py b/blenderkit/search.py index 738582e6..da71835f 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -908,23 +908,26 @@ class Searcher(threading.Thread): requeststring += q + ':' + str(query[q]).lower() # result ordering: _score - relevance, score - BlenderKit score - + order = [] + if params['free_first']: + order = ['-is_free',] if query.get('query') is None and query.get('category_subtree') == None: # assumes no keywords and no category, thus an empty search that is triggered on start. # orders by last core file upload if query.get('verification_status') == 'uploaded': # for validators, sort uploaded from oldest - requeststring += '+order:created' + order.append('created') else: - requeststring += '+order:-last_upload' + order.append('-last_upload') elif query.get('author_id') is not None and utils.profile_is_validator(): - requeststring += '+order:-created' + order.append('-created') else: if query.get('category_subtree') is not None: - requeststring += '+order:-score,_score' + order.append('-score,_score') else: - requeststring += '+order:_score' + order.append('_score') + requeststring += '+order:' + ','.join(order) requeststring += '&addon_version=%s' % params['addon_version'] if params.get('scene_uuid') is not None: @@ -1123,8 +1126,9 @@ def build_query_model(): else: query["model_style"] = props.search_style_other - if props.free_only: - query["is_free"] = True + # the 'free_only' parametr gets moved to the search command and is used for ordering the assets as free first + # if props.free_only: + # query["is_free"] = True # if props.search_advanced: if props.search_condition != 'UNSPECIFIED': @@ -1160,7 +1164,7 @@ def build_query_scene(): def build_query_HDR(): '''use all search input to request results from server''' - props = bpy.context.scene.blenderkit_scene + props = bpy.context.scene.blenderkit_HDR query = { "asset_type": 'hdr', # "engine": props.search_engine, @@ -1392,7 +1396,8 @@ def search(category='', get_next=False, author_id=''): 'scene_uuid': bpy.context.scene.get('uuid', None), 'addon_version': version_checker.get_addon_version(), 'api_key': user_preferences.api_key, - 'get_next': get_next + 'get_next': get_next, + 'free_first': props.free_only } # if free_only: diff --git a/blenderkit/tasks_queue.py b/blenderkit/tasks_queue.py index 3fd4d285..fe6cac76 100644 --- a/blenderkit/tasks_queue.py +++ b/blenderkit/tasks_queue.py @@ -62,7 +62,7 @@ def add_task(task, wait = 0, only_last = False, fake_context = False, fake_conte def queue_worker(): - #utils.p('timer queue worker') + #bk_logger.debug('timer queue worker') time_step = 2.0 q = get_queue() @@ -83,7 +83,7 @@ def queue_worker(): else: back_to_queue.append(task) if len(stashed.keys())>1: - utils.p('task queue stashed task:', stashed) + bk_logger.debug('task queue stashed task:' +str(stashed)) #return tasks to que except for stashed for task in back_to_queue: q.put(task) @@ -100,7 +100,7 @@ def queue_worker(): task.wait-=time_step back_to_queue.append(task) else: - utils.p('task queue task:', task.command, task.arguments) + bk_logger.debug('task queue task:'+ str( task.command) +str( task.arguments)) try: if task.fake_context: fc = utils.get_fake_context(bpy.context, area_type = task.fake_context_area) diff --git a/blenderkit/ui.py b/blenderkit/ui.py index d2c28237..60e99c4f 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -1206,7 +1206,7 @@ class AssetBarOperator(bpy.types.Operator): do_search: BoolProperty(name="Run Search", description='', default=True, options={'SKIP_SAVE'}) keep_running: BoolProperty(name="Keep Running", description='', default=True, options={'SKIP_SAVE'}) - free_only: BoolProperty(name="Free Only", description='', default=False, options={'SKIP_SAVE'}) + free_only: BoolProperty(name="Free first", description='', default=False, options={'SKIP_SAVE'}) category: StringProperty( name="Category", diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index 6cccf42a..f3e0491e 100644 --- a/blenderkit/ui_panels.py +++ b/blenderkit/ui_panels.py @@ -93,7 +93,7 @@ def draw_not_logged_in(source, message='Please Login/Signup to use this feature' def draw_upload_common(layout, props, asset_type, context): - op = layout.operator("wm.url_open", text="Read upload instructions", + op = layout.operator("wm.url_open", text=f"Read {asset_type.lower()} upload instructions", icon='QUESTION') if asset_type == 'MODEL': op.url = paths.BLENDERKIT_MODEL_UPLOAD_INSTRUCTIONS_URL diff --git a/blenderkit/utils.py b/blenderkit/utils.py index ef3b5da6..09d6c77b 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -33,6 +33,10 @@ import os import sys import shutil import logging +import traceback +import inspect + +bk_logger = logging.getLogger('blenderkit') ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000 BELOW_NORMAL_PRIORITY_CLASS = 0x00004000 @@ -377,7 +381,7 @@ def get_brush_props(context): return None -def p(text, text1='', text2='', text3='', text4='', text5=''): +def p(text, text1='', text2='', text3='', text4='', text5='', level = 'DEBUG'): '''debug printing depending on blender's debug value''' if 1:#bpy.app.debug_value != 0: @@ -388,7 +392,7 @@ def p(text, text1='', text2='', text3='', text4='', text5=''): for t in texts: if t!= '': text += ' ' + str(t) - bk_logger = logging.getLogger('blenderkit') + bk_logger.debug(text) # print('---------------------\n') @@ -396,11 +400,11 @@ def p(text, text1='', text2='', text3='', text4='', text5=''): def copy_asset(fp1, fp2): '''synchronizes the asset between folders, including it's texture subdirectories''' if 1: - p('copy asset') - p(fp1, fp2) + bk_logger.debug('copy asset') + bk_logger.debug(fp1, fp2) if not os.path.exists(fp2): shutil.copyfile(fp1, fp2) - p('copied') + bk_logger.debug('copied') source_dir = os.path.dirname(fp1) target_dir = os.path.dirname(fp2) for subdir in os.scandir(source_dir): @@ -409,9 +413,9 @@ def copy_asset(fp1, fp2): target_subdir = os.path.join(target_dir, subdir.name) if os.path.exists(target_subdir): continue - p(subdir, target_subdir) + bk_logger.debug(subdir, target_subdir) shutil.copytree(subdir, target_subdir) - p('copied') + bk_logger.debug('copied') # except Exception as e: # print('BlenderKit failed to copy asset') |