Setting up and using Python's logging framework.
It's dubious whether logging.basicConfig() should be called here, so that call will probably be moved somewhere else.
This commit is contained in:
@@ -42,6 +42,8 @@ if 'pillar' in locals():
|
||||
else:
|
||||
from . import pillar, async_loop, gui
|
||||
|
||||
import logging
|
||||
|
||||
import bpy
|
||||
from bpy.types import AddonPreferences, Operator, WindowManager
|
||||
from bpy.props import StringProperty
|
||||
@@ -145,6 +147,8 @@ def register():
|
||||
name="Blender Cloud node UUID",
|
||||
default='') # empty == top-level of project
|
||||
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format='%(asctime)-15s %(levelname)8s %(name)s %(message)s')
|
||||
gui.register()
|
||||
|
||||
|
||||
|
@@ -2,26 +2,29 @@
|
||||
|
||||
import asyncio
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
import bpy
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def kick_async_loop(*args):
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
if loop.is_closed():
|
||||
print('{}: loop closed, stopping'.format(__name__))
|
||||
log.warning('loop closed, stopping')
|
||||
stop_async_loop()
|
||||
return
|
||||
|
||||
all_tasks = asyncio.Task.all_tasks()
|
||||
if not all_tasks:
|
||||
print('{}: no more scheduled tasks, stopping'.format(__name__))
|
||||
log.debug('no more scheduled tasks, stopping')
|
||||
stop_async_loop()
|
||||
return
|
||||
|
||||
if all(task.done() for task in all_tasks):
|
||||
print('{}: all tasks are done, fetching results and stopping.'.format(__name__))
|
||||
log.info('all tasks are done, fetching results and stopping.'.format(__name__))
|
||||
for task in all_tasks:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
@@ -43,6 +46,12 @@ def kick_async_loop(*args):
|
||||
|
||||
|
||||
def async_loop_handler() -> callable:
|
||||
"""Returns the asynchronous loop handler `kick_async_loop`
|
||||
|
||||
Only returns the function if it is installed as scene_update_pre handler, otherwise
|
||||
it returns None.
|
||||
"""
|
||||
|
||||
name = kick_async_loop.__name__
|
||||
for handler in bpy.app.handlers.scene_update_pre:
|
||||
if getattr(handler, '__name__', '') == name:
|
||||
@@ -61,3 +70,4 @@ def stop_async_loop():
|
||||
if handler is None:
|
||||
return
|
||||
bpy.app.handlers.scene_update_pre.remove(handler)
|
||||
log.debug('stopped async loop.')
|
||||
|
@@ -19,7 +19,9 @@
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
import bpy
|
||||
import bgl
|
||||
@@ -160,6 +162,7 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
||||
node_uuid = '' # Blender Cloud node UUID
|
||||
async_task = None # asyncio task for fetching thumbnails
|
||||
timer = None
|
||||
log = logging.getLogger('%s.BlenderCloudBrowser' % __name__)
|
||||
|
||||
_menu_item_lock = threading.Lock()
|
||||
current_path = ''
|
||||
@@ -172,11 +175,9 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
if context.area.type != 'VIEW_3D':
|
||||
self.report({'WARNING'}, "View3D not found, cannot show asset flinger")
|
||||
self.report({'WARNING'}, "View3D not found, cannot show Blender Cloud browser")
|
||||
return {'CANCELLED'}
|
||||
|
||||
print('Area is %s' % context.area)
|
||||
|
||||
wm = context.window_manager
|
||||
self.thumbnails_cache = wm.thumbnails_cache
|
||||
self.project_uuid = wm.blender_cloud_project
|
||||
@@ -241,10 +242,12 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
||||
self.async_task.result() # This re-raises any exception of the task.
|
||||
|
||||
def _finish(self, context):
|
||||
self.log.debug('Finishing the modal operator')
|
||||
self._stop_async_task()
|
||||
bpy.types.SpaceView3D.draw_handler_remove(self._draw_handle, 'WINDOW')
|
||||
context.window_manager.event_timer_remove(self.timer)
|
||||
context.area.tag_redraw()
|
||||
self.log.debug('Modal operator finished')
|
||||
|
||||
def clear_images(self):
|
||||
"""Removes all images we loaded from Blender's memory."""
|
||||
|
@@ -2,6 +2,7 @@ import asyncio
|
||||
import sys
|
||||
import os
|
||||
import functools
|
||||
import logging
|
||||
|
||||
# Add our shipped Pillar SDK wheel to the Python path
|
||||
if not any('pillar_sdk' in path for path in sys.path):
|
||||
@@ -17,6 +18,7 @@ import pillarsdk.exceptions
|
||||
import pillarsdk.utils
|
||||
|
||||
_pillar_api = None # will become a pillarsdk.Api object.
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class UserNotLoggedInError(RuntimeError):
|
||||
@@ -75,10 +77,10 @@ async def get_project_uuid(project_url: str) -> str:
|
||||
try:
|
||||
project = await loop.run_in_executor(None, find_one)
|
||||
except pillarsdk.exceptions.ResourceNotFound:
|
||||
print('Project with URL %r does not exist' % project_url)
|
||||
log.error('Project with URL %r does not exist', project_url)
|
||||
return None
|
||||
|
||||
print('Found project %r' % project)
|
||||
log.info('Found project %r', project)
|
||||
return project['_id']
|
||||
|
||||
|
||||
@@ -218,10 +220,12 @@ async def parent_node_uuid(node_uuid: str) -> str:
|
||||
api = pillar_api()
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
log.debug('Finding parent node for node %r', node_uuid)
|
||||
find_node = functools.partial(pillarsdk.Node.find, node_uuid,
|
||||
{'projection': {'parent': 1}}, api=api)
|
||||
node = await loop.run_in_executor(None, find_node)
|
||||
if node is None:
|
||||
log.debug('Unable to find node %r, returning empty parent', node_uuid)
|
||||
return ''
|
||||
|
||||
print('Found node {}'.format(node))
|
||||
|
Reference in New Issue
Block a user