mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +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
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ def install():
|
|||
reg_paths = request_aport("/pipeline/register_plugin_path",
|
||||
{"publish_path": PUBLISH_PATH})
|
||||
log.info(str(reg_paths))
|
||||
# api.message(title="pyblish_paths", message=str(reg_paths), level="info")
|
||||
api.message(title="pyblish_paths", message=str(reg_paths), level="info")
|
||||
|
||||
avalon.register_plugin_path(avalon.Loader, LOAD_PATH)
|
||||
avalon.register_plugin_path(avalon.Creator, CREATE_PATH)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class Window(QWidget):
|
||||
def __init__(self, title, message, level):
|
||||
def __init__(self, parent, title, message, level):
|
||||
super().__init__()
|
||||
self.parent = parent
|
||||
self.title = title
|
||||
self.message = message
|
||||
self.level = level
|
||||
|
|
@ -25,26 +26,32 @@ class Window(QWidget):
|
|||
rc = QMessageBox.information(
|
||||
self, self.title, self.message)
|
||||
if rc:
|
||||
sys.exit(app.exec_())
|
||||
self.exit()
|
||||
|
||||
def _warning(self):
|
||||
self.setWindowTitle(self.title)
|
||||
rc = QMessageBox.warning(
|
||||
self, self.title, self.message)
|
||||
if rc:
|
||||
sys.exit(app.exec_())
|
||||
self.exit()
|
||||
|
||||
def _critical(self):
|
||||
self.setWindowTitle(self.title)
|
||||
rc = QMessageBox.critical(
|
||||
self, self.title, self.message)
|
||||
if rc:
|
||||
sys.exit(app.exec_())
|
||||
self.exit()
|
||||
|
||||
def exit(self):
|
||||
self.hide()
|
||||
# self.parent.exec_()
|
||||
self.parent.hide()
|
||||
return
|
||||
|
||||
|
||||
def message(title=None, message=None, level="info"):
|
||||
global app
|
||||
app = QApplication(sys.argv)
|
||||
ex = Window(title, message, level)
|
||||
ex = Window(app, title, message, level)
|
||||
ex.show()
|
||||
sys.exit(app.exec_())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue