[Bf-extensions-cvs] [c8d1d2e] temp-blend-utils: Name callbacks process_pre/post

Campbell Barton noreply at git.blender.org
Fri Jan 29 07:11:25 CET 2016


Commit: c8d1d2e1eb904d0d274e5c1957818c1749f35e25
Author: Campbell Barton
Date:   Fri Jan 29 17:03:27 2016 +1100
Branches: temp-blend-utils
https://developer.blender.org/rBAc8d1d2e1eb904d0d274e5c1957818c1749f35e25

Name callbacks process_pre/post

===================================================================

M	io_blend_utils/__init__.py
M	io_blend_utils/bl_utils/subprocess_helper.py

===================================================================

diff --git a/io_blend_utils/__init__.py b/io_blend_utils/__init__.py
index 33d5d8f..0c8cf3c 100644
--- a/io_blend_utils/__init__.py
+++ b/io_blend_utils/__init__.py
@@ -54,35 +54,32 @@ class ExportBlendPack(Operator, ExportHelper, SubprocessHelper):
     def poll(cls, context):
         return bpy.data.is_saved
 
-    # command attribute for 'SubprocessHelper'
-    @property
-    def command(self):
+    def process_pre(self):
         import os
         import tempfile
 
         if self.temp_dir is None:
             self.temp_dir = tempfile.TemporaryDirectory()
 
-        return (
+        filepath_blend = bpy.data.filepath
+
+        self.command = (
             bpy.app.binary_path_python,
             os.path.join(os.path.dirname(__file__), "blendfile_pack.py"),
             # file to pack
-            "--input", bpy.data.filepath,
+            "--input", filepath_blend,
             # 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 process_post(self, returncode):
+        if self.temp_dir is not None:
+            try:
+                self.temp_dir.cleanup()
+            except:
+                import traceback
+                traceback.print_exc()
 
 
 def menu_func(self, context):
diff --git a/io_blend_utils/bl_utils/subprocess_helper.py b/io_blend_utils/bl_utils/subprocess_helper.py
index a19031b..2d289d3 100644
--- a/io_blend_utils/bl_utils/subprocess_helper.py
+++ b/io_blend_utils/bl_utils/subprocess_helper.py
@@ -28,18 +28,17 @@ class SubprocessHelper:
 
     This uses a modal operator to manage an external process.
 
-    This class defines:
-
-        _process: The running process object.
-
     Subclass must define:
+        ``command``:
+            List of arguments to pass to subprocess.Popen
+            report_interval: Time in seconds between updating reports.
 
-        command: List of arguments to pass to subprocess.Popen
-        report_interval: Time in seconds between updating reports.
+        ``process_pre()``:
+            Callback that runs before the process executes.
 
-        command_complete(returncode): Callback that runs
-        when the process has ended.
-        returncode is -1 if the process was terminated.
+        ``process_post(returncode)``:
+            Callback that runs when the process has ende.
+            returncode is -1 if the process was terminated.
     """
 
     @staticmethod
@@ -111,7 +110,10 @@ class SubprocessHelper:
         wm.event_timer_remove(self._timer)
         window.cursor_set('DEFAULT')
 
-    def command_complete(self, returncode):
+    def process_pre(self):
+        pass
+
+    def process_post(self, returncode):
         pass
 
     def modal(self, context, event):
@@ -127,7 +129,7 @@ class SubprocessHelper:
             if p.poll() is not None:
                 self._report_output()
                 self._wm_exit(context)
-                self.command_complete(p.returncode)
+                self.process_post(p.returncode)
                 return {'FINISHED'}
 
             self._report_output()
@@ -136,6 +138,9 @@ class SubprocessHelper:
 
     def execute(self, context):
         import subprocess
+
+        self.process_pre()
+
         try:
             p = subprocess.Popen(
                     self.command,
@@ -163,5 +168,5 @@ class SubprocessHelper:
     def cancel(self, context):
         self._wm_exit(context)
         self._process.kill()
-        self.command_complete(-1)
+        self.process_post(-1)



More information about the Bf-extensions-cvs mailing list