Skip to content

Commit

Permalink
Adjustment after being tested on Flame.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-ynput committed Nov 5, 2024
1 parent c76051e commit b65900b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions client/ayon_flame/plugins/create/create_workfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
import ayon_flame.api as flapi


wiretap_client = WireTapClient()
good = wiretap_client.init()
server = WireTapServerHandle("localhost:IFFFS")


class CreateWorkfile(AutoCreator):
"""Workfile auto-creator."""
settings_category = "flame"
Expand All @@ -39,12 +44,7 @@ def _get_project_metadata_handle(cls):
object. Flame wiretap handle for current project
"""
current_project = flapi.get_current_project()

wiretap_client = WireTapClient()
wiretap_client.init()

server = WireTapServerHandle("localhost:IFFFS")
project_node_handle = WireTapNodeHandle(server, "/projects/{current_project.name}")
project_node_handle = WireTapNodeHandle(server, f"/projects/{current_project.name}")
return project_node_handle

@classmethod
Expand All @@ -65,10 +65,18 @@ def _dump_instance_data(cls, data):
Args:
data (dict): The data to push to the project tag.
Returns:
bool. Has the metadata been updated.
"""
metadata = cls._get_project_metadata()
nickname_entry, = metadata.findall(cls._METADATA_KEY)
nickname_entry.text = json.dumps(data)
updated = ET.tostring(metadata, encoding='unicode')

project_node_handle = cls._get_project_metadata_handle()
new_metadata = WireTapStr(updated)
return project_node_handle.setMetaData("XML", new_metadata.c_str())

@classmethod
def _load_instance_data(cls):
Expand All @@ -79,7 +87,10 @@ def _load_instance_data(cls):
"""
metadata = cls._get_project_metadata()
nickname_entry, = metadata.findall(cls._METADATA_KEY)
return json.loads(nickname_entry.text) if nickname_entry.text else {}
try:
return json.loads(nickname_entry.text)
except json.JSONDecodeError as error:
return {}

def _create_new_instance(self):
"""Create a new workfile instance.
Expand Down Expand Up @@ -122,18 +133,16 @@ def _create_new_instance(self):
current_instance = CreatedInstance(
self.product_type, product_name, data, self)
self._add_instance_to_context(current_instance)
return current_instance

def create(self, options=None):
"""Auto-create an instance by default."""
instance_data = self._load_instance_data()
instance_data = self._load_instance_data()
if instance_data:
return
return

self.log.info("Auto-creating workfile instance...")
data = self._create_new_instance()
current_instance = CreatedInstance(
self.product_type, data["productName"], data, self)
self._add_instance_to_context(current_instance)
self._create_new_instance()

def collect_instances(self):
"""Collect from timeline marker or create a new one."""
Expand All @@ -155,4 +164,4 @@ def update_instances(self, update_list):
"""
for created_inst, _ in update_list:
data = created_inst.data_to_store()
self._dump_instance_data(data)
self._dump_instance_data(data)

0 comments on commit b65900b

Please sign in to comment.