Class: Yast::LogViewClass
- Inherits:
-
Module
- Object
- Module
- Yast::LogViewClass
- Defined in:
- ../../src/modules/LogView.rb
Instance Method Summary (collapse)
-
- (String) AdvancedHelp(label)
Get the second part of the help for the log in case of advanced functions.
-
- (String) AdvancedSaveHelp(label)
Get the second part of the help for the log in case of advanced functions and save support.
-
- (String) CreateHelp(logs, parameters)
Get the help of the widget.
-
- (Hash) CreateWidget(parameters, log_files)
Get the map with the log view widget.
-
- (Object) Display(parameters)
Main function for displaying logs.
-
- (Object) DisplayFiltered(file, grep)
Display log with filtering with 100 lines.
-
- (Object) DisplaySimple(file)
Display specified file, list 100 lines.
-
- (Yast::Term) GetButtonsBelowLog(popup, glob_param, _log_maps)
Get the buttons below the box with the log.
-
- (Fixnum) GetDefaultItemForLogsCombo(log_maps)
Get the default entry for the combo box with logs.
-
- (Yast::Term) GetLogSelectionCombo(log_maps)
Get the combo box of the available log files.
-
- (Yast::Term) GetMenuButtonWidget(actions, save, mb_label)
Get the widget with the menu button with actions to be processed on the log.
-
- (Object) Index2Descr(index)
Get the map describing the particular log file from its index.
-
- (Object) InitLogReading(index)
Starts the log reading command via process agent.
-
- (Object) KillBackgroundProcess(_key)
Kill processes running on the backgrouns.
-
- (Symbol) LogHandle(_key, event)
Handle the event on the log view widget.
-
- (Object) LogInit(_key)
Initialize the displayed log.
-
- (String) LogSelectionHelp
Get the help for the log in case of multiple logs.
-
- (Object) LogSwitch(index)
Switch the displayed log.
- - (Object) main
-
- (String) SaveHelp
Get the second part of the help for the log in case of save support.
-
- (String) SingleLogHelp
Get the help for the log in case of a single log.
Instance Method Details
- (String) AdvancedHelp(label)
Get the second part of the help for the log in case of advanced functions
142 143 144 145 146 147 148 149 150 151 152 |
# File '../../src/modules/LogView.rb', line 142 def AdvancedHelp(label) # help for the log widget, part 2, alt. 2, %1 is a menu button label Builtins.sformat( _( "<p>\n" \ "To process advanced actions, click <b>%1</b>\n" \ "and select the action to process.</p>" ), label ) end |
- (String) AdvancedSaveHelp(label)
Get the second part of the help for the log in case of advanced functions and save support
127 128 129 130 131 132 133 134 135 136 137 |
# File '../../src/modules/LogView.rb', line 127 def AdvancedSaveHelp(label) # help for the log widget, part 2, alt. 1, %1 is a menu button label Builtins.sformat( _( "<p>\n" \ "To process advanced actions or save the log into a file, click <b>%1</b>\n" \ "and select the action to process.</p>" ), label ) end |
- (String) CreateHelp(logs, parameters)
Get the help of the widget
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File '../../src/modules/LogView.rb', line 169 def CreateHelp(logs, parameters) parameters = deep_copy(parameters) help = Ops.get_string(parameters, "help", "") return help if help != "" && !help.nil? = Ops.get_string(parameters, "mb_label", "") if == "" || .nil? # menu button = _("Ad&vanced") end if Builtins.regexpmatch(, "^.*&.*$") = Builtins.regexpsub(, "^(.*)&(.*)$", "\\1\\2") end save = Ops.get_boolean(parameters, "save", false) save = false if save.nil? actions_lst = Ops.get_list(parameters, "actions", []) actions_lst = [] if actions_lst.nil? actions = Builtins.size(actions_lst) actions = Ops.add(actions, 1) if save if Ops.greater_than(logs, 1) help = LogSelectionHelp() elsif Ops.greater_or_equal(actions, 1) || save help = SingleLogHelp() else return "" end if Ops.greater_or_equal(actions, 2) if save help = Ops.add(help, AdvancedSaveHelp()) else help = Ops.add(help, AdvancedHelp()) end elsif save help = Ops.add(help, SaveHelp()) end help end |
- (Hash) CreateWidget(parameters, log_files)
Get the map with the log view widget <pre> - “save” – boolean, if true, then log saving is possible - “actions” – list, allows to specify additional actions. Each member is a 2- or 3-entry list, first entry is a label for the menubutton, the second one is a function that will be called when the entry is selected, the signature of the function must be void(), optional 3rd argument, if set to true, forces restarting of the log displaying command after the action is performed - “mb_label” – string, label of the menubutton, if not specified, then “Advanced” is used - “max_lines” – integer, maximum of lines to be displayed. If 0, then display whole file. Default is 100. - “help” – string for a rich text, help to be offered via a popup when user clicks the “Help” button. If not present, default help is shown or Help button is hidden. - “widget_height” – height of the LogView widget, to be adjusted so that the widget fits into the dialog well. Test it to find the best value, 15 seems to be good value (is default if not specified) </pre> <pre> - “file” – string, filename with the log - “grep” – string, basic regular expression to be grepped in the log (for getting relevant parts of /var/log/messages. If empty or not present, whole file is used - “command” – allows to specify comand to get the log for cases where grep isn't enough. If used, file and grep entries are ignored - “log_label” – header of the LogView widget, if not set, then the file name or the command is used - “default” – define and set to true to make this log be active after widget is displayed. If not defiend for any log, the first log is automatically default. If defined for multiple logs, the first one is active </pre>
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File '../../src/modules/LogView.rb', line 464 def CreateWidget(parameters, log_files) parameters = deep_copy(parameters) log_files = deep_copy(log_files) # logview caption caption = Ops.get_locale(@param, "log_label", _("&Log")) height = Ops.get_integer(@param, "widget_height", 15) default_index = GetDefaultItemForLogsCombo(log_files) = GetLogSelectionCombo(log_files) = GetButtonsBelowLog(false, parameters, log_files) Builtins.union( { "widget" => :custom, "custom_widget" => VBox( , ReplacePoint( Id(:_cwm_log_rp), LogView(Id(:_cwm_log), caption, height, 0) ), ), "init" => fun_ref(method(:LogInit), "void (string)"), "handle" => fun_ref( method(:LogHandle), "symbol (string, map)" ), "cleanup" => fun_ref( method(:KillBackgroundProcess), "void (string)" ), "ui_timeout" => 1000, "_cwm_default_index" => default_index, "_cwm_log_files" => log_files, "_cwm_button_actions" => [], "help" => CreateHelp( Builtins.size(log_files), parameters ) }, parameters ) end |
- (Object) Display(parameters)
Main function for displaying logs <pre> - “file” – string, filename with the log - “grep” – string, basic regular expression to be grepped in the log (for getting relevant parts of /var/log/messages. If empty or not present, whole file is used - “command” – allows to specify command to get the log for cases where grep isn't enough. If used, file and grep entries are ignored - “save” – boolean, if true, then log saving is possible - “actions” – list, allows to specify additional actions. Each member is a 2- or 3-entry list, first entry is a label for the menubutton, the second one is a function that will be called when the entry is selected, the signature of the function must be void(), optional 3rd argument, if set to true, forces restarting of the log displaying command after the action is performed - “help” – string for a rich text, help to be offered via a popup when user clicks the “Help” button. If not present, Help button isn't shown - “mb_label” – string, label of the menubutton, if not specified, then “Advanced” is used - “max_lines” – integer, maximum of lines to be displayed. If 0, then display whole file. Default is 100. - “log_label” – header of the LogView widget, if not set, then “Log” is used </pre>
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File '../../src/modules/LogView.rb', line 540 def Display(parameters) parameters = deep_copy(parameters) @param = deep_copy(parameters) # menubutton log_label = Ops.get_locale(@param, "log_label", _("&Log")) @logs = [@param] = GetButtonsBelowLog(true, @param, [@param]) UI.OpenDialog( HBox( HSpacing(1), VBox( VSpacing(1), HSpacing(70), # log view header LogView(Id(:_cwm_log), log_label, 19, 0), VSpacing(1), , VSpacing(1) ), HSpacing(1) ) ) if Ops.get_string(@param, "help", "") != "" UI.ReplaceWidget(Id(:rep_left), PushButton(Id(:help), Label.HelpButton)) end @mb_actions = Ops.get_list(@param, "actions", []) InitLogReading(0) ret = nil while ret != :close && ret != :cancel event = UI.WaitForEvent(1000) ret = Ops.get(event, "ID") if ret == :help UI.OpenDialog( VBox( RichText(Id(:help_text), Ops.get_string(@param, "help", "")), HBox( HStretch(), PushButton(Id(:close), Label.CloseButton), HStretch() ) ) ) ret = UI.UserInput while ret != :close && ret != :cancel ret = nil UI.CloseDialog else LogHandle("", event) end end LogViewCore.Stop UI.CloseDialog nil end |
- (Object) DisplayFiltered(file, grep)
Display log with filtering with 100 lines
612 613 614 615 616 |
# File '../../src/modules/LogView.rb', line 612 def DisplayFiltered(file, grep) Display("file" => file, "grep" => grep) nil end |
- (Object) DisplaySimple(file)
Display specified file, list 100 lines
603 604 605 606 607 |
# File '../../src/modules/LogView.rb', line 603 def DisplaySimple(file) Display("file" => file) nil end |
- (Yast::Term) GetButtonsBelowLog(popup, glob_param, _log_maps)
Get the buttons below the box with the log
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File '../../src/modules/LogView.rb', line 293 def GetButtonsBelowLog(popup, glob_param, _log_maps) glob_param = deep_copy(glob_param) left = Empty() center = Empty() if popup center = PushButton(Id(:close), Opt(:key_F9), Label.CloseButton) if Builtins.haskey(glob_param, "help") && Ops.get_string(glob_param, "help", "") != "" left = PushButton(Id(:help), Label.HelpButton) end end save = Ops.get_boolean(glob_param, "save", false) mb_label = Ops.get_locale(glob_param, "mb_label", _("Ad&vanced")) actions = Ops.get_list(glob_param, "actions", []) right = GetMenuButtonWidget(actions, save, mb_label) HBox( HWeight(1, left), HStretch(), HWeight(1, center), HStretch(), HWeight(1, right) ) end |
- (Fixnum) GetDefaultItemForLogsCombo(log_maps)
Get the default entry for the combo box with logs
324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File '../../src/modules/LogView.rb', line 324 def GetDefaultItemForLogsCombo(log_maps) log_maps = deep_copy(log_maps) default_log = 0 if Ops.greater_than(Builtins.size(log_maps), 0) index = -1 Builtins.foreach(log_maps) do |m| index = Ops.add(index, 1) if Builtins.haskey(m, "default") && default_log == 0 default_log = index end end end default_log end |
- (Yast::Term) GetLogSelectionCombo(log_maps)
Get the combo box of the available log files
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File '../../src/modules/LogView.rb', line 217 def GetLogSelectionCombo(log_maps) log_maps = deep_copy(log_maps) selection_combo = Empty() if Ops.greater_than(Builtins.size(log_maps), 0) index = -1 items = Builtins.maplist(log_maps) do |m| index = Ops.add(index, 1) Item( Id(index), Ops.get_locale( # combo box entry (only used as fallback in case # of error in the YaST code) m, "log_label", Ops.get_locale(m, "command", Ops.get_locale(m, "file", _("Log"))) ) ) end selection_combo = ComboBox( Id(:cwm_log_files), Opt(:notify, :hstretch), _("&Log"), items ) end deep_copy(selection_combo) end |
- (Yast::Term) GetMenuButtonWidget(actions, save, mb_label)
Get the widget with the menu button with actions to be processed on the log
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File '../../src/modules/LogView.rb', line 250 def GetMenuButtonWidget(actions, save, mb_label) actions = deep_copy(actions) = [] if save # menubutton entry = Builtins.add(, [:_cwm_log_save, _("&Save Log")]) end if Ops.greater_than(Builtins.size(actions), 0) index = 0 Builtins.foreach(actions) do |a| = Builtins.add( , [index, Ops.get_string(a, 0, "")] ) index = Ops.add(index, 1) end end if Ops.greater_than(Builtins.size(), 1) = Builtins.filter() do |m| m.is_a?(Array) && m.first end = Builtins.maplist() do |m| ml = Convert.to_list(m) Item(Id(Ops.get(ml, 0)), Ops.get_string(ml, 1, "")) end mb_label = _("Ad&vanced") if mb_label == "" || mb_label.nil? return MenuButton(Id(:_cwm_log_menu), mb_label, ) elsif Builtins.size() == 1 return PushButton( Id(Ops.get(, [0, 0], "")), Ops.get_string(, [0, 1], "") ) end Empty() end |
- (Object) Index2Descr(index)
Get the map describing the particular log file from its index
84 85 86 |
# File '../../src/modules/LogView.rb', line 84 def Index2Descr(index) Ops.get(@logs, index, {}) end |
- (Object) InitLogReading(index)
Starts the log reading command via process agent
90 91 92 93 94 95 |
# File '../../src/modules/LogView.rb', line 90 def InitLogReading(index) log_descr = Index2Descr(index) LogViewCore.Start(Id(:_cwm_log), log_descr) nil end |
- (Object) KillBackgroundProcess(_key)
Kill processes running on the backgrouns
99 100 101 102 103 |
# File '../../src/modules/LogView.rb', line 99 def KillBackgroundProcess(_key) LogViewCore.Stop nil end |
- (Symbol) LogHandle(_key, event)
Handle the event on the log view widget
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File '../../src/modules/LogView.rb', line 379 def LogHandle(_key, event) event = deep_copy(event) @param = CWM.GetProcessedWidget LogViewCore.Update(Id(:_cwm_log)) ret = Ops.get(event, "ID") # save the displayed log to file if ret == :_cwm_log_save filename = UI.AskForSaveFileName( # popup caption, save into home directory by default (bnc#653601) "~", "*.log", _("Save Log as...") ) if !filename.nil? SCR.Write( path(".target.string"), filename, Ops.add(Builtins.mergestring(LogViewCore.GetLines, "\n"), "\n") ) end # other operation specified by user elsif !ret.nil? && Ops.is_integer?(ret) iret = Convert.to_integer(ret) func = Convert.convert( Ops.get(@mb_actions, [iret, 1]), from: "any", to: "void ()" ) func.call if !func.nil? if Ops.get(@mb_actions, [iret, 2]) == true KillBackgroundProcess(nil) UI.ChangeWidget(Id(:_cwm_log), :Value, "") InitLogReading(@current_index) end # switch displayed log file elsif ret == :cwm_log_files index = Convert.to_integer(UI.QueryWidget(Id(:cwm_log_files), :Value)) LogSwitch(index) end nil end |
- (Object) LogInit(_key)
Initialize the displayed log
362 363 364 365 366 367 368 369 370 371 372 373 |
# File '../../src/modules/LogView.rb', line 362 def LogInit(_key) @param = CWM.GetProcessedWidget @current_index = Ops.get_integer(@param, "_cwm_default_index", 0) @mb_actions = Ops.get_list(@param, "_cwm_button_actions", []) @logs = Ops.get_list(@param, "_cwm_log_files", []) if UI.WidgetExists(Id(:cwm_log_files)) UI.ChangeWidget(Id(:cwm_log_files), :value, @current_index) end LogSwitch(@current_index) nil end |
- (String) LogSelectionHelp
Get the help for the log in case of multiple logs
107 108 109 110 111 112 113 114 |
# File '../../src/modules/LogView.rb', line 107 def LogSelectionHelp # help for the log widget, part 1, alt. 1 _( "<p><b><big>Displayed Log</big></b><br>\n" \ "Use <b>Log</b> to select the log to display. It will be displayed in\n" \ "the field below.</p>\n" ) end |
- (Object) LogSwitch(index)
Switch the displayed log
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File '../../src/modules/LogView.rb', line 341 def LogSwitch(index) @current_index = index log_descr = Index2Descr(index) # logview caption caption = Ops.get_locale( log_descr, "log_label", Ops.get_locale(@param, "log_label", _("&Log")) ) UI.ReplaceWidget(:_cwm_log_rp, LogView(Id(:_cwm_log), caption, 15, 0)) InitLogReading(index) nil end |
- (Object) main
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File '../../src/modules/LogView.rb', line 52 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Popup" Yast.import "Label" Yast.import "Report" Yast.import "LogViewCore" # fallback settings variables # configuration variables # global parameters for the log displaying widget @param = {} # list of all the logs that can be displayed @logs = [] # index of currently selected log @current_index = 0 # list of actions that can be processed on the logs @mb_actions = [] end |
- (String) SaveHelp
Get the second part of the help for the log in case of save support
156 157 158 159 160 161 162 163 |
# File '../../src/modules/LogView.rb', line 156 def SaveHelp # help for the log widget, part 2, alt. 3 _( "<p>\n" \ "To save the log into a file, click <b>Save Log</b> and select the file\n" \ "to which to save the log.</p>\n" ) end |
- (String) SingleLogHelp
Get the help for the log in case of a single log
118 119 120 121 |
# File '../../src/modules/LogView.rb', line 118 def SingleLogHelp # help for the log widget, part 1, alt. 2 _("<p><b><big>The Log</big></b><br>\nThis screen displays the log.</p>") end |