Report I
Publishing is about finding problems and the only way to find them is by bringing them to the surface, to visualise them. So in this example, we'll have a look at how you can do just that.
We can use the results produced during publishing to pretty-print ourselves a report of how things went. This is what we will be producing in this example.
1
Success Plug-in -> Instance
2
----------------------------------------------------------------------
3
1 CollectCaptainAmerica -> None
4
0 ValidateCaptainAmerica -> Captain America
Copied!
Let's dive into the plug-ins now.
1
import pyblish.api
2
3
class CollectCaptainAmerica(pyblish.api.ContextPlugin):
4
order = pyblish.api.CollectorOrder
5
6
def process(self, context):
7
context.create_instance("Captain America", isHero=False)
8
9
class ValidateCaptainAmerica(pyblish.api.InstancePlugin):
10
order = pyblish.api.ValidatorOrder
11
12
def process(self, instance):
13
# Any raised exception will mark a plug-in as failed
14
assert instance.data.get("isHero") == True, "%s must be a hero" % instance
15
16
pyblish.api.register_plugin(CollectCaptainAmerica)
17
pyblish.api.register_plugin(ValidateCaptainAmerica)
18
19
import pyblish.util
20
context = pyblish.util.publish()
Copied!
With context at hand, we can now format the results using the results dictionary stored within.
1
results = context.data.get("results")
2
header = "{:<10}{:<40} -> {}".format("Success", "Plug-in", "Instance")
3
result = "{success:<10}{plugin.__name__:<40} -> {instance}"
4
results = "\n".join(result.format(**r) for r in results)
5
report = """
6
{header}
7
{line}
8
{results}
9
"""
10
print(report.format(header=header,
11
results=results,
12
line="-" * 70))
Copied!
The actual output is this.
1
Success Plug-in -> Instance
2
----------------------------------------------------------------------
3
1 CollectCurrentWorkingDirectory -> None
4
1 CollectCaptainAmerica -> None
5
1 CollectCurrentUser -> None
6
0 ValidateCaptainAmerica -> Captain America
Copied!
The plug-ins CollectCurrentWorkingDirectory and CollectCurrentUser are included by default with Pyblish and adds the following data to the context.
1
cwd: The current working directory at the time of publish
2
user: The currently logged on user
Copied!
Last modified 1yr ago
Copy link