[e50b06d] master: io_blend_utils: Upgraded BAM from 1.1.3 â 1.1.4
Sybren A. Stüvel
noreply at git.blender.org
Wed Apr 12 11:15:00 CEST 2017
Commit: e50b06dde8eba0c7118c87aef4c4811d206f219a
Author: Sybren A. Stüvel
Date: Wed Apr 12 11:13:41 2017 +0200
Branches: master
https://developer.blender.org/rBAe50b06dde8eba0c7118c87aef4c4811d206f219a
io_blend_utils: Upgraded BAM from 1.1.3 → 1.1.4
Not only updated the wheel, but also updated the py files that originate
from the BAM Git repository.
===================================================================
M io_blend_utils/blend/blendfile.py
M io_blend_utils/blend/blendfile_path_walker.py
R075 io_blend_utils/blender_bam-1.1.3-py3-none-any.whl io_blend_utils/blender_bam-1.1.4-py3-none-any.whl
M io_blend_utils/utils/system.py
===================================================================
diff --git a/io_blend_utils/blend/blendfile.py b/io_blend_utils/blend/blendfile.py
index c7a83c3..e471bea 100644
--- a/io_blend_utils/blend/blendfile.py
+++ b/io_blend_utils/blend/blendfile.py
@@ -30,6 +30,10 @@ log = logging.getLogger("blendfile")
FILE_BUFFER_SIZE = 1024 * 1024
+class BlendFileError(Exception):
+ """Raised when there was an error reading/parsing a blend file."""
+
+
# -----------------------------------------------------------------------------
# module global routines
#
@@ -73,9 +77,9 @@ def open_blend(filename, access="rb"):
bfile.filepath_orig = filename
return bfile
else:
- raise Exception("filetype inside gzip not a blend")
+ raise BlendFileError("filetype inside gzip not a blend")
else:
- raise Exception("filetype not a blend or a gzip blend")
+ raise BlendFileError("filetype not a blend or a gzip blend")
def pad_up_4(offset):
@@ -143,11 +147,14 @@ class BlendFile:
self.blocks.append(block)
if not self.structs:
- raise Exception("No DNA1 block in file, this is not a valid .blend file!")
+ raise BlendFileError("No DNA1 block in file, this is not a valid .blend file!")
# cache (could lazy init, incase we never use?)
self.block_from_offset = {block.addr_old: block for block in self.blocks if block.code != b'ENDB'}
+ def __repr__(self):
+ return '<%s %r>' % (self.__class__.__qualname__, self.handle)
+
def __enter__(self):
return self
diff --git a/io_blend_utils/blend/blendfile_path_walker.py b/io_blend_utils/blend/blendfile_path_walker.py
index f900552..1c7b027 100644
--- a/io_blend_utils/blend/blendfile_path_walker.py
+++ b/io_blend_utils/blend/blendfile_path_walker.py
@@ -19,11 +19,16 @@
# ***** 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 = False
+USE_ALEMBIC_BRANCH = True
class C_defs:
@@ -61,17 +66,18 @@ 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"
- else:
- return (", ".join(sorted(i.decode('ascii') for i in sorted(s))))
+ return ", ".join(sorted(str(i) for i in s))
class FPElem:
@@ -256,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
@@ -395,7 +402,6 @@ class FilePath:
# store info to pass along with each iteration
extra_info = rootdir, os.path.basename(filepath)
- from . import blendfile
with blendfile.open_blend(filepath_tmp, "rb" if readonly else "r+b") as blend:
for code in blend.code_index.keys():
@@ -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:
@@ -508,11 +514,13 @@ class FilePath:
# (no expanding or following references)
@staticmethod
- def from_block(block, basedir, extra_info, level):
+ 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):
@@ -811,6 +819,7 @@ class ExpandID:
yield block.get_pointer(b'dup_group')
elif block_ren_as == C_defs.PART_DRAW_OB:
yield block.get_pointer(b'dup_ob')
+ yield from ExpandID._expand_generic_mtex(block)
@staticmethod
def expand_SC(block): # 'Scene'
diff --git a/io_blend_utils/blender_bam-1.1.3-py3-none-any.whl b/io_blend_utils/blender_bam-1.1.4-py3-none-any.whl
similarity index 75%
rename from io_blend_utils/blender_bam-1.1.3-py3-none-any.whl
rename to io_blend_utils/blender_bam-1.1.4-py3-none-any.whl
index 3115094..7535f82 100644
Binary files a/io_blend_utils/blender_bam-1.1.3-py3-none-any.whl and b/io_blend_utils/blender_bam-1.1.4-py3-none-any.whl differ
diff --git a/io_blend_utils/utils/system.py b/io_blend_utils/utils/system.py
index 970a646..313173e 100644
--- a/io_blend_utils/utils/system.py
+++ b/io_blend_utils/utils/system.py
@@ -72,6 +72,29 @@ def uuid_from_file(fn, block_size=1 << 20):
return hex(size)[2:] + sha1.hexdigest()
+def write_json_to_zip(zip_handle, path, data=None):
+ import json
+ zip_handle.writestr(
+ path,
+ json.dumps(
+ data,
+ check_circular=False,
+ # optional (pretty)
+ sort_keys=True, indent=4, separators=(',', ': '),
+ ).encode('utf-8'))
+
+
+def write_json_to_file(path, data):
+ import json
+ with open(path, 'w') as file_handle:
+ json.dump(
+ data, file_handle, ensure_ascii=False,
+ check_circular=False,
+ # optional (pretty)
+ sort_keys=True, indent=4, separators=(',', ': '),
+ )
+
+
def is_compressed_filetype(filepath):
"""
Use to check if we should compress files in a zip.
@@ -103,3 +126,18 @@ def is_compressed_filetype(filepath):
# '.zip',
}
+
+def is_subdir(path, directory):
+ """
+ Returns true if *path* in a subdirectory of *directory*.
+ """
+ import os
+ from os.path import normpath, normcase, sep
+ path = normpath(normcase(path))
+ directory = normpath(normcase(directory))
+ if len(path) > len(directory):
+ sep = sep.encode('ascii') if isinstance(directory, bytes) else sep
+ if path.startswith(directory.rstrip(sep) + sep):
+ return True
+ return False
+
More information about the Bf-extensions-cvs
mailing list