forked from northern-bites/tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOOL.py
64 lines (52 loc) · 1.3 KB
/
TOOL.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
import jpype
import platform
import threading
import time
import code
import sys
try:
import robolog
except ImportError:
pass
MAX_HEAP_SIZE = 512
DARWIN = 'Darwin'
PLATFORM = platform.system()
if PLATFORM == DARWIN:
try:
from PyObjCTools import AppHelper
except ImportError:
print "Running on a Mac, you need PyObjC"
print "Please install this package from sourceforge"
CLASSPATH = 'TOOL.jar'
global TOOL
global tool
def println(s):
sys.stdout.write(s + '\n')
sys.stdout.flush()
def startTOOL():
jpype.startJVM(jpype.getDefaultJVMPath(),
'-cp "%s" -Xmx %i' % (CLASSPATH, MAX_HEAP_SIZE))
if PLATFORM == DARWIN:
th = threading.Thread()
th.run = runTOOL
th.start()
AppHelper.runConsoleLoop()
else:
runTOOL()
def runTOOL():
global TOOL, tool
TOOL = jpype.JPackage('TOOL')
init_logging()
tool = TOOL.TOOL()
while tool:
time.sleep(10)
def init_logging():
global TOOL
log_handler = robolog.LogHandler()
proxy = jpype.JProxy('TOOL.Data.LogHandler', inst=log_handler)
TOOL.Data.SourceManager.DEFAULT_LOG_HANDLER = proxy;
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == '-p':
jpype.startJVM(jpype.getDefaultJVMPath(), *sys.argv[2:])
startTOOL()