Class: ServiceControler
- Inherits:
-
Object
- Object
- ServiceControler
- Defined in:
- lib/yasysdui/service_controler.rb
Constant Summary collapse
- @@cmd =
"sudo systemctl"
Instance Attribute Summary collapse
-
#listv ⇒ Object
Returns the value of attribute listv.
-
#restart_bt ⇒ Object
Returns the value of attribute restart_bt.
-
#service ⇒ Object
Returns the value of attribute service.
-
#start_bt ⇒ Object
Returns the value of attribute start_bt.
-
#status_bt ⇒ Object
Returns the value of attribute status_bt.
-
#stop_bt ⇒ Object
Returns the value of attribute stop_bt.
-
#txtv ⇒ Object
Returns the value of attribute txtv.
Instance Method Summary collapse
- #connect_list_sel_to_textv ⇒ Object
- #execute(action) ⇒ Object
- #init_textv ⇒ Object
-
#initialize(txtv, listv) ⇒ ServiceControler
constructor
A new instance of ServiceControler.
- #ui_update(action) ⇒ Object
Constructor Details
#initialize(txtv, listv) ⇒ ServiceControler
Returns a new instance of ServiceControler.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/yasysdui/service_controler.rb', line 17 def initialize(txtv, listv) @txtv = txtv self.init_textv @listv = listv @start_bt = CommandButton.new("Start", self) @stop_bt = CommandButton.new("Stop",self) @status_bt = CommandButton.new("Status", self) @restart_bt = CommandButton.new("Restart", self) connect_list_sel_to_textv end |
Instance Attribute Details
#listv ⇒ Object
Returns the value of attribute listv.
14 15 16 |
# File 'lib/yasysdui/service_controler.rb', line 14 def listv @listv end |
#restart_bt ⇒ Object
Returns the value of attribute restart_bt.
12 13 14 |
# File 'lib/yasysdui/service_controler.rb', line 12 def restart_bt @restart_bt end |
#service ⇒ Object
Returns the value of attribute service.
8 9 10 |
# File 'lib/yasysdui/service_controler.rb', line 8 def service @service end |
#start_bt ⇒ Object
Returns the value of attribute start_bt.
9 10 11 |
# File 'lib/yasysdui/service_controler.rb', line 9 def start_bt @start_bt end |
#status_bt ⇒ Object
Returns the value of attribute status_bt.
11 12 13 |
# File 'lib/yasysdui/service_controler.rb', line 11 def status_bt @status_bt end |
#stop_bt ⇒ Object
Returns the value of attribute stop_bt.
10 11 12 |
# File 'lib/yasysdui/service_controler.rb', line 10 def stop_bt @stop_bt end |
#txtv ⇒ Object
Returns the value of attribute txtv.
13 14 15 |
# File 'lib/yasysdui/service_controler.rb', line 13 def txtv @txtv end |
Instance Method Details
#connect_list_sel_to_textv ⇒ Object
30 31 32 |
# File 'lib/yasysdui/service_controler.rb', line 30 def connect_list_sel_to_textv @listv.signal_connect_sel_changed(self) end |
#execute(action) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/yasysdui/service_controler.rb', line 33 def execute(action) if @service then @action_output, @action_call_status = Open3.capture2e("#@@cmd #{action.downcase} #@service" ) self.ui_update(action) end end |
#init_textv ⇒ Object
27 28 29 |
# File 'lib/yasysdui/service_controler.rb', line 27 def init_textv @txtv.text = "No service selected" end |
#ui_update(action) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yasysdui/service_controler.rb', line 39 def ui_update(action) # (always) update textView buffer text result_text = "#{action}: #{@service.descr} " result_text << "\n Result: #{@action_call_status}" result_text << "\n" + @action_output @txtv.text = result_text # update status info in the result list if action.downcase == 'status' @status_output = @action_output else # not sure if this makes senses in case systemctl call would be non-blocking # but otherwise it makes @status_output, status_call_status = Open3.capture2e("#@@cmd status #@service" ) end @service.set_status_info_from_output( @status_output ) @listv.update_selected_row end |