-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunpy.rb
63 lines (56 loc) · 1.12 KB
/
runpy.rb
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
require 'ext'
module Python
def self.runfile(filename)
SimplePipe.run("python #{filename}", 10240).sub(/\0+$/){}
#system("cmd /k python #{filename}")
end
end
class PyMod < ExternalWrapper
def self.init(mod)
self.find(["python26.dll"])
pythondir = File.dirname(DLL)
self[:Py_Initialize].call
self[:PyRun_SimpleString].call %{
import sys
}
self[:PyRun_SimpleString].call %{
try:
sys.path.append("C:\\RMSFX")
sys.path.append(r'#{pythondir}\\DLLs')
sys.path.append(r'#{pythondir}\\lib')
import ctypes
import dem
import struct
dem.init(#{mod})
except Exception as exp:
f = open("runpy.log", "w")
f.write(str(type(exp)))
f.write(str(exp.args))
f.write(str(sys.path))
f.close
}
end
def self.runsimple(string)
self[:PyRun_SimpleString].call %{
import dem
import struct
#{string}
}
end
def self.eval(string)
self[:PyRun_SimpleString].call %{
def func():
#{string}
try:
import dem
import struct
func()
except Exception as exp:
f = open("runpy.log", "w")
f.write(str(type(exp)))
f.write(str(exp.args))
f.write(str(sys.path))
f.close
}
end
end