flame: adding maintainable temp file path

This commit is contained in:
Jakub Jezek 2022-04-08 11:17:22 +02:00
parent fc6d01d004
commit 5f1940a998
No known key found for this signature in database
GPG key ID: D8548FBF690B100A
2 changed files with 22 additions and 0 deletions

View file

@ -27,6 +27,7 @@ from .lib import (
get_frame_from_filename,
get_padding_from_filename,
maintained_object_duplication,
maintained_temp_file_path,
get_clip_segment,
get_batch_group_from_desktop,
MediaInfoFile
@ -103,6 +104,7 @@ __all__ = [
"get_frame_from_filename",
"get_padding_from_filename",
"maintained_object_duplication",
"maintained_temp_file_path",
"get_clip_segment",
"get_batch_group_from_desktop",
"MediaInfoFile",

View file

@ -4,6 +4,7 @@ import re
import six
import json
import pickle
import tempfile
import itertools
import contextlib
import xml.etree.cElementTree as cET
@ -695,6 +696,25 @@ def maintained_object_duplication(item):
flame.delete(duplicate)
@contextlib.contextmanager
def maintained_temp_file_path(suffix=None):
_suffix = suffix or ""
try:
# Store dumped json to temporary file
temporary_file = tempfile.mktemp(
suffix=_suffix, prefix="flame_maintained_")
yield temporary_file.name.replace("\\", "/")
except IOError as _error:
raise IOError(
"Not able to create temp json file: {}".format(_error)) from _error
finally:
# Remove the temporary json
os.remove(temporary_file)
def get_clip_segment(flame_clip):
name = flame_clip.name.get_value()
version = flame_clip.versions[0]