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