-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrapper.py
88 lines (69 loc) · 2.83 KB
/
bootstrapper.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
import os, sys
from pprint import pprint
# Run C:\Python27\Scripts\pip install requests to install relevant packages
# pip install requests
# pip install python-dateutil
# pip install html5lib
# pip install beautifulsoup4
# pip install bs4
#sys.path.append(os.path.abspath("Backups\\Framework.bundle\\Contents\\Resources\\Platforms\\Shared\\Libraries"))
#sys.path.append(os.path.abspath("C:\\Python27\\Lib\\site-packages"))
# sys.path.append(os.path.abspath("PlexSportsAgent.bundle\\Contents\\Libraries\\Shared"))
def BootstrapScanner():
# Dependencies: Anywhere I might resolve an import directive from
__add_to_sys_path("Backups\\Scanners.bundle\\Contents\\Resources\\Common")
Media = __import_module("Media")
Utils = __add_to_builtins(__import_module("Utils"))
# Import the actual module
__add_to_sys_path("Scanners\\Series")
PlexSportsScanner = __import_module("PlexSportsScanner")
return PlexSportsScanner
def BootstrapAgent():
# Dependencies: Anywhere I might resolve an import directive from
__add_to_sys_path("Backups\\Scanners.bundle\\Contents\\Resources\\Common")
# Simulated dependencies (builtins)
__add_to_sys_path("Debug\\Plex")
Agent = __import_module("Agent")
AudioCodec = __import_module("AudioCodec")
VideoCodec = __import_module("VideoCodec")
Container = __import_module("Container")
Utils = __add_to_builtins(__import_module("Utils"))
MetadataSearchResult = __import__("MetadataSearchResult")
__add_to_builtins(MetadataSearchResult.MetadataSearchResult)
# Import the actual module
#__add_to_sys_path("Plug-ins/PlexSportsAgent.bundle/Contents/Libraries/Shared")
__add_to_sys_path("Plug-ins/PlexSportsAgent.bundle/Contents")
PlexSportsAgent = __import_module("Code", "PlexSportsAgent")
return PlexSportsAgent
def BootstrapScannerAndUnitTests():
# Import the actual module
PlexSportsScanner = BootstrapScanner()
# Import the unit test module
UnitTests = __import_module("UnitTests")
return (PlexSportsScanner, UnitTests)
def __add_to_sys_path(relPath):
abspath = os.path.abspath(relPath)
if not abspath in sys.path:
sys.path.append(abspath)
def __import_module(moduleName, alias=None):
if moduleName not in sys.modules.keys():
module = __add_to_builtins(__add_to_sys_modules(__import__(moduleName), alias))
if alias:
module.__name__ = alias
return module
else:
return sys.modules[moduleName]
def __add_to_sys_modules(module, alias=None):
moduleName = alias or module.__name__
if moduleName not in sys.modules.keys():
sys.modules[moduleName] = module
return module
else:
return sys.modules[moduleName]
def __add_to_builtins(module, alias=None):
moduleName = alias or module.__name__
if moduleName not in __builtins__.keys():
__builtins__[moduleName] = module
return module
else:
return __builtins__[moduleName]