-
Notifications
You must be signed in to change notification settings - Fork 1
/
candy_editor_bin.py
94 lines (76 loc) · 2.33 KB
/
candy_editor_bin.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
##----------------------------------------------------------------##
# find candy library
import os
import os.path
import platform
import sys
try:
import faulthandler
faulthandler.enable ()
except Exception as e:
pass
def isPythonFrozen ():
return hasattr ( sys, "frozen" )
def getMainModulePath ():
if isPythonFrozen ():
p = os.path.dirname ( sys.executable )
if platform.system () == u'Darwin':
return os.path.realpath ( p + '/../../..' )
elif platform.system () == u'Windows':
return p
else:
return p
if __name__ == 'main':
mainfile = os.path.realpath ( __file__ )
return os.path.dirname ( mainfile )
else:
import __main__
if hasattr ( __main__, "__candy_path__" ):
return __main__.__candy_path__
else:
mainfile = os.path.realpath ( __main__.__file__ )
return os.path.dirname ( mainfile )
candyPath = getMainModulePath () + '/lib'
candyEditorPath = getMainModulePath () + '/lib/candy_editor'
thirdPartyPathBase = getMainModulePath () + '/lib/3rdparty'
thirdPartyPathCommon = thirdPartyPathBase + '/common'
if platform.system () == u'Darwin':
thirdPartyPathNative = thirdPartyPathBase + '/osx'
else:
thirdPartyPathNative = thirdPartyPathBase + '/windows'
sys.path.insert ( 0, candyPath )
sys.path.insert ( 2, thirdPartyPathNative )
sys.path.insert ( 1, thirdPartyPathCommon )
##----------------------------------------------------------------##
import candy_editor_cfg
import candy_editor
##----------------------------------------------------------------##
DO_PROFILE = False
candy_editor.MODULEPATH = [
candyPath,
thirdPartyPathNative,
thirdPartyPathCommon,
]
PYTHONPATH0 = os.getenv ( 'PYTHONPATH' )
PYTHONPATH1 = (PYTHONPATH0 and PYTHONPATH0 + ':' or '') + (':'.join ( candy_editor.MODULEPATH ))
os.putenv ( 'PYTHONPATH', PYTHONPATH1 )
print ( "PYTHONPATH: %s" % os.getenv ( 'PYTHONPATH' ) )
def main ():
if DO_PROFILE:
import cProfile, pstats
pr = cProfile.Profile ()
pr.enable ()
candy_editor.startup ()
pr.disable ()
ps = pstats.Stats ( pr )
ps.sort_stats ( 'calls', 'time' )
ps.print_stats ()
else:
# print ( "candyPath: %s" % candyPath )
# print ( "thirdPartyPathNative: %s" % thirdPartyPathNative )
# print ( "thirdPartyPathCommon: %s" % thirdPartyPathCommon )
candy_editor.startup ()
if __name__ == '__main__':
if isPythonFrozen ():
sys.argv = [ 'candy_editor', 'stub' ]
main ()