added reset of context

This commit is contained in:
iLLiCiTiT 2021-10-06 11:38:23 +02:00
parent 4bb14b5f6b
commit 57b553a13c
2 changed files with 39 additions and 0 deletions

View file

@ -751,6 +751,7 @@ class CreateContext:
All changes will be lost if were not saved explicitely.
"""
self.reset_avalon_context()
self.reset_plugins(discover_publish_plugins)
self.reset_context_data()
@ -758,6 +759,39 @@ class CreateContext:
self.reset_instances()
self.execute_autocreators()
def reset_avalon_context(self):
"""Give ability to reset avalon context.
Reset is based on optional host implementation of `get_current_context`
function or using `avalon.api.Session`.
Some hosts have ability to change context file without using workfiles
tool but that change is not propagated to
"""
import avalon.api
project_name = asset_name = task_name = None
if hasattr(self.host, "get_current_context"):
host_context = self.host.get_current_context()
if host_context:
project_name = host_context.get("project_name")
asset_name = host_context.get("asset_name")
task_name = host_context.get("task_name")
if not project_name:
project_name = avalon.api.Session.get("AVALON_PROJECT")
if not asset_name:
asset_name = avalon.api.Session.get("AVALON_ASSET")
if not task_name:
task_name = avalon.api.Session.get("AVALON_TASK")
if project_name:
self.dbcon.Session["AVALON_PROJECT"] = project_name
if asset_name:
self.dbcon.Session["AVALON_ASSET"] = asset_name
if task_name:
self.dbcon.Session["AVALON_TASK"] = task_name
def reset_plugins(self, discover_publish_plugins=True):
"""Reload plugins.

View file

@ -538,7 +538,12 @@ class PublisherController:
def reset(self):
"""Reset everything related to creation and publishing."""
# Stop publishing
self.stop_publish()
# Reset avalon context
self.create_context.reset_avalon_context()
self._reset_plugins()
# Publish part must be resetted after plugins
self._reset_publish()