Class: OverrideDlg
Constant Summary collapse
- XTERM =
'xterm'- WHIPTAIL =
TERMINAL = ‘x-terminal-emulator’
'whiptail'- YAD =
'yad'- ZENITY =
'zenity'- @@Executables =
The external programs which are supported for the time. They will be run in a new process (IO.popen() ). The first program from this array, which is found in the Path, will be used. Whiptail and a pure ruby dialog necessitate that xterm be found, too.
[YAD, ZENITY, WHIPTAIL, XTERM]
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Class Attribute Summary collapse
-
.cvars ⇒ Object
readonly
Returns the value of attribute cvars.
Attributes included from BasicLogging
Instance Method Summary collapse
-
#initialize ⇒ OverrideDlg
constructor
Create the object.
-
#show ⇒ Object
display a dialog and return the new options.
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, #set_target
Constructor Details
#initialize ⇒ OverrideDlg
Create the object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/override.rb', line 49 def initialize @config = Configuration::instance # find the supported programs @executables = @@Executables.select do |ex_name| ENV['PATH'].split(':').each do |dir_name| Dir.entries(dir_name).include?(ex_name) end end # As we are calling external programs anyway, # why not continue with that.... @xmsg = ENV['PATH'].split(':').any? {|d| Dir.children(d).include?('xmessage')} end |
Class Attribute Details
.cvars ⇒ Object (readonly)
Returns the value of attribute cvars.
45 46 47 |
# File 'lib/override.rb', line 45 def cvars @cvars end |
Instance Method Details
#show ⇒ Object
display a dialog and return the new options.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/override.rb', line 63 def show if(@executables && !@executables.empty?) debug('found executables ' << @executables.join(', ') ) opts = nil begin if has?(YAD) return yad_dlg.split.collect {|o| o.to_s}.join(' ') elsif has?(ZENITY) return zenity_dlg.split.collect {|o| o.to_s}.join(' ') elsif has? XTERM if has?(WHIPTAIL) return whiptail_dlg.split.collect {|o| o.to_s}.join(' ') else debug 'using naked xterm' return ruby_dlg.split.collect {|o| o.to_s}.join(' ') end end rescue SystemExit msg = 'Process is cancelled (SystemExit)' info msg exit true rescue Exception => ex msg = 'Error upon showing dialog ' << ex. error(msg) end # no program to show the dialog else msg = "#{File.basename($0)}: No suitable executable found to display the dialog" warn msg # if xmessage is available, give the user a last chance. if @xmsg io = IO.popen('xmessage -buttons continue:0,abort:1 -default abort -print ' << msg) Process.wait(io.pid) # ATTN! read io only once! exit if ('continue' != io.read.to_s.strip ) debug('continue with configured settings') end end end |