Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions pyblish_qml/control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import json
import time
import math
import collections

# Dependencies
Expand Down Expand Up @@ -842,21 +843,27 @@ def on_run(plugins):

def on_discover(plugins, context):
collectors = list()
model = self.data["models"]["item"]

# For backwards compatibility check for existance of
# "plugins_by_targets" method.
if hasattr(pyblish.api, "plugins_by_targets"):
plugins = pyblish.api.plugins_by_targets(plugins, self.targets)

for plugin in plugins:
self.data["models"]["item"].add_plugin(plugin.to_json())
model.add_plugin(plugin.to_json())

# Sort out which of these are Collectors
if not pyblish.lib.inrange(
number=plugin.order,
base=pyblish.api.Collector.order):
continue

if plugin.order >= context.data["postCollectOrder"]:
model.plugins[-1].verb = "Additional"
model.add_section("Additional")
continue

if not plugin.active:
continue

Expand Down Expand Up @@ -885,6 +892,69 @@ def on_reset():

util.defer(self.host.reset, callback=on_reset)

def post_collect(self, on_post_collected):

def on_finished(plugins, context):
# Compute compatibility
for plugin in self.data["models"]["item"].plugins:
if plugin.instanceEnabled:
instances = pyblish.logic.instances_by_plugin(context,
plugin)
plugin.compatibleInstances = list(i.id for i in instances)
else:
plugin.compatibleInstances = [context.id]

self.data["models"]["item"].reorder(context)
self.data["models"]["item"].update_compatibility()

# Hidden sections
for section in self.data["models"]["item"].sections:
if section.name in settings.HiddenSections:
self.hideSection(True, section.name)

on_post_collected()

def on_run(plugins):
"""Fetch instances in their current state, right after reset"""
util.defer(self.host.context,
callback=lambda context: on_finished(plugins, context))

def on_post_collectors(collectors):
plugins = self.host.cached_discover
context = self.host.cached_context

self.run(collectors, context,
callback=on_run,
callback_args=[plugins])

def post_collectors():
plugins = self.host.cached_discover
context = self.host.cached_context
collectors = list()

for plugin in plugins:
# Sort out which of these are Post Collectors
if not pyblish.lib.inrange(
number=plugin.order,
base=pyblish.api.Collector.order):
continue

if plugin.order < context.data["postCollectOrder"]:
continue

if not plugin.active:
continue

collectors.append(plugin)

return collectors

util.defer(post_collectors, callback=on_post_collectors)

def _use_post_collect(self):
context = self.host.cached_context
return not math.isnan(context.data["postCollectOrder"])

@QtCore.pyqtSlot()
def publish(self):
"""Start asynchonous publishing
Expand Down Expand Up @@ -921,6 +991,9 @@ def get_data():

return plugins, instances

def on_post_collected():
util.defer(get_data, callback=on_data_received)

def on_data_received(args):
self.run(*args, callback=on_finished)

Expand All @@ -940,7 +1013,10 @@ def on_finished():
self.info.emit("Published, with errors..")
break

util.defer(get_data, callback=on_data_received)
if self._use_post_collect():
self.post_collect(on_post_collected)
else:
util.defer(get_data, callback=on_data_received)

@QtCore.pyqtSlot()
def validate(self):
Expand Down Expand Up @@ -976,13 +1052,19 @@ def get_data():

return plugins, instances

def on_post_collected():
util.defer(get_data, callback=on_data_received)

def on_data_received(args):
self.run(*args, callback=on_finished)

def on_finished():
self.host.emit("validated", context=None)

util.defer(get_data, callback=on_data_received)
if self._use_post_collect():
self.post_collect(on_post_collected)
else:
util.defer(get_data, callback=on_data_received)

def run(self, plugins, context, callback=None, callback_args=[]):
"""Commence asynchronous tasks
Expand Down
8 changes: 8 additions & 0 deletions pyblish_qml/ipc/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def format_data(data):
"port",
"user",
"connectTime",
"postCollectOrder",
"pyblishVersion",
"pyblishRPCVersion",
"pythonVersion")
Expand Down Expand Up @@ -194,6 +195,13 @@ def format_context(context):
}


def format_post_collect_order(order):
try:
return float(order)
except (TypeError, ValueError):
return float("NaN")


def format_plugins(plugins):
"""Serialise multiple plug-in

Expand Down
4 changes: 4 additions & 0 deletions pyblish_qml/ipc/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self):
self._context = None
self._plugins = None
self._provider = None
self._post_collect = None

self.reset()

Expand All @@ -51,6 +52,8 @@ def reset(self):
self._context = pyblish.api.Context()
self._plugins = pyblish.api.discover()
self._provider = pyblish.plugin.Provider()
self._post_collect = formatting.format_post_collect_order(
os.environ.get("PYBLISH_QML_POST_COLLECT"))

def context(self):
# Append additional metadata to context
Expand All @@ -60,6 +63,7 @@ def context(self):
for key, value in {"host": hosts,
"port": int(port),
"user": getpass.getuser(),
"postCollectOrder": self._post_collect,
"connectTime": pyblish.lib.time(),
"pyblishVersion": pyblish.version,
"pythonVersion": sys.version}.items():
Expand Down
1 change: 1 addition & 0 deletions pyblish_qml/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"port": 0,
"host": "default",
"user": "default",
"postCollectOrder": float("NaN"),
"connectTime": "default",
"pythonVersion": "default",
"pyblishVersion": "default",
Expand Down
4 changes: 4 additions & 0 deletions pyblish_qml/qml/delegates/ContextDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ BaseDelegate {
"key": "Targets",
"value": object.targets
},
{
"key": "Post Collect",
"value": object.postCollectOrder
},
{
"key": "Connected",
"value": Date(Date.parse(object.connectTime))
Expand Down