-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathframework.py
75 lines (58 loc) · 2.07 KB
/
framework.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
# Copyright (c) 2019 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 sys
import platform
import sgtk
logger = sgtk.platform.get_logger(__name__)
def get_vendors_path():
"""Return the path to the vendors folder.
The vendors folder is a way to package the dependecies of this framework in a "It just works" manner.
:returns: path to the vendors folder
:rtype: str
"""
return os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"Vendors",
"pkgs.zip",
)
)
def patch_environment():
"""
This function patch the python path to add the required modules to the python path.
"""
# Try to import websocket to see if we are good to go.
vendor_path = get_vendors_path()
if vendor_path not in sys.path:
logger.debug("Adding {} to the python path".format(vendor_path))
sys.path.insert(0, vendor_path)
def unpatch_environment():
"""
Removes the vendors path from the python path.
"""
vendor_path = get_vendors_path()
if vendor_path in sys.path:
sys.path.remove(get_vendors_path())
class CreateClientFramework(sgtk.platform.Framework):
def init_framework(self):
"""
Implemented by deriving classes in order to initialize the app.
Called by the engine as it loads the framework.
"""
self.log_debug("%s: Initializing..." % self)
patch_environment()
def destroy_framework(self):
"""
Implemented by deriving classes in order to tear down the framework.
Called by the engine as it is being destroyed.
"""
self.log_debug("%s: Destroying..." % self)
unpatch_environment()