[Bf-extensions-cvs] [c016452] temp-blend-utils: Use a temp directory for packing
Campbell Barton
noreply at git.blender.org
Fri Jan 29 06:33:58 CET 2016
Commit: c016452827149229eb6b16ac087598d43760a570
Author: Campbell Barton
Date: Fri Jan 29 16:25:49 2016 +1100
Branches: temp-blend-utils
https://developer.blender.org/rBAc016452827149229eb6b16ac087598d43760a570
Use a temp directory for packing
===================================================================
M io_blend_utils/__init__.py
M io_blend_utils/blendfile_pack.py
===================================================================
diff --git a/io_blend_utils/__init__.py b/io_blend_utils/__init__.py
index 220c107..33d5d8f 100644
--- a/io_blend_utils/__init__.py
+++ b/io_blend_utils/__init__.py
@@ -48,6 +48,8 @@ class ExportBlendPack(Operator, ExportHelper, SubprocessHelper):
# SubprocessHelper
report_interval = 0.25
+ temp_dir = None
+
@classmethod
def poll(cls, context):
return bpy.data.is_saved
@@ -56,6 +58,11 @@ class ExportBlendPack(Operator, ExportHelper, SubprocessHelper):
@property
def command(self):
import os
+ import tempfile
+
+ if self.temp_dir is None:
+ self.temp_dir = tempfile.TemporaryDirectory()
+
return (
bpy.app.binary_path_python,
os.path.join(os.path.dirname(__file__), "blendfile_pack.py"),
@@ -63,8 +70,20 @@ class ExportBlendPack(Operator, ExportHelper, SubprocessHelper):
"--input", bpy.data.filepath,
# file to write
"--output", bpy.path.ensure_ext(self.filepath, ".zip"),
+ "--temp", self.temp_dir.name,
)
+ def command_complete(self, returncode):
+ if self.temp_dir is None:
+ return
+
+ try:
+ self.temp_dir.cleanup()
+ self.temp_dir = None
+ except:
+ import traceback
+ traceback.print_exc()
+
def menu_func(self, context):
layout = self.layout
diff --git a/io_blend_utils/blendfile_pack.py b/io_blend_utils/blendfile_pack.py
index c34fabb..f905884 100755
--- a/io_blend_utils/blendfile_pack.py
+++ b/io_blend_utils/blendfile_pack.py
@@ -89,7 +89,10 @@ def pack(
# os.path.dirname(blendfile_src)
# but in some cases we wan't to use a path higher up.
# base_dir_src,
- blendfile_src, blendfile_dst, mode='FILE',
+ blendfile_src, blendfile_dst,
+ mode='ZIP',
+ # optionally pass in the temp dir
+ base_dir_dst_temp=None,
paths_remap_relbase=None,
deps_remap=None, paths_remap=None, paths_uuid=None,
# load every libs dep, not just used deps.
@@ -181,10 +184,11 @@ def pack(
# _dbg(blendfile_src)
# _dbg(blendfile_dst)
- if mode == 'ZIP':
- base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_temp__')
- else:
- base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_pack__')
+ if base_dir_dst_temp is None:
+ if mode == 'ZIP':
+ base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_temp__')
+ else:
+ base_dir_dst_temp = os.path.join(base_dir_dst, b'__blendfile_pack__')
def temp_remap_cb(filepath, rootdir):
"""
@@ -555,6 +559,10 @@ def create_argparse():
"-q", "--quiet", dest="use_quiet", action='store_true', required=False,
help="Suppress status output",
)
+ parser.add_argument(
+ "-t", "--temp", dest="temp_path", metavar='DIR', required=False,
+ help="Temporary directory to use",
+ )
return parser
@@ -577,6 +585,7 @@ def main():
args.path_src.encode('utf-8'),
args.path_dst.encode('utf-8'),
mode=args.mode,
+ base_dir_dst_temp=args.temp_path.encode('utf-8'),
):
report(msg)
More information about the Bf-extensions-cvs
mailing list