diff --git a/bam/blend/blendfile_path_walker.py b/bam/blend/blendfile_path_walker.py index abefb25..6e6f865 100644 --- a/bam/blend/blendfile_path_walker.py +++ b/bam/blend/blendfile_path_walker.py @@ -19,10 +19,13 @@ # ***** END GPL LICENCE BLOCK ***** import os +import logging + from . import blendfile # 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 USE_ALEMBIC_BRANCH = True @@ -63,12 +66,14 @@ class C_defs: if USE_ALEMBIC_BRANCH: 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: - import logging - log_deps = logging.getLogger("path_walker") - del logging - def set_as_str(s): if s is None: return "None" @@ -257,14 +262,15 @@ class FilePath: filepath = os.path.abspath(filepath) - if VERBOSE: - indent_str = " " * level - # print(indent_str + "Opening:", filepath) - # print(indent_str + "... blocks:", block_codes) + indent_str = " " * level + # print(indent_str + "Opening:", filepath) + # print(indent_str + "... blocks:", block_codes) - log_deps.info("~") - log_deps.info("%s%s" % (indent_str, filepath.decode('utf-8'))) - log_deps.info("%s%s" % (indent_str, set_as_str(block_codes))) + log = log_deps.getChild('visit_from_blend') + log.info("~") + 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 @@ -421,7 +427,7 @@ class FilePath: # print("A:", expand_addr_visit) # print("B:", block_codes) 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: @@ -511,8 +517,10 @@ class FilePath: def from_block(block: blendfile.BlendFileBlock, basedir, extra_info, level): assert(block.code != b'DATA') fn = FilePath._from_block_dict.get(block.code) - if fn is not None: - yield from fn(block, basedir, extra_info, level) + if fn is None: + return + + yield from fn(block, basedir, extra_info, level) @staticmethod def _from_block_OB(block, basedir, extra_info, level):