Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/invalid-scope'
Browse files Browse the repository at this point in the history
  • Loading branch information
mkolar committed Aug 12, 2020
2 parents edf61b7 + 58cd5f8 commit c5e1a17
Show file tree
Hide file tree
Showing 25 changed files with 878 additions and 406 deletions.
18 changes: 11 additions & 7 deletions pype/hosts/harmony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,31 @@ def application_launch():
def export_template(backdrops, nodes, filepath):
func = """function func(args)
{
// Add an extra node just so a new group can be created.
var temp_node = node.add("Top", "temp_note", "NOTE", 0, 0, 0);
var template_group = node.createGroup(temp_node, "temp_group");
node.deleteNode( template_group + "/temp_note" );
// This will make Node View to focus on the new group.
selection.clearSelection();
for (var f = 0; f < args[1].length; f++)
{
selection.addNodeToSelection(args[1][f]);
}
Action.perform("copy()", "Node View");
selection.clearSelection();
selection.addNodeToSelection(template_group);
Action.perform("onActionEnterGroup()", "Node View");
Action.perform("paste()", "Node View");
// Recreate backdrops in group.
for (var i = 0 ; i < args[0].length; i++)
{
MessageLog.trace(args[0][i]);
Backdrop.addBackdrop(template_group, args[0][i]);
};
// Copy-paste the selected nodes into the new group.
var drag_object = copyPaste.copy(args[1], 1, frame.numberOf, "");
copyPaste.pasteNewNodes(drag_object, template_group, "");
// Select all nodes within group and export as template.
Action.perform( "selectAll()", "Node View" );
copyPaste.createTemplateFromSelection(args[2], args[3]);
Expand Down
73 changes: 48 additions & 25 deletions pype/modules/ftrack/actions/action_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ def interface(self, session, entities, event):
anatomy = Anatomy(project_name)
new_anatomies = []
first = None
for key in (anatomy.templates.get("delivery") or {}):
new_anatomies.append({
"label": key,
"value": key
})
if first is None:
first = key
for key, template in (anatomy.templates.get("delivery") or {}).items():
# Use only keys with `{root}` or `{root[*]}` in value
if isinstance(template, str) and "{root" in template:
new_anatomies.append({
"label": key,
"value": key
})
if first is None:
first = key

skipped = False
# Add message if there are any common components
Expand Down Expand Up @@ -226,12 +228,7 @@ def launch(self, session, entities, event):
if location_path:
location_path = os.path.normpath(location_path)
if not os.path.exists(location_path):
return {
"success": False,
"message": (
"Entered location path does not exists. \"{}\""
).format(location_path)
}
os.makedirs(location_path)

self.db_con.install()
self.db_con.Session["AVALON_PROJECT"] = project_name
Expand Down Expand Up @@ -293,6 +290,20 @@ def launch(self, session, entities, event):
repres_to_deliver.append(repre)

anatomy = Anatomy(project_name)

format_dict = {}
if location_path:
location_path = location_path.replace("\\", "/")
root_names = anatomy.root_names_from_templates(
anatomy.templates["delivery"]
)
if root_names is None:
format_dict["root"] = location_path
else:
format_dict["root"] = {}
for name in root_names:
format_dict["root"][name] = location_path

for repre in repres_to_deliver:
# Get destination repre path
anatomy_data = copy.deepcopy(repre["context"])
Expand Down Expand Up @@ -339,33 +350,41 @@ def launch(self, session, entities, event):
repre_path = self.path_from_represenation(repre, anatomy)
# TODO add backup solution where root of path from component
# is repalced with root
if not frame:
self.process_single_file(
repre_path, anatomy, anatomy_name, anatomy_data
)
args = (
repre_path,
anatomy,
anatomy_name,
anatomy_data,
format_dict
)

if not frame:
self.process_single_file(*args)
else:
self.process_sequence(
repre_path, anatomy, anatomy_name, anatomy_data
)
self.process_sequence(*args)

self.db_con.uninstall()

return self.report()

def process_single_file(
self, repre_path, anatomy, anatomy_name, anatomy_data
self, repre_path, anatomy, anatomy_name, anatomy_data, format_dict
):
anatomy_filled = anatomy.format(anatomy_data)
delivery_path = anatomy_filled["delivery"][anatomy_name]
if format_dict:
template_result = anatomy_filled["delivery"][anatomy_name]
delivery_path = template_result.rootless.format(**format_dict)
else:
delivery_path = anatomy_filled["delivery"][anatomy_name]

delivery_folder = os.path.dirname(delivery_path)
if not os.path.exists(delivery_folder):
os.makedirs(delivery_folder)

self.copy_file(repre_path, delivery_path)

def process_sequence(
self, repre_path, anatomy, anatomy_name, anatomy_data
self, repre_path, anatomy, anatomy_name, anatomy_data, format_dict
):
dir_path, file_name = os.path.split(str(repre_path))

Expand Down Expand Up @@ -408,8 +427,12 @@ def process_sequence(
anatomy_data["frame"] = frame_indicator
anatomy_filled = anatomy.format(anatomy_data)

delivery_path = anatomy_filled["delivery"][anatomy_name]
print(delivery_path)
if format_dict:
template_result = anatomy_filled["delivery"][anatomy_name]
delivery_path = template_result.rootless.format(**format_dict)
else:
delivery_path = anatomy_filled["delivery"][anatomy_name]

delivery_folder = os.path.dirname(delivery_path)
dst_head, dst_tail = delivery_path.split(frame_indicator)
dst_padding = src_collection.padding
Expand Down
2 changes: 1 addition & 1 deletion pype/modules/ftrack/lib/avalon_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_avalon_attr(session, split_hierarchical=True):
cust_attrs_query = (
"select id, entity_type, object_type_id, is_hierarchical, default"
" from CustomAttributeConfiguration"
" where group.name = \"avalon\""
" where group.name in (\"avalon\", \"pype\")"
)
all_avalon_attr = session.query(cust_attrs_query).all()
for cust_attr in all_avalon_attr:
Expand Down
122 changes: 44 additions & 78 deletions pype/modules/standalonepublish/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import random
import string

from avalon import io, api
from avalon.tools import publish as av_publish

from avalon import io
import pype
from pype.api import execute
from pype.api import execute, Logger

import pyblish.api
from . import PUBLISH_PATHS


log = Logger().get_logger("standalonepublisher")


def set_context(project, asset, task, app):
Expand Down Expand Up @@ -61,17 +61,12 @@ def set_context(project, asset, task, app):
def publish(data, gui=True):
# cli pyblish seems like better solution
return cli_publish(data, gui)
# # this uses avalon pyblish launch tool
# avalon_api_publish(data, gui)


def avalon_api_publish(data, gui=True):
''' Launches Pyblish (GUI by default)
:param data: Should include data for pyblish and standalone collector
:type data: dict
:param gui: Pyblish will be launched in GUI mode if set to True
:type gui: bool
'''
def cli_publish(data, gui=True):
from . import PUBLISH_PATHS

PUBLISH_SCRIPT_PATH = os.path.join(os.path.dirname(__file__), "publish.py")
io.install()

# Create hash name folder in temp
Expand All @@ -83,83 +78,54 @@ def avalon_api_publish(data, gui=True):
with open(json_data_path, 'w') as outfile:
json.dump(data, outfile)

args = [
"-pp", os.pathsep.join(pyblish.api.registered_paths())
]

envcopy = os.environ.copy()
envcopy["PYBLISH_HOSTS"] = "standalonepublisher"
envcopy["SAPUBLISH_INPATH"] = json_data_path
envcopy["PYBLISHGUI"] = "pyblish_pype"
envcopy["PUBLISH_PATHS"] = os.pathsep.join(PUBLISH_PATHS)

result = execute(
[sys.executable, PUBLISH_SCRIPT_PATH],
env=envcopy
)

result = {}
if os.path.exists(json_data_path):
with open(json_data_path, "r") as f:
result = json.load(f)

if gui:
av_publish.show()
else:
returncode = execute([
sys.executable, "-u", "-m", "pyblish"
] + args, env=envcopy)
log.info(f"Publish result: {result}")

io.uninstall()

return False

def cli_publish(data, gui=True):
io.install()

pyblish.api.deregister_all_plugins()
# Registers Global pyblish plugins
def main(env):
from avalon.tools import publish
# Registers pype's Global pyblish plugins
pype.install()
# Registers Standalone pyblish plugins
for path in PUBLISH_PATHS:

# Register additional paths
addition_paths_str = env.get("PUBLISH_PATHS") or ""
addition_paths = addition_paths_str.split(os.pathsep)
for path in addition_paths:
path = os.path.normpath(path)
if not os.path.exists(path):
continue
pyblish.api.register_plugin_path(path)

project_plugins_paths = os.environ.get("PYPE_PROJECT_PLUGINS")
# Register project specific plugins
project_name = os.environ["AVALON_PROJECT"]
if project_plugins_paths and project_name:
for path in project_plugins_paths.split(os.pathsep):
if not path:
continue
plugin_path = os.path.join(path, project_name, "plugins")
if os.path.exists(plugin_path):
pyblish.api.register_plugin_path(plugin_path)
api.register_plugin_path(api.Loader, plugin_path)
api.register_plugin_path(api.Creator, plugin_path)

# Create hash name folder in temp
chars = "".join([random.choice(string.ascii_letters) for i in range(15)])
staging_dir = tempfile.mkdtemp(chars)

# create json for return data
return_data_path = (
staging_dir + os.path.basename(staging_dir) + 'return.json'
)
# create also json and fill with data
json_data_path = staging_dir + os.path.basename(staging_dir) + '.json'
with open(json_data_path, 'w') as outfile:
json.dump(data, outfile)

args = [
"-pp", os.pathsep.join(pyblish.api.registered_paths())
]

if gui:
args += ["gui"]
project_plugins_paths = env.get("PYPE_PROJECT_PLUGINS") or ""
for path in project_plugins_paths.split(os.pathsep):
plugin_path = os.path.join(path, project_name, "plugins")
if os.path.exists(plugin_path):
pyblish.api.register_plugin_path(plugin_path)

envcopy = os.environ.copy()
envcopy["PYBLISH_HOSTS"] = "standalonepublisher"
envcopy["SAPUBLISH_INPATH"] = json_data_path
envcopy["SAPUBLISH_OUTPATH"] = return_data_path
envcopy["PYBLISH_GUI"] = "pyblish_pype"
return publish.show()

returncode = execute([
sys.executable, "-u", "-m", "pyblish"
] + args, env=envcopy)

result = {}
if os.path.exists(json_data_path):
with open(json_data_path, "r") as f:
result = json.load(f)

io.uninstall()
# TODO: check if was pyblish successful
# if successful return True
print('Check result here')
return False
if __name__ == "__main__":
result = main(os.environ)
sys.exit(not bool(result))
4 changes: 2 additions & 2 deletions pype/modules/standalonepublish/widgets/widget_drop_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def _process_data(self, data):
if data['name'] == item.in_data['name']:
found = True
break
paths = data['files']
paths = list(data['files'])
paths.extend(item.in_data['files'])
c, r = clique.assemble(paths)
if len(c) == 0:
Expand Down Expand Up @@ -392,7 +392,7 @@ def _process_data(self, data):
else:
if data['name'] != item.in_data['name']:
continue
if data['files'] == item.in_data['files']:
if data['files'] == list(item.in_data['files']):
found = True
break
a_name = 'merge'
Expand Down
2 changes: 1 addition & 1 deletion pype/plugins/ftrack/publish/integrate_hierarchy_ftrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IntegrateHierarchyToFtrack(pyblish.api.ContextPlugin):

order = pyblish.api.IntegratorOrder - 0.04
label = 'Integrate Hierarchy To Ftrack'
families = ["clip", "shot"]
families = ["shot"]
optional = False

def process(self, context):
Expand Down
9 changes: 8 additions & 1 deletion pype/plugins/global/publish/extract_burnin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class ExtractBurnin(pype.api.Extractor):
label = "Extract burnins"
order = pyblish.api.ExtractorOrder + 0.03
families = ["review", "burnin"]
hosts = ["nuke", "maya", "shell", "nukestudio", "premiere"]
hosts = [
"nuke",
"maya",
"shell",
"nukestudio",
"premiere",
"standalonepublisher"
]
optional = True

positions = [
Expand Down
2 changes: 1 addition & 1 deletion pype/plugins/global/publish/extract_hierarchy_avalon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ExtractHierarchyToAvalon(pyblish.api.ContextPlugin):

order = pyblish.api.ExtractorOrder - 0.01
label = "Extract Hierarchy To Avalon"
families = ["clip", "shot", "editorial"]
families = ["clip", "shot"]

def process(self, context):
if "hierarchyContext" not in context.data:
Expand Down
Loading

0 comments on commit c5e1a17

Please sign in to comment.