Class: OverrideDlg

Inherits:
Object
  • Object
show all
Includes:
BasicLogging
Defined in:
lib/override.rb

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]
@@LIBDIR =
File::dirname(__FILE__)

Constants included from BasicLogging

BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasicLogging

#clear_log, is_muted?, #level, #log, mute, #set_level, #set_target, #target

Constructor Details

#initializeOverrideDlg

Create the object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/override.rb', line 54

def initialize
  @config = Configuration::instance
  # find the supported programs 
  @executables = @@Executables.select do |ex_name|
    program?(ex_name) 
  end
  # As we are calling external programs anyway, 
  # why not continue with that ...
  @xmsg = ENV['PATH'].split(':').any? {|d| Dir.children(d).include?('xmessage')}
  # bof.
end

Class Attribute Details

.cvarsObject (readonly)

Returns the value of attribute cvars.



49
50
51
# File 'lib/override.rb', line 49

def cvars
  @cvars
end

Instance Method Details

#showObject

display a dialog and return the new options.



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
103
104
105
106
# File 'lib/override.rb', line 67

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.message
      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 )
      # ... but then again, we still have a log.
      debug('continue with configured settings')
    end
  end
end