From 8b0864a5e3f7b7d1849898de2623dbb79fc4179e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 17 Mar 2014 19:03:07 +1100 Subject: Use a temp directory for writing the blend into --- io_online_sketchfab/__init__.py | 6 +++++- io_online_sketchfab/pack_for_export.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'io_online_sketchfab') diff --git a/io_online_sketchfab/__init__.py b/io_online_sketchfab/__init__.py index 3e5d7472..b39f4f7f 100644 --- a/io_online_sketchfab/__init__.py +++ b/io_online_sketchfab/__init__.py @@ -47,6 +47,7 @@ else: import bpy import os +import tempfile import threading import subprocess @@ -244,7 +245,8 @@ class ExportSketchfab(bpy.types.Operator): basename = os.path.join(basename, "temp") if not ext: ext = ".blend" - filepath = basename + "-export-sketchfab" + ext + tempdir = tempfile.mkdtemp() + filepath = os.path.join(tempdir, "export-sketchfab" + ext) try: # save a copy of actual scene but don't interfere with the users models @@ -262,6 +264,7 @@ class ExportSketchfab(bpy.types.Operator): "-noaudio", filepath, "--python", os.path.join(script_path, "pack_for_export.py"), + "--", tempdir ]) os.remove(filepath) @@ -434,6 +437,7 @@ class SketchfabEmailToken(bpy.types.Operator): # remove file copy def terminate(filepath): os.remove(filepath) + os.rmdir(os.path.dirname(filepath)) # registration classes = ( diff --git a/io_online_sketchfab/pack_for_export.py b/io_online_sketchfab/pack_for_export.py index a8e7fc9b..16d38cca 100644 --- a/io_online_sketchfab/pack_for_export.py +++ b/io_online_sketchfab/pack_for_export.py @@ -23,10 +23,12 @@ import os import bpy import json +import sys SKETCHFAB_EXPORT_DATA_FILENAME = 'sketchfab-export-data.json' +SKETCHFAB_EXPORT_TEMP_DIR = sys.argv[-1] SKETCHFAB_EXPORT_DATA_FILE = os.path.join( bpy.utils.user_resource('SCRIPTS'), "presets", @@ -38,7 +40,7 @@ SKETCHFAB_EXPORT_DATA_FILE = os.path.join( def save_blend_copy(): import time - filepath = os.path.dirname(bpy.data.filepath) + filepath = SKETCHFAB_EXPORT_TEMP_DIR filename = time.strftime("Sketchfab_%Y_%m_%d_%H_%M_%S.blend", time.localtime(time.time())) filepath = os.path.join(filepath, filename) @@ -119,6 +121,5 @@ if __name__ == "__main__": import traceback traceback.print_exc() - import sys sys.exit(1) -- cgit v1.2.3