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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 | class TrayPublishAddon(
AYONAddon, IHostAddon, ITrayAction, IPluginPaths
):
label = "Publisher"
name = "traypublisher"
version = __version__
host_name = "traypublisher"
_choose_dialog = None
def tray_init(self):
return
def get_plugin_paths(self):
return {}
def get_publish_plugin_paths(self, host_name):
output = []
if host_name == self.host_name:
output.append(
os.path.join(TRAYPUBLISH_ROOT_DIR, "plugins", "publish")
)
return output
def get_create_plugin_paths(self, host_name):
output = []
if host_name == self.host_name:
output.append(
os.path.join(TRAYPUBLISH_ROOT_DIR, "plugins", "create")
)
return output
def on_action_trigger(self):
self._show_choose_project()
def cli(self, click_group):
cli_main = click_wrap.group(
self._cli_main,
name=self.name,
help="TrayPublisher commands"
)
cli_main.command(
self._cli_launch,
name="launch",
help="Launch TrayPublish tool UI.",
).option(
"--project",
help="Project name",
envvar="AYON_PROJECT_NAME",
default=None,
)
cli_main.command(
self._cli_ingest_csv,
name="ingestcsv",
).option(
"--filepath",
help="Full path to CSV file with data",
type=str,
required=True
).option(
"--project",
help="Project name in which the context will be used",
type=str,
required=True
).option(
"--folder-path",
help="Asset name in which the context will be used",
type=str,
required=True
).option(
"--task",
help="Task name under Asset in which the context will be used",
type=str,
required=False
).option(
"--ignore-validators",
help="Option to ignore validators",
type=bool,
is_flag=True,
required=False
)
click_group.add_command(cli_main.to_click_obj())
def _cli_main(self):
pass
def _cli_launch(self, project: Optional[str] = None):
from .api.main import launch_traypublisher_ui
launch_traypublisher_ui(self, project)
def _start_traypublisher(self, project_name: str):
args = get_ayon_launcher_args(
"addon", self.name, "launch", "--project", project_name
)
env = os.environ.copy()
env["AYON_PROJECT_NAME"] = project_name
run_detached_process(args, env=env)
def _get_choose_dialog(self):
if self._choose_dialog is None:
from ayon_traypublisher.ui import ChooseProjectWindow
choose_dialog = ChooseProjectWindow()
choose_dialog.accepted.connect(self._on_choose_dialog_accept)
self._choose_dialog = choose_dialog
return self._choose_dialog
def _on_choose_dialog_accept(self):
project_name = self._choose_dialog.get_selected_project_name()
if project_name:
self._start_traypublisher(project_name)
def _show_choose_project(self):
from qtpy import QtCore
window = self._get_choose_dialog()
window.show()
window.setWindowState(
window.windowState()
& ~QtCore.Qt.WindowMinimized
| QtCore.Qt.WindowActive
)
window.activateWindow()
def _cli_ingest_csv(
self,
filepath,
project,
folder_path,
task,
ignore_validators,
):
"""Ingest CSV file into project.
This command will ingest CSV file into project. CSV file must be in
specific format. See documentation for more information.
"""
from .csv_publish import csvpublish
# Allow user override through AYON_USERNAME when
# current connection is made through a service user.
username = os.environ.get("AYON_USERNAME")
if username:
con = ayon_api.get_server_api_connection()
if con.is_service_user():
con.set_default_service_username(username)
# use Path to check if csv_filepath exists
if not Path(filepath).exists():
raise FileNotFoundError(f"File {filepath} does not exist.")
csvpublish(
filepath,
project,
folder_path,
task,
ignore_validators
)
|