-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-old.py
executable file
·136 lines (112 loc) · 4.45 KB
/
run-old.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
# Standard library imports.
import sys
import logging
# A list of the directories that contain the application's eggs (any directory
# not specified as an absolute path is treated as being relative to the current
# working directory).
EGG_PATH = ['eggs']
last_trace_was_system_call = False
trace_after_funcname = None
def trace_calls(frame, event, arg):
global last_trace_was_system_call, trace_after_funcname
if event != 'call':
return
co = frame.f_code
func_name = co.co_name
if func_name == 'write':
# Ignore write() calls from print statements
return
if trace_after_funcname is not None:
if func_name == trace_after_funcname:
trace_after_funcname = None
else:
# skip anything until it hits the trace_after function
return
func_line_no = frame.f_lineno
func_filename = co.co_filename
caller = frame.f_back
caller_line_no = caller.f_lineno
caller_filename = caller.f_code.co_filename
if "/python2.7" in caller_filename or "agw/aui" in func_filename or "agw/aui" in caller_filename or "/logging/" in func_filename or "/wx/core.py" in func_filename or "/traits/" in func_filename or "/traits/" in caller_filename or "/traitsui/" in func_filename or "/traitsui/" in caller_filename or "/sre_" in caller_filename or "/logging/" in caller_filename:
if not last_trace_was_system_call:
print(' <system calls>')
last_trace_was_system_call = True
return
last_trace_was_system_call = False
print('%s:%s -> %s %s:%s' % (caller_filename, caller_line_no, func_name, func_filename, func_line_no))
return
def create_global_functions():
def what_called_me():
import traceback
stack = traceback.extract_stack()
count = len(stack) - 2
for i, item in enumerate(stack[:-1]):
print(("#%d %s in %s at %s:%d" % (count - i, item[3], item[2], item[0], item[1])))
import builtins
builtins.what_called_me = what_called_me
create_global_functions()
# # Force wx toolkit to be imported before loading plugins
# from pyface.toolkit import toolkit_object
# toolkit_object("init:_app")
def main(argv):
""" Run the application.
"""
logging.basicConfig(level=logging.WARNING)
for toolkit in ['pyface', 'envisage', 'traits', 'traitsui', 'apptools']:
_ = logging.getLogger(toolkit)
_.setLevel(logging.WARNING)
# check for logging early so we can get logging output during application init
import sawx.utils.wx.error_logger as error_logger
if "-d" in argv:
i = argv.index("-d")
error_logger.enable_loggers(argv[i+1])
else:
logger = logging.getLogger()
logger.setLevel(logging.INFO)
if "--trace" in argv:
i = argv.index("--trace")
argv.pop(i)
sys.settrace(trace_calls)
if "--trace-after" in argv:
global trace_after_funcname
i = argv.index("--trace-after")
argv.pop(i)
funcname = argv.pop(i)
trace_after_funcname = funcname
sys.settrace(trace_calls)
try:
from omnivore.plugin import OmnivoreEditorPlugin
plugins = [OmnivoreEditorPlugin()]
import omnivore.file_type
plugins.extend(omnivore.file_type.plugins)
import omnivore.viewers
plugins.extend(omnivore.viewers.plugins)
except ImportError as e:
plugins = []
raise
except ModuleNotFoundError as e:
plugins = []
raise
from sawx import get_image_path
image_path = [get_image_path("omnivore/icons")]
template_path = []
import omnivore
template_path.append(get_image_path("templates", omnivore))
import atrcopy
path = atrcopy.get_template_path()
template_path.append(path)
# # Crypto is separated to make it easy to make it optional for those
# # framework users who don't want the extra dependencies
# import omnivore_extra.crypto.file_type
# plugins.extend(omnivore_extra.crypto.file_type.plugins)
from sawx.app_init import run
from omnivore.document import SegmentedDocument
from omnivore._metadata import __version__
run(plugins=plugins, use_eggs=False, image_path=image_path, template_path=template_path, document_class=SegmentedDocument, about_version=__version__)
logging.shutdown()
if __name__ == '__main__':
import sys
from sawx.app_init import setup_frozen_logging
setup_frozen_logging()
main(sys.argv)