forked from shotgunsoftware/tk-multi-publish2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
125 lines (100 loc) · 4.09 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright (c) 2017 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
import os
import sgtk
import re
logger = sgtk.platform.get_logger(__name__)
class MultiPublish2(sgtk.platform.Application):
"""
This is the :class:`sgtk.platform.Application` subclass that defines the
top-level publish2 interface.
"""
def init_app(self):
"""
Called as the application is being initialized
"""
tk_multi_publish2 = self.import_module("tk_multi_publish2")
# the manager class provides the interface for publishing. We store a
# reference to it to enable the create_publish_manager method exposed on
# the application itself
self._manager_class = tk_multi_publish2.PublishManager
# make the util methods available via the app instance
self._util = tk_multi_publish2.util
# make the base plugins available via the app
self._base_hooks = tk_multi_publish2.base_hooks
display_name = self.get_setting("display_name")
# "Publish Render" ---> publish_render
command_name = display_name.lower()
# replace all non alphanumeric characters by '_'
command_name = re.sub('[^0-9a-zA-Z]+', '_', command_name)
# register command
cb = lambda: tk_multi_publish2.show_dialog(self)
menu_caption = "%s..." % display_name
menu_options = {
"short_name": command_name,
"description": "Publishing of data to Shotgun",
# dark themed icon for engines that recognize this format
"icons": {
"dark": {
"png": os.path.join(self.disk_location, "icon_256_dark.png")
}
}
}
self.engine.register_command(menu_caption, cb, menu_options)
@property
def base_hooks(self):
"""
Exposes the publish2 ``base_hooks`` module.
This module provides base class implementations of collector and publish
plugin hooks:
- :class:`~.base_hooks.CollectorPlugin`
- :class:`~.base_hooks.PublishPlugin`
Access to these classes won't typically be needed when writing hooks as
they are are injected into the class hierarchy automatically for any
collector or publish plugins configured.
:return: A handle on the app's ``base_hooks`` module.
"""
return self._base_hooks
@property
def util(self):
"""
Exposes the publish2 ``util`` module.
This module provides methods that are useful to collector and publish
plugin hooks. Example code running in a hook:
.. code-block:: python
# get a handle on the publish2 app
app = self.parent
# call a util method
path_components = app.util.get_file_path_components(path)
Some of the methods available via ``util`` are the ``path_info`` hook
methods. Exposing them via this property allows them to be called
directly.
:return: A handle on the app's ``util`` module.
"""
return self._util
@property
def context_change_allowed(self):
"""
Specifies that context changes are allowed.
"""
return True
def create_publish_manager(self):
"""
Create and return a :class:`tk_multi_publish2.PublishManager` instance.
See the :class:`tk_multi_publish2.PublishManager` docs for details on
how it can be used to automate your publishing workflows.
:returns: A :class:`tk_multi_publish2.PublishManager` instance
"""
return self._manager_class()
def destroy_app(self):
"""
Tear down the app
"""
self.log_debug("Destroying tk-multi-publish2")