mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
adding extract post json
This commit is contained in:
parent
be134b1b77
commit
3eb44d968c
4 changed files with 90 additions and 22 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import pico
|
||||
# from pico.decorators import request_args, prehandle
|
||||
from pico import PicoApp
|
||||
|
|
@ -28,20 +29,42 @@ if not SESSION:
|
|||
|
||||
|
||||
@pico.expose()
|
||||
def publish(json_data_path):
|
||||
log.warning("avalon.session is: \n{}".format(SESSION))
|
||||
# load json_data_path; add context into data; damp
|
||||
# create empty temp/json_data_get
|
||||
# run standalone pyblish
|
||||
def publish(json_data_path, staging_dir=None):
|
||||
"""
|
||||
Runs standalone pyblish and adds link to
|
||||
data in external json file
|
||||
|
||||
It is necessary to run `register_plugin_path` if particular
|
||||
host is needed
|
||||
|
||||
Args:
|
||||
json_data_path (string): path to temp json file with
|
||||
context data
|
||||
staging_dir (strign, optional): path to temp directory
|
||||
|
||||
Returns:
|
||||
dict: return_json_path
|
||||
|
||||
Raises:
|
||||
Exception: description
|
||||
|
||||
"""
|
||||
staging_dir = staging_dir \
|
||||
or tempfile.mkdtemp(prefix="pype_aport_")
|
||||
|
||||
return_json_path = os.path.join(staging_dir, "return_data.json")
|
||||
|
||||
log.debug("avalon.session is: \n{}".format(SESSION))
|
||||
pype_start = os.path.join(os.getenv('PYPE_SETUP_ROOT'),
|
||||
"app", "pype-start.py")
|
||||
|
||||
args = [pype_start, "--publish",
|
||||
"-pp", os.environ["PUBLISH_PATH"],
|
||||
"-d", "json_context_data_path", json_data_path
|
||||
"-d", "rqst_json_data_path", json_data_path,
|
||||
"-d", "post_json_data_path", return_json_path
|
||||
]
|
||||
|
||||
log.info(args)
|
||||
log.debug(args)
|
||||
|
||||
# start standalone pyblish qml
|
||||
forward([
|
||||
|
|
@ -50,7 +73,7 @@ def publish(json_data_path):
|
|||
cwd=os.getenv('PYPE_SETUP_ROOT')
|
||||
)
|
||||
|
||||
return {"json_back": "this/json/file"}
|
||||
return {"return_json_path": return_json_path}
|
||||
|
||||
|
||||
@pico.expose()
|
||||
|
|
@ -95,7 +118,9 @@ def register_plugin_path(publish_path):
|
|||
)
|
||||
else:
|
||||
os.environ["PUBLISH_PATH"] = publish_path
|
||||
log.warning(os.environ["PUBLISH_PATH"].split(os.pathsep))
|
||||
|
||||
log.info(os.environ["PUBLISH_PATH"].split(os.pathsep))
|
||||
|
||||
return "Publish registered paths: {}".format(
|
||||
os.environ["PUBLISH_PATH"].split(os.pathsep)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,35 @@
|
|||
import pyblish.api
|
||||
from avalon import api as avalon
|
||||
from avalon import io
|
||||
from avalon import (
|
||||
io,
|
||||
api as avalon
|
||||
)
|
||||
import pprint
|
||||
|
||||
|
||||
class CollectContextDataEditorial(pyblish.api.ContextPlugin):
|
||||
"""Collecting data from temp json sent from premiera context"""
|
||||
class CollectContextDataFromAport(pyblish.api.ContextPlugin):
|
||||
"""
|
||||
Collecting temp json data sent from a host context
|
||||
and path for returning json data back to hostself.
|
||||
|
||||
label = "Collect Editorial Context"
|
||||
Setting avalon session into correct context
|
||||
|
||||
Args:
|
||||
context (obj): pyblish context session
|
||||
|
||||
"""
|
||||
|
||||
label = "Collect Aport Context"
|
||||
order = pyblish.api.CollectorOrder + 0.1
|
||||
|
||||
def process(self, context):
|
||||
data_path = context.data['json_context_data_path']
|
||||
self.log.info("Context is: {}".format(data_path))
|
||||
self.log.warning("avalon.session is: {}".format(avalon.session))
|
||||
rqst_json_data_path = context.data['rqst_json_data_path']
|
||||
post_json_data_path = context.data['post_json_data_path']
|
||||
|
||||
self.log.info("Context.data are: {}".format(
|
||||
context.data))
|
||||
|
||||
self.log.info("rqst_json_data_path is: {}".format(rqst_json_data_path))
|
||||
|
||||
self.log.info("post_json_data_path is: {}".format(post_json_data_path))
|
||||
|
||||
self.log.info("avalon.session is: {}".format(avalon.session))
|
||||
|
|
|
|||
16
pype/plugins/aport/publish/extract_post_json.py
Normal file
16
pype/plugins/aport/publish/extract_post_json.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import json
|
||||
import pyblish.api
|
||||
|
||||
|
||||
class ExtractJSON(pyblish.api.ContextPlugin):
|
||||
""" Extract all instances to a serialized json file. """
|
||||
|
||||
order = pyblish.api.IntegratorOrder
|
||||
label = "Extract to JSON"
|
||||
|
||||
def process(self, context):
|
||||
json_path = context.data['post_json_data_path']
|
||||
data = dict(context.data)
|
||||
self.log.info(data)
|
||||
with open(json_path, "w") as outfile:
|
||||
json.dump(data, outfile, indent=4, sort_keys=True)
|
||||
|
|
@ -22,19 +22,24 @@ PACKAGE_DIR = os.path.dirname(PARENT_DIR)
|
|||
PLUGINS_DIR = os.path.join(PACKAGE_DIR, "plugins")
|
||||
|
||||
PUBLISH_PATH = os.path.join(
|
||||
PLUGINS_DIR, "premiera", "publish"
|
||||
PLUGINS_DIR, "premiere", "publish"
|
||||
).replace("\\", "/")
|
||||
|
||||
LOAD_PATH = os.path.join(PLUGINS_DIR, "premiera", "load")
|
||||
CREATE_PATH = os.path.join(PLUGINS_DIR, "premiera", "create")
|
||||
INVENTORY_PATH = os.path.join(PLUGINS_DIR, "premiera", "inventory")
|
||||
LOAD_PATH = os.path.join(PLUGINS_DIR, "premiere", "load")
|
||||
CREATE_PATH = os.path.join(PLUGINS_DIR, "premiere", "create")
|
||||
INVENTORY_PATH = os.path.join(PLUGINS_DIR, "premiere", "inventory")
|
||||
|
||||
|
||||
def request_aport(url_path, data={}):
|
||||
try:
|
||||
api.add_tool_to_environment(["aport"])
|
||||
|
||||
ip = os.getenv("PICO_IP", None)
|
||||
if ip and ip.startswith('http'):
|
||||
ip = ip.replace("http://", "")
|
||||
|
||||
port = int(os.getenv("PICO_PORT", None))
|
||||
|
||||
url = "http://{0}:{1}{2}".format(ip, port, url_path)
|
||||
req = requests.post(url, data=data).text
|
||||
return req
|
||||
|
|
@ -73,9 +78,11 @@ def install():
|
|||
|
||||
api.set_avalon_workdir()
|
||||
log.info("Registering Premiera plug-ins..")
|
||||
|
||||
reg_paths = request_aport("/pipeline/register_plugin_path",
|
||||
{"publish_path": PUBLISH_PATH})
|
||||
api.message(title="pyblish_paths", message=str(reg_paths), level="info")
|
||||
log.info(str(reg_paths))
|
||||
# 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue