More control over logging + added extra DEBUG level

This commit is contained in:
2017-04-05 12:37:53 +02:00
parent 4c0de51d2a
commit c43248a235

View File

@@ -19,10 +19,13 @@
# ***** END GPL LICENCE BLOCK ***** # ***** END GPL LICENCE BLOCK *****
import os import os
import logging
from . import blendfile from . import blendfile
# gives problems with scripts that use stdout, for testing 'bam deps' for eg. # gives problems with scripts that use stdout, for testing 'bam deps' for eg.
VERBOSE = False # os.environ.get('BAM_VERBOSE', False) DEBUG = False
VERBOSE = DEBUG or False # os.environ.get('BAM_VERBOSE', False)
TIMEIT = False TIMEIT = False
USE_ALEMBIC_BRANCH = True USE_ALEMBIC_BRANCH = True
@@ -63,12 +66,14 @@ class C_defs:
if USE_ALEMBIC_BRANCH: if USE_ALEMBIC_BRANCH:
CACHE_LIBRARY_SOURCE_CACHE = 1 CACHE_LIBRARY_SOURCE_CACHE = 1
log_deps = logging.getLogger("path_walker")
log_deps.setLevel({
(True, True): logging.DEBUG,
(False, True): logging.INFO,
(False, False): logging.WARNING
}[DEBUG, VERBOSE])
if VERBOSE: if VERBOSE:
import logging
log_deps = logging.getLogger("path_walker")
del logging
def set_as_str(s): def set_as_str(s):
if s is None: if s is None:
return "None" return "None"
@@ -257,14 +262,15 @@ class FilePath:
filepath = os.path.abspath(filepath) filepath = os.path.abspath(filepath)
if VERBOSE: indent_str = " " * level
indent_str = " " * level # print(indent_str + "Opening:", filepath)
# print(indent_str + "Opening:", filepath) # print(indent_str + "... blocks:", block_codes)
# print(indent_str + "... blocks:", block_codes)
log_deps.info("~") log = log_deps.getChild('visit_from_blend')
log_deps.info("%s%s" % (indent_str, filepath.decode('utf-8'))) log.info("~")
log_deps.info("%s%s" % (indent_str, set_as_str(block_codes))) log.info("%sOpening: %s", indent_str, filepath)
if VERBOSE:
log.info("%s blocks: %s", indent_str, set_as_str(block_codes))
blendfile_level_cb_enter, blendfile_level_cb_exit = blendfile_level_cb blendfile_level_cb_enter, blendfile_level_cb_exit = blendfile_level_cb
@@ -421,7 +427,7 @@ class FilePath:
# print("A:", expand_addr_visit) # print("A:", expand_addr_visit)
# print("B:", block_codes) # print("B:", block_codes)
if VERBOSE: if VERBOSE:
log_deps.info("%s%s" % (indent_str, set_as_str(expand_addr_visit))) log.info("%s expand_addr_visit=%s", indent_str, set_as_str(expand_addr_visit))
if recursive: if recursive:
@@ -511,8 +517,10 @@ class FilePath:
def from_block(block: blendfile.BlendFileBlock, basedir, extra_info, level): def from_block(block: blendfile.BlendFileBlock, basedir, extra_info, level):
assert(block.code != b'DATA') assert(block.code != b'DATA')
fn = FilePath._from_block_dict.get(block.code) fn = FilePath._from_block_dict.get(block.code)
if fn is not None: if fn is None:
yield from fn(block, basedir, extra_info, level) return
yield from fn(block, basedir, extra_info, level)
@staticmethod @staticmethod
def _from_block_OB(block, basedir, extra_info, level): def _from_block_OB(block, basedir, extra_info, level):