Fix for indirect lib linking and libraries being overwritten
This commit is contained in:
@@ -93,7 +93,7 @@ class FilePath:
|
|||||||
|
|
||||||
if VERBOSE:
|
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)
|
||||||
|
|
||||||
|
|
||||||
@@ -113,6 +113,9 @@ class FilePath:
|
|||||||
# {lib_id: {block_ids... }}
|
# {lib_id: {block_ids... }}
|
||||||
expand_codes_idlib = {}
|
expand_codes_idlib = {}
|
||||||
|
|
||||||
|
# libraries used by this blend
|
||||||
|
block_codes_idlib = set()
|
||||||
|
|
||||||
# only for this block
|
# only for this block
|
||||||
def _expand_codes_add_test(block, code):
|
def _expand_codes_add_test(block, code):
|
||||||
# return True, if the ID should be searched further
|
# return True, if the ID should be searched further
|
||||||
@@ -120,6 +123,7 @@ class FilePath:
|
|||||||
# we could investigate a better way...
|
# we could investigate a better way...
|
||||||
# Not to be accessing ID blocks at this point. but its harmless
|
# Not to be accessing ID blocks at this point. but its harmless
|
||||||
if code == b'ID':
|
if code == b'ID':
|
||||||
|
assert(code == block.code)
|
||||||
if recursive:
|
if recursive:
|
||||||
expand_codes_idlib.setdefault(block[b'lib'], set()).add(block[b'name'])
|
expand_codes_idlib.setdefault(block[b'lib'], set()).add(block[b'name'])
|
||||||
return False
|
return False
|
||||||
@@ -132,6 +136,7 @@ class FilePath:
|
|||||||
if _expand_codes_add_test(block, code):
|
if _expand_codes_add_test(block, code):
|
||||||
yield block
|
yield block
|
||||||
|
|
||||||
|
assert(block.code == code)
|
||||||
fn = ExpandID.expand_funcs.get(code)
|
fn = ExpandID.expand_funcs.get(code)
|
||||||
if fn is not None:
|
if fn is not None:
|
||||||
for sub_block in fn(block):
|
for sub_block in fn(block):
|
||||||
@@ -145,18 +150,38 @@ class FilePath:
|
|||||||
# set below
|
# set below
|
||||||
expand_codes_idlib = None
|
expand_codes_idlib = None
|
||||||
|
|
||||||
|
# never set
|
||||||
|
block_codes_idlib = None
|
||||||
|
|
||||||
def block_expand(block, code):
|
def block_expand(block, code):
|
||||||
yield block
|
yield block
|
||||||
|
|
||||||
|
# ------
|
||||||
|
# Define
|
||||||
|
#
|
||||||
|
# - iter_blocks_id(code)
|
||||||
|
# - iter_blocks_idlib()
|
||||||
if block_codes is None:
|
if block_codes is None:
|
||||||
def iter_blocks_id(code):
|
def iter_blocks_id(code):
|
||||||
return blend.find_blocks_from_code(code)
|
return blend.find_blocks_from_code(code)
|
||||||
|
|
||||||
|
def iter_blocks_idlib():
|
||||||
|
return blend.find_blocks_from_code(b'LI')
|
||||||
else:
|
else:
|
||||||
def iter_blocks_id(code):
|
def iter_blocks_id(code):
|
||||||
for block in blend.find_blocks_from_code(code):
|
for block in blend.find_blocks_from_code(code):
|
||||||
if block[b'id.name'] in block_codes:
|
if block[b'id.name'] in block_codes:
|
||||||
yield from block_expand(block, code)
|
yield from block_expand(block, code)
|
||||||
|
|
||||||
|
if block_codes_idlib is not None:
|
||||||
|
def iter_blocks_idlib():
|
||||||
|
for block in blend.find_blocks_from_code(b'LI'):
|
||||||
|
if block[b'name'] in block_codes_idlib:
|
||||||
|
yield from block_expand(block, b'LI')
|
||||||
|
else:
|
||||||
|
def iter_blocks_idlib():
|
||||||
|
return blend.find_blocks_from_code(b'LI')
|
||||||
|
|
||||||
if temp_remap_cb is not None:
|
if temp_remap_cb is not None:
|
||||||
filepath_tmp = temp_remap_cb(filepath, level)
|
filepath_tmp = temp_remap_cb(filepath, level)
|
||||||
else:
|
else:
|
||||||
@@ -210,8 +235,12 @@ class FilePath:
|
|||||||
lib_all.append((lib_path, lib_block_codes))
|
lib_all.append((lib_path, lib_block_codes))
|
||||||
# import IPython; IPython.embed()
|
# import IPython; IPython.embed()
|
||||||
|
|
||||||
|
# ensure we expand indirect linked libs
|
||||||
|
if block_codes_idlib is not None:
|
||||||
|
block_codes_idlib.add(lib_path)
|
||||||
|
|
||||||
# do this after, incase we mangle names above
|
# do this after, incase we mangle names above
|
||||||
for block in iter_blocks_id(b'LI'):
|
for block in iter_blocks_idlib():
|
||||||
yield from FilePath.from_block(block, basedir, rootdir, level)
|
yield from FilePath.from_block(block, basedir, rootdir, level)
|
||||||
|
|
||||||
blend.close()
|
blend.close()
|
||||||
@@ -502,6 +531,7 @@ def pack(blendfile_src, blendfile_dst):
|
|||||||
path_copy_files = set()
|
path_copy_files = set()
|
||||||
|
|
||||||
SUBDIR = b'data'
|
SUBDIR = b'data'
|
||||||
|
TEMP_SUFFIX = b'@'
|
||||||
|
|
||||||
if TIMEIT:
|
if TIMEIT:
|
||||||
import time
|
import time
|
||||||
@@ -514,9 +544,11 @@ def pack(blendfile_src, blendfile_dst):
|
|||||||
filepath = utils.compatpath(filepath)
|
filepath = utils.compatpath(filepath)
|
||||||
|
|
||||||
if level == 0:
|
if level == 0:
|
||||||
filepath_tmp = os.path.join(base_dir_dst, os.path.basename(filepath)) + b'@'
|
filepath_tmp = os.path.join(base_dir_dst, os.path.basename(filepath)) + TEMP_SUFFIX
|
||||||
else:
|
else:
|
||||||
filepath_tmp = os.path.join(base_dir_dst, SUBDIR, os.path.basename(filepath)) + b'@'
|
filepath_tmp = os.path.join(base_dir_dst, SUBDIR, os.path.basename(filepath)) + TEMP_SUFFIX
|
||||||
|
|
||||||
|
filepath_tmp = os.path.normpath(filepath_tmp)
|
||||||
|
|
||||||
# only overwrite once (allows us to )
|
# only overwrite once (allows us to )
|
||||||
if filepath_tmp not in path_temp_files:
|
if filepath_tmp not in path_temp_files:
|
||||||
@@ -567,10 +599,15 @@ def pack(blendfile_src, blendfile_dst):
|
|||||||
path_temp_files.remove(blendfile_dst_tmp)
|
path_temp_files.remove(blendfile_dst_tmp)
|
||||||
|
|
||||||
for fn in path_temp_files:
|
for fn in path_temp_files:
|
||||||
# strip '@'
|
# strip TEMP_SUFFIX
|
||||||
shutil.move(fn, fn[:-1])
|
shutil.copyfile(fn, fn[:-1])
|
||||||
|
|
||||||
for src, dst in path_copy_files:
|
for src, dst in path_copy_files:
|
||||||
|
if dst + TEMP_SUFFIX in path_temp_files:
|
||||||
|
continue
|
||||||
|
|
||||||
|
assert(b'.blend' not in dst)
|
||||||
|
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
print(" Source missing! %r" % src)
|
print(" Source missing! %r" % src)
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user