Sharing
Publishing is about sharing, so let's have a look at how to publish something other than by printing.
1
import os
2
import datetime
3
import pyblish.api
4
5
class CollectUserDir(pyblish.api.ContextPlugin):
6
order = 0
7
8
def process(self, context):
9
context.data["userDir"] = os.path.expanduser("~")
10
11
class WriteTime(pyblish.api.ContextPlugin):
12
order = 1
13
14
def process(self, context):
15
user_dir = context.data["userDir"]
16
destination_path = os.path.join(user_dir, "time.txt")
17
18
print("Writing time to %s" % destination_path)
19
with open(destination_path, "w") as f:
20
f.write("The time is %s" % datetime.datetime.today().ctime())
21
22
pyblish.api.register_plugin(CollectUserDir)
23
pyblish.api.register_plugin(WriteTime)
24
25
import pyblish.util
26
pyblish.util.publish()
27
# Writing time to C:\Users\marcus\Documents\time.txt
Copied!
And here's what time.txt looks like.
1
The time is Thu Jan 21 16:34:58 2016
Copied!
Last modified 1yr ago
Copy link