]>
Commit | Line | Data |
---|---|---|
e57df425 | 1 | #!/usr/bin/env ruby |
0bc67a4f AT |
2 | |
3 | require 'rubygems' | |
a7db8aa6 | 4 | require 'bundler/setup' |
0bc67a4f AT |
5 | require 'json' |
6 | require './unittest' | |
7 | ||
8 | h = Handler.new() | |
9492f34d AT |
9 | f = File.open "/tmp/remotebackend.txt.#{$$}","a" |
10 | f.sync | |
0bc67a4f AT |
11 | |
12 | STDOUT.sync = true | |
13 | begin | |
14 | STDIN.each_line do |line| | |
9492f34d | 15 | f.puts "#{Time.now.to_f}: [pipe] #{line}" |
0bc67a4f AT |
16 | # expect json |
17 | input = {} | |
18 | line = line.strip | |
19 | next if line.empty? | |
20 | begin | |
21 | input = JSON.parse(line) | |
22 | method = "do_#{input["method"].downcase}" | |
f7b89fc4 | 23 | args = input["parameters"] || [] |
0bc67a4f AT |
24 | |
25 | if h.respond_to?(method.to_sym) == false | |
26 | res = false | |
27 | elsif args.size > 0 | |
28 | res, log = h.send(method,args) | |
29 | else | |
30 | res, log = h.send(method) | |
31 | end | |
32 | puts ({:result => res, :log => log}).to_json | |
9492f34d | 33 | f.puts "#{Time.now.to_f} [pipe]: #{({:result => res, :log => log}).to_json}" |
0bc67a4f AT |
34 | rescue JSON::ParserError |
35 | puts ({:result => false, :log => "Cannot parse input #{line}"}).to_json | |
9492f34d | 36 | f.puts "#{Time.now.to_f} [pipe]: #{({:result => false, :log => "Cannot parse input #{line}"}).to_json}" |
0bc67a4f AT |
37 | next |
38 | end | |
39 | end | |
40 | rescue SystemExit, Interrupt | |
41 | end |