support passing arguments to template create commands
This commit is contained in:
@@ -23,11 +23,11 @@ def _clear_blend():
|
|||||||
bpy_data_iter.remove(id_data)
|
bpy_data_iter.remove(id_data)
|
||||||
|
|
||||||
|
|
||||||
def create_blank(blendfile_root, deps):
|
def create_blank(blendfile_root, _create_data, deps):
|
||||||
assert(isinstance(deps, list))
|
assert(isinstance(deps, list))
|
||||||
|
|
||||||
|
|
||||||
def create_image_single(blendfile_root, deps):
|
def create_image_single(blendfile_root, _create_data, deps):
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
path = "//my_image.png"
|
path = "//my_image.png"
|
||||||
@@ -39,7 +39,7 @@ def create_image_single(blendfile_root, deps):
|
|||||||
image.save()
|
image.save()
|
||||||
|
|
||||||
|
|
||||||
def create_from_files(blendfile_root, deps):
|
def create_from_files(blendfile_root, _create_data, deps):
|
||||||
"""Create a blend file which users all sub-directories.
|
"""Create a blend file which users all sub-directories.
|
||||||
(currently images only)
|
(currently images only)
|
||||||
"""
|
"""
|
||||||
@@ -62,12 +62,20 @@ def create_from_files(blendfile_root, deps):
|
|||||||
deps.append(f_abs)
|
deps.append(f_abs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
blendfile, blendfile_root, blendfile_deps_json, create_id, returncode = sys.argv[-5:]
|
blendfile, blendfile_root, blendfile_deps_json, create_id, create_data, returncode = sys.argv[-6:]
|
||||||
returncode = int(returncode)
|
returncode = int(returncode)
|
||||||
create_fn = globals()[create_id]
|
create_fn = globals()[create_id]
|
||||||
|
|
||||||
|
if create_data != "NONE":
|
||||||
|
with open(create_data, 'r') as f:
|
||||||
|
import json
|
||||||
|
create_data = json.load(f)
|
||||||
|
del json
|
||||||
|
|
||||||
# ----
|
# ----
|
||||||
import bpy
|
import bpy
|
||||||
# no need for blend1's
|
# no need for blend1's
|
||||||
@@ -81,7 +89,7 @@ if __name__ == "__main__":
|
|||||||
_clear_blend()
|
_clear_blend()
|
||||||
deps = []
|
deps = []
|
||||||
|
|
||||||
create_fn(blendfile_root, deps)
|
create_fn(blendfile_root, create_data, deps)
|
||||||
|
|
||||||
if deps:
|
if deps:
|
||||||
with open(blendfile_deps_json, 'w') as f:
|
with open(blendfile_deps_json, 'w') as f:
|
||||||
|
@@ -337,10 +337,25 @@ def _dbg_dump_path(path):
|
|||||||
print("\n".join(sorted(stdout.decode('utf-8').split("\n"))))
|
print("\n".join(sorted(stdout.decode('utf-8').split("\n"))))
|
||||||
|
|
||||||
|
|
||||||
def blendfile_template_create(blendfile, blendfile_root, create_id, deps):
|
def blendfile_template_create(blendfile, blendfile_root, create_id, create_data, deps):
|
||||||
returncode_test = 123
|
returncode_test = 123
|
||||||
blendfile_deps_json = os.path.join(TEMP_LOCAL, "blend_template_deps.json")
|
blendfile_deps_json = os.path.join(TEMP_LOCAL, "blend_template_deps.json")
|
||||||
os.makedirs(os.path.dirname(blendfile), exist_ok=True)
|
os.makedirs(os.path.dirname(blendfile), exist_ok=True)
|
||||||
|
|
||||||
|
if create_data is not None:
|
||||||
|
blendfile_create_data_json = os.path.join(TEMP_LOCAL, "blendfile_create_data.json")
|
||||||
|
with open(blendfile_create_data_json, 'w') as f:
|
||||||
|
import json
|
||||||
|
json.dump(
|
||||||
|
create_data, f, ensure_ascii=False,
|
||||||
|
check_circular=False,
|
||||||
|
# optional (pretty)
|
||||||
|
sort_keys=True, indent=4, separators=(',', ': '),
|
||||||
|
)
|
||||||
|
del json
|
||||||
|
else:
|
||||||
|
blendfile_create_data_json = None
|
||||||
|
|
||||||
cmd = (
|
cmd = (
|
||||||
"blender",
|
"blender",
|
||||||
"--background",
|
"--background",
|
||||||
@@ -353,18 +368,23 @@ def blendfile_template_create(blendfile, blendfile_root, create_id, deps):
|
|||||||
blendfile_root,
|
blendfile_root,
|
||||||
blendfile_deps_json,
|
blendfile_deps_json,
|
||||||
create_id,
|
create_id,
|
||||||
|
"NONE" if blendfile_create_data_json is None else blendfile_create_data_json,
|
||||||
str(returncode_test),
|
str(returncode_test),
|
||||||
)
|
)
|
||||||
stdout, stderr, returncode = run(cmd)
|
stdout, stderr, returncode = run(cmd)
|
||||||
|
|
||||||
if os.path.exists(blendfile_deps_json):
|
if os.path.exists(blendfile_deps_json):
|
||||||
import json
|
|
||||||
with open(blendfile_deps_json, 'r') as f:
|
with open(blendfile_deps_json, 'r') as f:
|
||||||
|
import json
|
||||||
deps[:] = json.load(f)
|
deps[:] = json.load(f)
|
||||||
|
del json
|
||||||
os.remove(blendfile_deps_json)
|
os.remove(blendfile_deps_json)
|
||||||
else:
|
else:
|
||||||
deps.clear()
|
deps.clear()
|
||||||
|
|
||||||
|
if blendfile_create_data_json is not None:
|
||||||
|
os.remove(blendfile_create_data_json)
|
||||||
|
|
||||||
if returncode != returncode_test:
|
if returncode != returncode_test:
|
||||||
# verbose will have already printed
|
# verbose will have already printed
|
||||||
if not VERBOSE:
|
if not VERBOSE:
|
||||||
@@ -386,7 +406,7 @@ def blendfile_template_create_from_files(proj_path, session_path, blendfile, ima
|
|||||||
|
|
||||||
blendfile_abs = os.path.join(session_path, blendfile[0])
|
blendfile_abs = os.path.join(session_path, blendfile[0])
|
||||||
deps = []
|
deps = []
|
||||||
blendfile_template_create(blendfile_abs, session_path, "create_from_files", deps)
|
blendfile_template_create(blendfile_abs, session_path, "create_from_files", None, deps)
|
||||||
|
|
||||||
# not essential but we need to be sure what we made has correct deps
|
# not essential but we need to be sure what we made has correct deps
|
||||||
# otherwise further tests will fail
|
# otherwise further tests will fail
|
||||||
@@ -720,7 +740,7 @@ class BamBlendTest(BamSimpleTestCase):
|
|||||||
blendfile = os.path.join(TEMP_SESSION, create_id + ".blend")
|
blendfile = os.path.join(TEMP_SESSION, create_id + ".blend")
|
||||||
deps = []
|
deps = []
|
||||||
|
|
||||||
if not blendfile_template_create(blendfile, TEMP_SESSION, create_id, deps):
|
if not blendfile_template_create(blendfile, TEMP_SESSION, create_id, None, deps):
|
||||||
# self.fail("blend file couldn't be create")
|
# self.fail("blend file couldn't be create")
|
||||||
# ... we want to keep running
|
# ... we want to keep running
|
||||||
self.assertTrue(False, True) # GRR, a better way?
|
self.assertTrue(False, True) # GRR, a better way?
|
||||||
@@ -743,7 +763,7 @@ class BamBlendTest(BamSimpleTestCase):
|
|||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
file_name = "testfile.blend"
|
file_name = "testfile.blend"
|
||||||
blendfile = os.path.join(TEMP_LOCAL, file_name)
|
blendfile = os.path.join(TEMP_LOCAL, file_name)
|
||||||
if not blendfile_template_create(blendfile, TEMP_LOCAL, "create_blank", []):
|
if not blendfile_template_create(blendfile, TEMP_LOCAL, "create_blank", None, []):
|
||||||
self.fail("blend file couldn't be created")
|
self.fail("blend file couldn't be created")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -765,7 +785,7 @@ class BamDeleteTest(BamSessionTestCase):
|
|||||||
|
|
||||||
# now do a real commit
|
# now do a real commit
|
||||||
blendfile = os.path.join(session_path, file_name)
|
blendfile = os.path.join(session_path, file_name)
|
||||||
if not blendfile_template_create(blendfile, session_path, "create_blank", []):
|
if not blendfile_template_create(blendfile, session_path, "create_blank", None, []):
|
||||||
self.fail("blend file couldn't be created")
|
self.fail("blend file couldn't be created")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user