Batch-previews generation: add option to control whether we save backup .blend1 file...
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 1 Mar 2016 16:46:21 +0000 (17:46 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 1 Mar 2016 16:46:21 +0000 (17:46 +0100)
Requested by Aaron Carlisle (@blendify) over IRC.

release/scripts/modules/bl_previews_utils/bl_previews_render.py
release/scripts/startup/bl_operators/file.py

index beee78b3ce03a6d7a19ce599ca41950d521d38fe..674c1c00ab174ee2d4a09567f642a2620b84368d 100644 (file)
@@ -471,14 +471,26 @@ def main():
     argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
 
     parser = argparse.ArgumentParser(description="Use Blender to generate previews for currently open Blender file's items.")
-    parser.add_argument('--clear', default=False, action="store_true", help="Clear previews instead of generating them.")
-    parser.add_argument('--no_scenes', default=True, action="store_false", help="Do not generate/clear previews for scene IDs.")
-    parser.add_argument('--no_groups', default=True, action="store_false", help="Do not generate/clear previews for group IDs.")
-    parser.add_argument('--no_objects', default=True, action="store_false", help="Do not generate/clear previews for object IDs.")
+    parser.add_argument('--clear', default=False, action="store_true",
+                        help="Clear previews instead of generating them.")
+    parser.add_argument('--no_backups', default=False, action="store_true",
+                        help="Do not generate a backup .blend1 file when saving processed ones.")
+    parser.add_argument('--no_scenes', default=True, action="store_false",
+                        help="Do not generate/clear previews for scene IDs.")
+    parser.add_argument('--no_groups', default=True, action="store_false",
+                        help="Do not generate/clear previews for group IDs.")
+    parser.add_argument('--no_objects', default=True, action="store_false",
+                        help="Do not generate/clear previews for object IDs.")
     parser.add_argument('--no_data_intern', default=True, action="store_false",
                         help="Do not generate/clear previews for mat/tex/image/etc. IDs (those handled by core Blender code).")
     args = parser.parse_args(argv)
 
+    orig_save_version = bpy.context.user_preferences.filepaths.save_version
+    if args.no_backups:
+        bpy.context.user_preferences.filepaths.save_version = 0
+    elif orig_save_version < 1:
+        bpy.context.user_preferences.filepaths.save_version = 1
+
     if args.clear:
         print("clear!")
         do_clear_previews(do_objects=args.no_objects, do_groups=args.no_groups, do_scenes=args.no_scenes,
@@ -488,6 +500,9 @@ def main():
         do_previews(do_objects=args.no_objects, do_groups=args.no_groups, do_scenes=args.no_scenes,
                     do_data_intern=args.no_data_intern)
 
+    # Not really necessary, but better be consistent.
+    bpy.context.user_preferences.filepaths.save_version = orig_save_version
+
 
 if __name__ == "__main__":
     print("\n\n *** Running {} *** \n".format(__file__))
index efcc7d5c65ea3d3955cc6b1b2b6c80621ba292f7..64cc0aeddb3cc86e5c61672a7ca4a1e62d06ef2a 100644 (file)
@@ -86,6 +86,11 @@ class WM_OT_previews_batch_generate(Operator):
             name="Trusted Blend Files",
             description="Enable python evaluation for selected files",
             )
+    use_backups = BoolProperty(
+            default=True,
+            name="Save Backups",
+            description="Keep a backup (.blend1) version of the files when saving with generated previews",
+            )
 
     def invoke(self, context, event):
         context.window_manager.fileselect_add(self)
@@ -126,6 +131,8 @@ class WM_OT_previews_batch_generate(Operator):
                 cmd.append('--no_objects')
             if not self.use_intern_data:
                 cmd.append('--no_data_intern')
+            if not self.use_backups:
+                cmd.append("--no_backups")
             if subprocess.call(cmd):
                 self.report({'ERROR'}, "Previews generation process failed for file '%s'!" % blen_path)
                 context.window_manager.progress_end()
@@ -192,6 +199,11 @@ class WM_OT_previews_batch_clear(Operator):
             name="Trusted Blend Files",
             description="Enable python evaluation for selected files",
             )
+    use_backups = BoolProperty(
+            default=True,
+            name="Save Backups",
+            description="Keep a backup (.blend1) version of the files when saving with cleared previews",
+            )
 
     def invoke(self, context, event):
         context.window_manager.fileselect_add(self)
@@ -233,6 +245,8 @@ class WM_OT_previews_batch_clear(Operator):
                 cmd.append('--no_objects')
             if not self.use_intern_data:
                 cmd.append('--no_data_intern')
+            if not self.use_backups:
+                cmd.append("--no_backups")
             if subprocess.call(cmd):
                 self.report({'ERROR'}, "Previews clear process failed for file '%s'!" % blen_path)
                 context.window_manager.progress_end()