/
app_launch.py
73 lines (60 loc) · 2.9 KB
/
app_launch.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
# Copyright (c) 2013 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.
"""
App Launch Hook
This hook is executed to launch the applications.
"""
import os
import re
import sys
import tank
class AppLaunch(tank.Hook):
"""
Hook to run an application.
"""
def execute(self, app_path, app_args, version, engine_name, **kwargs):
"""
The execute functon of the hook will be called to start the required application
:param app_path: (str) The path of the application executable
:param app_args: (str) Any arguments the application may require
:param version: (str) version of the application being run if set in the
"versions" settings of the Launcher instance, otherwise None
:param engine_name (str) The name of the engine associated with the
software about to be launched.
:returns: (dict) The two valid keys are 'command' (str) and 'return_code' (int).
"""
if tank.util.is_linux():
# on linux, we just run the executable directly
cmd = "%s %s &" % (app_path, app_args)
elif tank.util.is_macos():
# If we're on OS X, then we have two possibilities: we can be asked
# to launch an application bundle using the "open" command, or we
# might have been given an executable that we need to treat like
# any other Unix-style command. The best way we have to know whether
# we're in one situation or the other is to check the app path we're
# being asked to launch; if it's a .app, we use the "open" command,
# and if it's not then we treat it like a typical, Unix executable.
if app_path.endswith(".app"):
# The -n flag tells the OS to launch a new instance even if one is
# already running. The -a flag specifies that the path is an
# application and supports both the app bundle form or the full
# executable form.
cmd = 'open -n -a "%s"' % (app_path)
if app_args:
cmd += " --args %s" % app_args
else:
cmd = "%s %s &" % (app_path, app_args)
else:
# on windows, we run the start command in order to avoid
# any command shells popping up as part of the application launch.
cmd = 'start /B "App" "%s" %s' % (app_path, app_args)
# run the command to launch the app
exit_code = os.system(cmd)
return {"command": cmd, "return_code": exit_code}