Class: Kopflos::Xvfb
- Inherits:
-
Object
show all
- Defined in:
- lib/kopflos/xvfb.rb
Defined Under Namespace
Classes: Error, NotInstalled, NotSupported
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Xvfb
Returns a new instance of Xvfb.
24
25
26
27
28
29
30
31
|
# File 'lib/kopflos/xvfb.rb', line 24
def initialize(options = {})
@font_path = options[:font_path] || self.class.determine_font_path
@resolution = options[:resolution] || '1024x768x24'
@screen = options[:screen] || '1'
@wait = options[:wait] || 5
@manager = options[:manager] || options[:wm]
raise NotSupported unless self.class.supported?
end
|
Instance Attribute Details
#font_path ⇒ Object
Returns the value of attribute font_path.
22
23
24
|
# File 'lib/kopflos/xvfb.rb', line 22
def font_path
@font_path
end
|
#resolution ⇒ Object
Returns the value of attribute resolution.
22
23
24
|
# File 'lib/kopflos/xvfb.rb', line 22
def resolution
@resolution
end
|
#screen ⇒ Object
Returns the value of attribute screen.
22
23
24
|
# File 'lib/kopflos/xvfb.rb', line 22
def screen
@screen
end
|
#wait ⇒ Object
Returns the value of attribute wait.
22
23
24
|
# File 'lib/kopflos/xvfb.rb', line 22
def wait
@wait
end
|
Class Method Details
.start(options = {}) ⇒ Object
33
34
35
36
37
|
# File 'lib/kopflos/xvfb.rb', line 33
def self.start(options={})
xvfb = new(options)
xvfb.start
xvfb
end
|
.supported? ⇒ Boolean
39
40
41
|
# File 'lib/kopflos/xvfb.rb', line 39
def self.supported?
RUBY_PLATFORM =~ /linux/
end
|
Instance Method Details
#authorize ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/kopflos/xvfb.rb', line 86
def authorize
@origin_env = current_env
ENV['XAUTHORITY'] = authfile.path
ENV['DISPLAY'] = ":#{servernum}.#{@screen}"
IO.popen('xauth source -', 'w') do |xauth|
xauth.puts %Q~add :#{servernum} . #{mcookie}~
end
end
|
#command ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/kopflos/xvfb.rb', line 75
def command
[
executable,
":#{servernum}",
'-br', "-fp", @font_path,
'-screen', @screen,
@resolution,
]
end
|
#running? ⇒ Boolean
52
53
54
|
# File 'lib/kopflos/xvfb.rb', line 52
def running?
!!@server && !!@server.status
end
|
#screenshot(filename = 'screenshot.png') ⇒ Object
71
72
73
|
# File 'lib/kopflos/xvfb.rb', line 71
def screenshot(filename='screenshot.png')
system 'import', '-window', 'root', filename
end
|
#start ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/kopflos/xvfb.rb', line 43
def start
authorize
@server = start_server_in_subprocess
log "started => #{@server.pid}"
sleep @wait @window_manager = start_window_manager
log "finished"
end
|
#stop ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/kopflos/xvfb.rb', line 56
def stop
kill_window_manager
kill_server
Process.wait
rescue Errno::ENOENT => e
rescue Errno::ECHILD => e
rescue Errno::EPIPE => e
ensure
if @servernum
File.unlink( lockfile ) if File.exist?(lockfile)
end
load_env @origin_env
@server = nil
end
|
#to_s ⇒ Object
95
96
97
|
# File 'lib/kopflos/xvfb.rb', line 95
def to_s
"<#{self.class} :#{servernum}.#{@screen}>"
end
|