Fix for committing paths which start out with absolute remapping "_" prefix

This commit is contained in:
2014-12-03 17:20:55 +01:00
parent 2b7cb9ed7a
commit 4880615660
2 changed files with 68 additions and 16 deletions

View File

@@ -505,27 +505,68 @@ class bam_commands:
print("Nothing to commit!")
return
# we need to update paths_remap as we go
with open(os.path.join(session_rootdir, ".bam_paths_remap.json")) as f:
paths_remap = json.load(f)
paths_remap_relbase = paths_remap.get(".", "")
def remap_cb(f, data):
# check for the absolute path hint
if f.startswith(b'//_'):
proj_base_b = data
return b'//' + os.path.relpath(f[3:], proj_base_b)
return None
for f_rel, f_abs in list(paths_modified.items()):
# we may want to be more clever here
deps = deps_remap.get(f_rel)
if deps:
# ----
# Remap!
if 1:
f_abs_remap = os.path.join(basedir_temp, f_rel)
dir_remap = os.path.dirname(f_abs_remap)
os.makedirs(dir_remap, exist_ok=True)
# final location in the project
f_rel_in_proj = paths_remap.get(f_rel)
if f_rel_in_proj is None:
if paths_remap_relbase:
f_rel_in_proj = os.path.join(paths_remap_relbase, f_rel)
else:
f_rel_in_proj = f_rel
proj_base_b = os.path.dirname(f_rel_in_proj).encode("utf-8")
import blendfile_pack_restore
blendfile_pack_restore.blendfile_remap(
f_abs.encode('utf-8'),
dir_remap.encode('utf-8'),
deps,
deps_remap_cb=remap_cb,
deps_remap_cb_userdata=proj_base_b,
)
if os.path.exists(f_abs_remap):
f_abs = f_abs_remap
paths_modified[f_rel] = f_abs
else:
deps = deps_remap.get(f_rel)
if deps:
# ----
# remap!
f_abs_remap = os.path.join(basedir_temp, f_rel)
dir_remap = os.path.dirname(f_abs_remap)
os.makedirs(dir_remap, exist_ok=True)
import blendfile_pack_restore
blendfile_pack_restore.blendfile_remap(
f_abs.encode('utf-8'),
dir_remap.encode('utf-8'),
deps,
)
if os.path.exists(f_abs_remap):
f_abs = f_abs_remap
paths_modified[f_rel] = f_abs
# -------------------------
print("Now make a zipfile")
import zipfile
@@ -547,9 +588,6 @@ class bam_commands:
sort_keys=True, indent=4, separators=(',', ': '),
).encode('utf-8'))
with open(os.path.join(session_rootdir, ".bam_paths_remap.json")) as f:
paths_remap = json.load(f)
paths_remap_subset = {k: v for k, v in paths_remap.items() if k in paths_modified}
paths_remap_subset.update(paths_remap_subset_add)
write_dict_as_json(".bam_paths_remap.json", paths_remap_subset)

View File

@@ -29,7 +29,11 @@ VERBOSE = 1
import blendfile_path_walker
def blendfile_remap(blendfile_src, blendpath_dst, deps_remap):
def blendfile_remap(
blendfile_src, blendpath_dst,
deps_remap=None, deps_remap_cb=None,
deps_remap_cb_userdata=None,
):
import os
def temp_remap_cb(filepath, level):
@@ -56,12 +60,22 @@ def blendfile_remap(blendfile_src, blendpath_dst, deps_remap):
# path_dst_final - current path in blend.
# path_src_orig - original path from JSON.
path_dst_final = fp.filepath.decode('utf-8')
path_src_orig = deps_remap.get(path_dst_final)
if path_src_orig is not None:
fp.filepath = path_src_orig.encode('utf-8')
if VERBOSE:
print(" Remapping:", path_dst_final, "->", path_src_orig)
path_dst_final_b = fp.filepath
# support 2 modes, callback or dictionary
if deps_remap_cb is not None:
path_src_orig = deps_remap_cb(path_dst_final_b, deps_remap_cb_userdata)
if path_src_orig is not None:
fp.filepath = path_src_orig
if VERBOSE:
print(" Remapping:", path_dst_final_b, "->", path_src_orig)
else:
path_dst_final = path_dst_final_b.decode('utf-8')
path_src_orig = deps_remap.get(path_dst_final)
if path_src_orig is not None:
fp.filepath = path_src_orig.encode('utf-8')
if VERBOSE:
print(" Remapping:", path_dst_final, "->", path_src_orig)
def pack_restore(blendfile_dir_src, blendfile_dir_dst, pathmap):