remote-dcl 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,25 +37,28 @@ or the repository snapshot, <a href="./remote-dcl-snapshot.tar.gz">remote-dcl-sn
37
37
  === Usage
38
38
  ==== At remote server
39
39
  If you do not use xvfb-run command,
40
- you should lounch Xvfb server before execution of remote-dcl.rb.
40
+ you should lounch Xvfb server before execution of remote-dcl.
41
41
  e.g.)
42
42
  % Xvfb :99 -screen 0 640x480x8 -nolisten tcp
43
43
 
44
- Note: xvfb-run command lounch Xvfb server internally, and the lounching is occuer at every execution of remote-dcl.rb.
45
- It takes some seconds, so lounching Xvfb server by your self reduces execution time of remote-dcl.rb.
44
+ Note: xvfb-run command lounch Xvfb server internally, and the lounching is occuer at every execution of remote-dcl.
45
+ It takes some seconds, so lounching Xvfb server by your self reduces execution time of remote-dcl.
46
46
 
47
47
  ==== At local
48
- % ruby remote-dcl.rb yourescript.rb server_name [--display=] [--dir=]
49
- * yourscript.rb:
50
- script name which is executed at the remote server
48
+ % remote-dcl [--display=] [--dir=] [--remote] server_name script_name [args]
51
49
  * server_name:
52
- server name at which the script is execued.
50
+ server name at which the script is execued
51
+ * script_name:
52
+ script name which is executed at the remote server
53
53
  * display (optional):
54
- x server number of Xvfb (e.g. --display=:99).
54
+ x server number of Xvfb (e.g. --display=:99)
55
55
  If this is ommited, xvfb-run comand is used.
56
56
  * dir (optional):
57
- directory name of the remote server at which the script is executed.
57
+ directory name of the remote server at which the script is executed
58
58
  If this is ommited, the script is executed at the home directory.
59
+ * remote (optional):
60
+ If --remote option is set, the script should be at the remote server,
61
+ else at local.
59
62
 
60
63
  === User Interface
61
64
  Actions with key and mouse events are the followings:
@@ -1,5 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  def usage(error = false)
2
- print "Usage: ruby #$0 scriptname host [--display=:99] [--dir=directory]\n"
4
+ print "Usage: #$0 [--display=:99] [--dir=directory] [--remote] server_name script_name [args]\n"
3
5
  print "\n"
4
6
  print " Note: If xvfb-run does not exit at remote server,\n"
5
7
  print " run Xvfb at the remote server before execution of this script:\n"
@@ -10,7 +12,8 @@ end
10
12
  usage if ARGV.index("--help") || ARGV.index("-h")
11
13
  opts = {
12
14
  "display" => nil,
13
- "dir" => nil
15
+ "dir" => nil,
16
+ "remote" => false
14
17
  }
15
18
  opts.keys.each do |name|
16
19
  ARGV.dup.each do |opt|
@@ -19,18 +22,35 @@ opts.keys.each do |name|
19
22
  case name
20
23
  when "display", "dir"
21
24
  opts[name] = val
25
+ when "remote"
26
+ opts[name] = true
22
27
  end
23
28
  ARGV.delete(opt)
24
29
  end
25
30
  end
26
31
 
27
- script = ARGV.shift || usage(true)
28
32
  host = ARGV.shift || usage(true)
33
+ script = ARGV.shift || usage(true)
29
34
 
30
35
 
31
36
 
32
37
 
33
- dcl_code = File.read(script)
38
+ if opts["remote"]
39
+ dcl_code = "load File.expand_path('#{script}')"
40
+ else
41
+ dcl_code = File.read(script)
42
+ dcl_code = <<EOF
43
+ #{dcl_code}
44
+ rescue => error
45
+ backtrace = error.backtrace[0..-3].map do |s|
46
+ a = s.split(':')
47
+ a[0] = 'yourscript.rb' if a[0] == '-e'
48
+ a[1] = a[1].to_i - line
49
+ a.join(':')
50
+ end
51
+ raise error.class, error.message, backtrace
52
+ EOF
53
+ end
34
54
  remote_code = <<EOC
35
55
  pin, pout = IO.pipe
36
56
  pid = fork do
@@ -111,14 +131,6 @@ pid = fork do
111
131
  line = __LINE__ + 1
112
132
  begin
113
133
  #{dcl_code}
114
- rescue => error
115
- backtrace = error.backtrace[0..-3].map do |s|
116
- a = s.split(':')
117
- a[0] = 'yourscript.rb' if a[0] == '-e'
118
- a[1] = a[1].to_i - line
119
- a.join(':')
120
- end
121
- raise error.class, error.message, backtrace
122
134
  ensure
123
135
  Dir[REMOTE_DCL_FNAME+'_*.png'].each do |fname|
124
136
  FileUtils.rm(fname)
@@ -141,7 +153,7 @@ end
141
153
 
142
154
  escape remote_code
143
155
  #cmd = "ruby -e \"#{remote_code}\""
144
- cmd = "stdbuf -i0 -o0 -e0 ruby -e \"#{remote_code}\""
156
+ cmd = "stdbuf -i0 -o0 -e0 ruby -e \"#{remote_code}\" #{ARGV.join(' ')}"
145
157
 
146
158
  class Viewer
147
159
  def initialize(io)
@@ -189,7 +201,7 @@ class Viewer
189
201
  if eof
190
202
  quit
191
203
  elsif @wait
192
- print "next\n"
204
+ # print "next\n"
193
205
  @io.puts "n"
194
206
  @io.flush
195
207
  @wait = false
@@ -197,7 +209,7 @@ class Viewer
197
209
  end
198
210
  def quit
199
211
  unless @quit
200
- print "quit\n"
212
+ # print "quit\n"
201
213
  begin
202
214
  @io.puts("q") unless eof
203
215
  @io.flush
@@ -214,7 +226,7 @@ class Viewer
214
226
  end
215
227
  end
216
228
  def render(png)
217
- print "render\n"
229
+ # print "render\n"
218
230
  loader = Gdk::PixbufLoader.open("png")
219
231
  loader.last_write(png)
220
232
  @pixbuf = loader.pixbuf
@@ -1,3 +1,3 @@
1
1
  module RemoteDCL
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote-dcl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seiya Nishizawa