publisher has temp dir for thumbnails which is cleared up on publisher close

This commit is contained in:
Jakub Trllo 2022-10-27 18:46:09 +02:00
parent 9c048478bb
commit 90222b1b3f
2 changed files with 40 additions and 0 deletions

View file

@ -4,6 +4,8 @@ import logging
import traceback
import collections
import uuid
import tempfile
import shutil
from abc import ABCMeta, abstractmethod, abstractproperty
import six
@ -24,6 +26,7 @@ from openpype.pipeline import (
KnownPublishError,
registered_host,
legacy_io,
get_process_id,
)
from openpype.pipeline.create import (
CreateContext,
@ -1283,6 +1286,22 @@ class AbstractPublisherController(object):
pass
@abstractmethod
def get_thumbnail_temp_dir_path(self):
"""Return path to directory where thumbnails can be temporary stored.
Returns:
str: Path to a directory.
"""
pass
@abstractmethod
def clear_thumbnail_temp_dir_path(self):
"""Remove content of thumbnail temp directory."""
pass
class BasePublisherController(AbstractPublisherController):
"""Implement common logic for controllers.
@ -1523,6 +1542,26 @@ class BasePublisherController(AbstractPublisherController):
return creator_item.icon
return None
def get_thumbnail_temp_dir_path(self):
"""Return path to directory where thumbnails can be temporary stored.
Returns:
str: Path to a directory.
"""
return os.path.join(
tempfile.gettempdir(),
"publisher_thumbnails",
get_process_id()
)
def clear_thumbnail_temp_dir_path(self):
"""Remove content of thumbnail temp directory."""
dirpath = self.get_thumbnail_temp_dir_path()
if os.path.exists(dirpath):
shutil.rmtree(dirpath)
class PublisherController(BasePublisherController):
"""Middleware between UI, CreateContext and publish Context.

View file

@ -383,6 +383,7 @@ class PublisherWindow(QtWidgets.QDialog):
def closeEvent(self, event):
self.save_changes()
self._reset_on_show = True
self._controller.clear_thumbnail_temp_dir_path()
super(PublisherWindow, self).closeEvent(event)
def save_changes(self):