Batch-previews generation: add option to control whether we save backup .blend1 file or not.

Requested by Aaron Carlisle (@blendify) over IRC.
This commit is contained in:
Bastien Montagne 2016-03-01 17:46:21 +01:00
parent 50500a4399
commit 449fbde7d1
2 changed files with 33 additions and 4 deletions

View 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__))

View 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()