lib/rbbt/util/python.rb in rbbt-util-5.26.85 vs lib/rbbt/util/python.rb in rbbt-util-5.26.86
- old
+ new
@@ -1,24 +1,46 @@
require 'rbbt-util'
-
require 'pycall/import'
module RbbtPython
extend PyCall::Import
def self.run(mod = nil, imports = nil, &block)
- begin
- if mod
- if imports
- pyfrom mod, :import => imports
- else
- pyimport mod
- end
+ if mod
+ if imports
+ pyfrom mod, :import => imports
+ else
+ pyimport mod
end
+ end
+ module_eval(&block)
+ end
+
+ def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
+ if mod
+ if imports
+ pyfrom mod, :import => imports
+ else
+ pyimport mod
+ end
+ end
+
+ Log.trap_std("Python STDOUT", "Python STDERR", severity, severity_err) do
module_eval(&block)
+ end
+ end
- rescue
- Log.exception $!
+ def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
+ if mod
+ if imports
+ pyfrom mod, :import => imports
+ else
+ pyimport mod
+ end
+ end
+
+ Log.trap_stderr("Python STDERR", severity) do
+ module_eval(&block)
end
end
def self.add_path(path)
self.run 'sys' do