Skip to content

Commit e562d62

Browse files
committed
testing a startup.py to open a terminal in windows.
1 parent 55f0936 commit e562d62

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

engine.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import tank
1717
import inspect
1818
import logging
19-
import sys
2019
import os
2120
import platform
2221

@@ -179,8 +178,8 @@ def execute_command(self, cmd_key, args):
179178
# This resolves issues with mismatched Qt libraries between the OS and the
180179
# application being launched if it is a DCC that comes with a bundled Qt.
181180
if (
182-
tank.util.is_linux()
183-
and os.environ.get("KDE_FULL_SESSION") is not None
181+
tank.util.is_linux() and
182+
os.environ.get("KDE_FULL_SESSION") is not None
184183
):
185184
QtGui.QApplication.setLibraryPaths([])
186185

startup.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
import sys
3+
import sgtk.context
4+
from sgtk.platform import SoftwareLauncher, SoftwareVersion, LaunchInformation
5+
6+
7+
class ShellLauncher(SoftwareLauncher):
8+
9+
def scan_software(self):
10+
11+
ICON_LOCATION = os.path.join(self.disk_location, "icon_256.png")
12+
TERMINAL_SOFTWARE = {
13+
"darwin": [
14+
SoftwareVersion(
15+
"MacOS",
16+
"Terminal",
17+
"/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal",
18+
icon=ICON_LOCATION,
19+
args=None
20+
),
21+
# SoftwareVersion(
22+
# "2",
23+
# "iTerm",
24+
# "/Applications/iTerm.app/Contents/MacOS/iTerm2",
25+
# icon=ICON_LOCATION,
26+
# args=None
27+
# )
28+
],
29+
"win32": [
30+
SoftwareVersion(
31+
"Windows",
32+
"Terminal",
33+
r"C:\WINDOWS\system32\cmd.exe",
34+
icon=ICON_LOCATION,
35+
args=None
36+
)
37+
],
38+
"linux2": [
39+
SoftwareVersion(
40+
"Gnome",
41+
"Terminal",
42+
r"/usr/bin/gnome-terminal",
43+
icon=ICON_LOCATION,
44+
args=None
45+
)
46+
]
47+
}
48+
49+
return TERMINAL_SOFTWARE[sys.platform]
50+
51+
def prepare_launch(self, exec_path, args, file_to_open=None):
52+
# Construct an environment to launch the DCC in,
53+
# confirm the correct executable path to
54+
# launch, and provide required command line args.
55+
# Return this information as a
56+
# LaunchInformation instance.
57+
correct_executable_path = "python"
58+
command_line_args = "{}".format(os.path.join(self.disk_location, "startup", "bootstrap.py"))
59+
# command_line_args = ""
60+
launch_environment = {}
61+
62+
# once the software has launched, execute
63+
# startup script startup/userSetup.py
64+
# launch_environment["PYTHONPATH"] = os.path.join(self.disk_location, "startup")
65+
launch_environment["PATH"] = os.environ["PATH"] + os.pathsep + os.path.dirname(sys.executable)
66+
launch_environment["SGTK_ENGINE"] = self.engine_name
67+
launch_environment["SGTK_CONTEXT"] = sgtk.context.serialize(self.context)
68+
launch_environment["SGTK_TERMINAL"] = exec_path
69+
70+
# make sure to include some standard fields describing the current context and site
71+
std_env = self.get_standard_plugin_environment()
72+
launch_environment.update(std_env)
73+
74+
launch_information = LaunchInformation(
75+
correct_executable_path,
76+
command_line_args,
77+
launch_environment
78+
)
79+
return launch_information

startup/bootstrap.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import subprocess
3+
4+
5+
def start_toolkit():
6+
"""
7+
Import Toolkit and start up a tk-shell engine based on
8+
environment variables.
9+
"""
10+
11+
# Verify sgtk can be loaded.
12+
try:
13+
import sgtk
14+
except Exception as e:
15+
print "Shotgun: Could not import sgtk! Disabling for now: {}".format(e)
16+
return
17+
18+
# start up toolkit logging to file
19+
sgtk.LogManager().initialize_base_file_handler("tk-shell")
20+
logger = sgtk.LogManager.get_logger(__name__)
21+
22+
logger.debug("Launching toolkit in classic mode.")
23+
24+
# Get the name of the engine to start from the environement
25+
env_engine = os.environ.get("SGTK_ENGINE")
26+
if not env_engine:
27+
print "Shotgun: Missing required environment variable SGTK_ENGINE."
28+
return
29+
30+
# Get the context load from the environment.
31+
env_context = os.environ.get("SGTK_CONTEXT")
32+
if not env_context:
33+
print "Shotgun: Missing required environment variable SGTK_CONTEXT."
34+
return
35+
try:
36+
# Deserialize the environment context
37+
context = sgtk.context.deserialize(env_context)
38+
except Exception as e:
39+
print "Shotgun: Could not create context! Shotgun Pipeline Toolkit will " \
40+
"be disabled. Details: {}".format(e)
41+
return
42+
43+
try:
44+
# Start up the toolkit engine from the environment data
45+
logger.debug(
46+
"Launching engine instance '%s' for context %s" % (env_engine, env_context)
47+
)
48+
print "Starting Toolkit, please be patent..."
49+
sgtk.platform.start_engine(env_engine, context.sgtk, context)
50+
print sgtk.platform.current_engine()
51+
subprocess.Popen(os.environ.get("SGTK_TERMINAL"), shell=True, env=os.environ)
52+
except Exception as e:
53+
print "Shotgun: Could not start engine: {}".format(e)
54+
return
55+
56+
# # Clean up temp env variables.
57+
# del_vars = [
58+
# "SGTK_ENGINE",
59+
# "SGTK_CONTEXT",
60+
# "SGTK_FILE_TO_OPEN",
61+
# "SGTK_LOAD_MAYA_PLUGINS",
62+
# ]
63+
# for var in del_vars:
64+
# if var in os.environ:
65+
# del os.environ[var]
66+
67+
68+
if __name__ == "__main__":
69+
start_toolkit()

0 commit comments

Comments
 (0)