This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
/
pype_commands.py
311 lines (243 loc) · 9.35 KB
/
pype_commands.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# -*- coding: utf-8 -*-
"""Implementation of Pype commands."""
import os
import sys
import json
import time
import signal
class PypeCommands:
"""Class implementing commands used by Pype.
Most of its methods are called by :mod:`cli` module.
"""
@staticmethod
def launch_tray():
from openpype.lib import Logger
from openpype.tools import tray
Logger.set_process_name("Tray")
tray.main()
@staticmethod
def launch_settings_gui(dev):
from openpype.tools import settings
# TODO change argument options to allow enum of user roles
if dev:
user_role = "developer"
else:
user_role = "manager"
settings.main(user_role)
@staticmethod
def add_modules(click_func):
"""Modules/Addons can add their cli commands dynamically."""
from openpype.lib import Logger
from openpype.modules import ModulesManager
manager = ModulesManager()
log = Logger.get_logger("CLI-AddModules")
for module in manager.modules:
try:
module.cli(click_func)
except Exception:
log.warning(
"Failed to add cli command for module \"{}\"".format(
module.name
)
)
return click_func
@staticmethod
def launch_eventservercli(*args):
from openpype_modules.ftrack.ftrack_server.event_server_cli import (
run_event_server
)
return run_event_server(*args)
@staticmethod
def launch_webpublisher_webservercli(*args, **kwargs):
from openpype.hosts.webpublisher.webserver_service import run_webserver
return run_webserver(*args, **kwargs)
@staticmethod
def launch_traypublisher():
from openpype.tools import traypublisher
traypublisher.main()
@staticmethod
def publish(paths, targets=None, gui=False):
"""Start headless publishing.
Publish use json from passed paths argument.
Args:
paths (list): Paths to jsons.
targets (string): What module should be targeted
(to choose validator for example)
gui (bool): Show publish UI.
Raises:
RuntimeError: When there is no path to process.
"""
from openpype.lib import Logger
from openpype.lib.applications import (
get_app_environments_for_context,
LaunchTypes,
)
from openpype.modules import ModulesManager
from openpype.pipeline import (
install_openpype_plugins,
get_global_context,
)
# Register target and host
import pyblish.api
import pyblish.util
log = Logger.get_logger("CLI-publish")
install_openpype_plugins()
manager = ModulesManager()
publish_paths = manager.collect_plugin_paths()["publish"]
for path in publish_paths:
pyblish.api.register_plugin_path(path)
if not any(paths):
raise RuntimeError("No publish paths specified")
app_full_name = os.getenv("AVALON_APP_NAME")
if app_full_name:
context = get_global_context()
env = get_app_environments_for_context(
context["project_name"],
context["asset_name"],
context["task_name"],
app_full_name,
launch_type=LaunchTypes.farm_publish,
)
os.environ.update(env)
pyblish.api.register_host("shell")
if targets:
for target in targets:
print(f"setting target: {target}")
pyblish.api.register_target(target)
else:
pyblish.api.register_target("farm")
os.environ["OPENPYPE_PUBLISH_DATA"] = os.pathsep.join(paths)
os.environ["HEADLESS_PUBLISH"] = 'true' # to use in app lib
log.info("Running publish ...")
plugins = pyblish.api.discover()
print("Using plugins:")
for plugin in plugins:
print(plugin)
if gui:
from openpype.tools.utils.host_tools import show_publish
from openpype.tools.utils.lib import qt_app_context
with qt_app_context():
show_publish()
else:
# Error exit as soon as any error occurs.
error_format = ("Failed {plugin.__name__}: "
"{error} -- {error.traceback}")
for result in pyblish.util.publish_iter():
if result["error"]:
log.error(error_format.format(**result))
# uninstall()
sys.exit(1)
log.info("Publish finished.")
@staticmethod
def extractenvironments(output_json_path, project, asset, task, app,
env_group):
"""Produces json file with environment based on project and app.
Called by Deadline plugin to propagate environment into render jobs.
"""
from openpype.lib.applications import (
get_app_environments_for_context,
LaunchTypes,
)
if all((project, asset, task, app)):
env = get_app_environments_for_context(
project,
asset,
task,
app,
env_group=env_group,
launch_type=LaunchTypes.farm_render
)
else:
env = os.environ.copy()
output_dir = os.path.dirname(output_json_path)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with open(output_json_path, "w") as file_stream:
json.dump(env, file_stream, indent=4)
@staticmethod
def launch_project_manager():
from openpype.tools import project_manager
project_manager.main()
@staticmethod
def contextselection(output_path, project_name, asset_name, strict):
from openpype.tools.context_dialog import main
main(output_path, project_name, asset_name, strict)
def validate_jsons(self):
pass
def run_tests(self, folder, mark, pyargs,
test_data_folder, persist, app_variant, timeout, setup_only,
mongo_url, app_group, dump_databases):
"""
Runs tests from 'folder'
Args:
folder (str): relative path to folder with tests
mark (str): label to run tests marked by it (slow etc)
pyargs (str): package path to test
test_data_folder (str): url to unzipped folder of test data
persist (bool): True if keep test db and published after test
end
app_variant (str): variant (eg 2020 for AE), empty if use
latest installed version
timeout (int): explicit timeout for single test
setup_only (bool): if only preparation steps should be
triggered, no tests (useful for debugging/development)
mongo_url (str): url to Openpype Mongo database
"""
print("run_tests")
if folder:
folder = " ".join(list(folder))
else:
folder = "../tests"
# disable warnings and show captured stdout even if success
args = [
"--disable-pytest-warnings",
"--capture=sys",
"--print",
"-W ignore::DeprecationWarning",
"-rP",
folder
]
if mark:
args.extend(["-m", mark])
if pyargs:
args.extend(["--pyargs", pyargs])
if test_data_folder:
args.extend(["--test_data_folder", test_data_folder])
if persist:
args.extend(["--persist", persist])
if app_group:
args.extend(["--app_group", app_group])
if app_variant:
args.extend(["--app_variant", app_variant])
if timeout:
args.extend(["--timeout", timeout])
if setup_only:
args.extend(["--setup_only", setup_only])
if mongo_url:
args.extend(["--mongo_url", mongo_url])
if dump_databases:
msg = "dump_databases format is not recognized: {}".format(
dump_databases
)
assert dump_databases in ["bson", "json"], msg
args.extend(["--dump_databases", dump_databases])
print("run_tests args: {}".format(args))
import pytest
pytest.main(args)
def repack_version(self, directory):
"""Repacking OpenPype version."""
from openpype.tools.repack_version import VersionRepacker
version_packer = VersionRepacker(directory)
version_packer.process()
def pack_project(self, project_name, dirpath, database_only):
from openpype.lib.project_backpack import pack_project
if database_only and not dirpath:
raise ValueError((
"Destination dir must be defined when using --dbonly."
" Use '--dirpath {output dir path}' flag"
" to specify directory."
))
pack_project(project_name, dirpath, database_only)
def unpack_project(self, zip_filepath, new_root, database_only):
from openpype.lib.project_backpack import unpack_project
unpack_project(zip_filepath, new_root, database_only)