mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
adding aport json exporter, fixing message_window to be closing process properly, aport collect context update
This commit is contained in:
parent
2a1f637880
commit
6c24580ede
4 changed files with 107 additions and 11 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import os
|
||||
import pyblish.api
|
||||
from avalon import (
|
||||
io,
|
||||
api as avalon
|
||||
)
|
||||
import pprint
|
||||
|
||||
|
||||
class CollectContextDataFromAport(pyblish.api.ContextPlugin):
|
||||
|
|
@ -19,11 +19,21 @@ class CollectContextDataFromAport(pyblish.api.ContextPlugin):
|
|||
"""
|
||||
|
||||
label = "Collect Aport Context"
|
||||
order = pyblish.api.CollectorOrder + 0.1
|
||||
order = pyblish.api.CollectorOrder - 0.01
|
||||
|
||||
def process(self, context):
|
||||
context.data["avalonSession"] = session = avalon.session
|
||||
rqst_json_data_path = context.data['rqst_json_data_path']
|
||||
post_json_data_path = context.data['post_json_data_path']
|
||||
context.data["stagingDir"] = staging_dir = os.path.dirname(post_json_data_path)
|
||||
|
||||
pyblish.api.deregister_all_hosts()
|
||||
pyblish.api.register_host(session["AVALON_APP"])
|
||||
|
||||
context.data["currentFile"] = session["AVALON_WORKDIR"]
|
||||
|
||||
if not os.path.exists(staging_dir):
|
||||
os.makedirs(staging_dir)
|
||||
|
||||
self.log.info("Context.data are: {}".format(
|
||||
context.data))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import clique
|
||||
import pyblish.api
|
||||
|
||||
|
||||
|
|
@ -10,7 +11,85 @@ class ExtractJSON(pyblish.api.ContextPlugin):
|
|||
|
||||
def process(self, context):
|
||||
json_path = context.data['post_json_data_path']
|
||||
data = dict(context.data)
|
||||
self.log.info(data)
|
||||
|
||||
data = dict(self.serialize(context.data()))
|
||||
# self.log.info(data)
|
||||
|
||||
instances_data = []
|
||||
for instance in context:
|
||||
|
||||
data = {}
|
||||
for key, value in instance.data.items():
|
||||
if isinstance(value, clique.Collection):
|
||||
value = value.format()
|
||||
|
||||
try:
|
||||
json.dumps(value)
|
||||
data[key] = value
|
||||
except KeyError:
|
||||
msg = "\"{0}\"".format(value)
|
||||
msg += " in instance.data[\"{0}\"]".format(key)
|
||||
msg += " could not be serialized."
|
||||
self.log.debug(msg)
|
||||
|
||||
instances_data.append(data)
|
||||
|
||||
data["instances"] = instances_data
|
||||
|
||||
with open(json_path, "w") as outfile:
|
||||
json.dump(data, outfile, indent=4, sort_keys=True)
|
||||
outfile.write(json.dumps(data, indent=4, sort_keys=True))
|
||||
|
||||
def serialize(self, data):
|
||||
"""
|
||||
Convert all nested content to serialized objects
|
||||
|
||||
Args:
|
||||
data (dict): nested data
|
||||
|
||||
Returns:
|
||||
dict: nested data
|
||||
"""
|
||||
|
||||
def encoding_obj(value):
|
||||
try:
|
||||
value = getattr(value, '__dict__', value)
|
||||
except Exception:
|
||||
pass
|
||||
return value
|
||||
|
||||
if isinstance(data, object):
|
||||
data = dict(data)
|
||||
|
||||
for key, value in data.items():
|
||||
if "records" in key:
|
||||
# escape all record objects
|
||||
data[key] = None
|
||||
continue
|
||||
|
||||
if hasattr(value, '__module__'):
|
||||
# only deals with module objects
|
||||
if "plugins" in value.__module__:
|
||||
# only dealing with plugin objects
|
||||
data[key] = str(value.__module__)
|
||||
else:
|
||||
if ".lib." in value.__module__:
|
||||
# will allow only anatomy dict
|
||||
data[key] = self.serialize(value)
|
||||
else:
|
||||
data[key] = None
|
||||
continue
|
||||
continue
|
||||
|
||||
if isinstance(value, dict):
|
||||
# loops if dictionary
|
||||
data[key] = self.serialize(value)
|
||||
|
||||
if isinstance(value, (list or tuple)):
|
||||
# loops if list or tuple
|
||||
for i, item in enumerate(value):
|
||||
value[i] = self.serialize(item)
|
||||
data[key] = value
|
||||
|
||||
data[key] = encoding_obj(value)
|
||||
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue