Class: Yast::LogViewClass
- Inherits:
-
Module
- Object
- Module
- Yast::LogViewClass
- Defined in:
- library/log/src/modules/LogView.rb
Instance Method Summary collapse
-
#AdvancedHelp(label) ⇒ String
Get the second part of the help for the log in case of advanced functions.
-
#AdvancedSaveHelp(label) ⇒ String
Get the second part of the help for the log in case of advanced functions and save support.
-
#CreateHelp(logs, parameters) ⇒ String
Get the help of the widget.
-
#CreateWidget(parameters, log_files) ⇒ Hash
Get the map with the log view widget
- "save" -- boolean, if true, then log saving is possible - "actions" -- list, allows to specify additional actions.
-
#Display(parameters) ⇒ Object
Main function for displaying logs
.- "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
-
#DisplayFiltered(file, grep) ⇒ Object
Display log with filtering with 100 lines.
-
#DisplaySimple(file) ⇒ Object
Display specified file, list 100 lines.
-
#GetButtonsBelowLog(popup, glob_param, _log_maps) ⇒ Yast::Term
Get the buttons below the box with the log.
-
#GetDefaultItemForLogsCombo(log_maps) ⇒ Fixnum
Get the default entry for the combo box with logs.
-
#GetLogSelectionCombo(log_maps) ⇒ Yast::Term
Get the combo box of the available log files.
-
#GetMenuButtonWidget(actions, save, mb_label) ⇒ Yast::Term
Get the widget with the menu button with actions to be processed on the log.
-
#Index2Descr(index) ⇒ Object
Get the map describing the particular log file from its index.
-
#InitLogReading(index) ⇒ Object
Starts the log reading command via process agent.
-
#KillBackgroundProcess(_key) ⇒ Object
Kill processes running on the backgrouns.
-
#LogHandle(_key, event) ⇒ Symbol
Handle the event on the log view widget.
-
#LogInit(_key) ⇒ Object
Initialize the displayed log.
-
#LogSelectionHelp ⇒ String
Get the help for the log in case of multiple logs.
-
#LogSwitch(index) ⇒ Object
Switch the displayed log.
- #main ⇒ Object
-
#SaveHelp ⇒ String
Get the second part of the help for the log in case of save support.
-
#SingleLogHelp ⇒ String
Get the help for the log in case of a single log.
Instance Method Details
#AdvancedHelp(label) ⇒ String
Get the second part of the help for the log in case of advanced functions
140 141 142 143 144 145 146 147 148 149 150 |
# File 'library/log/src/modules/LogView.rb', line 140 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 |
#AdvancedSaveHelp(label) ⇒ String
Get the second part of the help for the log in case of advanced functions and save support
125 126 127 128 129 130 131 132 133 134 135 |
# File 'library/log/src/modules/LogView.rb', line 125 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 |
#CreateHelp(logs, parameters) ⇒ String
Get the help of the widget
167 168 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 |
# File 'library/log/src/modules/LogView.rb', line 167 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 = Builtins.regexpsub(, "^(.*)&(.*)$", "\\1\\2") if Builtins.regexpmatch(, "^.*&.*$") 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) help = if save Ops.add(help, AdvancedSaveHelp()) else Ops.add(help, AdvancedHelp()) end elsif save help = Ops.add(help, SaveHelp()) end help end |
#CreateWidget(parameters, log_files) ⇒ Hash
Get the map with the log view widget
- "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)
- "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
456 457 458 459 460 461 462 463 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 |
# File 'library/log/src/modules/LogView.rb', line 456 def CreateWidget(parameters, log_files) parameters = deep_copy(parameters) log_files = deep_copy(log_files) # logview 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), , 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 |
#Display(parameters) ⇒ Object
Main function for displaying logs
- "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
532 533 534 535 536 537 538 539 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 |
# File 'library/log/src/modules/LogView.rb', line 532 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) ) ) UI.ReplaceWidget(Id(:rep_left), PushButton(Id(:help), Label.HelpButton)) if Ops.get_string(@param, "help", "") != "" @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 |
#DisplayFiltered(file, grep) ⇒ Object
Display log with filtering with 100 lines
602 603 604 605 606 |
# File 'library/log/src/modules/LogView.rb', line 602 def DisplayFiltered(file, grep) Display("file" => file, "grep" => grep) nil end |
#DisplaySimple(file) ⇒ Object
Display specified file, list 100 lines
593 594 595 596 597 |
# File 'library/log/src/modules/LogView.rb', line 593 def DisplaySimple(file) Display("file" => file) nil end |
#GetButtonsBelowLog(popup, glob_param, _log_maps) ⇒ Yast::Term
Get the buttons below the box with the log
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'library/log/src/modules/LogView.rb', line 289 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 |
#GetDefaultItemForLogsCombo(log_maps) ⇒ Fixnum
Get the default entry for the combo box with logs
320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'library/log/src/modules/LogView.rb', line 320 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) default_log = index if Builtins.haskey(m, "default") && default_log == 0 end end default_log end |
#GetLogSelectionCombo(log_maps) ⇒ Yast::Term
Get the combo box of the available log files
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'library/log/src/modules/LogView.rb', line 213 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 |
#GetMenuButtonWidget(actions, save, mb_label) ⇒ Yast::Term
Get the widget with the menu button with actions to be processed on the log
246 247 248 249 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 |
# File 'library/log/src/modules/LogView.rb', line 246 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 |
#Index2Descr(index) ⇒ Object
Get the map describing the particular log file from its index
82 83 84 |
# File 'library/log/src/modules/LogView.rb', line 82 def Index2Descr(index) Ops.get(@logs, index, {}) end |
#InitLogReading(index) ⇒ Object
Starts the log reading command via process agent
88 89 90 91 92 93 |
# File 'library/log/src/modules/LogView.rb', line 88 def InitLogReading(index) log_descr = Index2Descr(index) LogViewCore.Start(Id(:_cwm_log), log_descr) nil end |
#KillBackgroundProcess(_key) ⇒ Object
Kill processes running on the backgrouns
97 98 99 100 101 |
# File 'library/log/src/modules/LogView.rb', line 97 def KillBackgroundProcess(_key) LogViewCore.Stop nil end |
#LogHandle(_key, event) ⇒ Symbol
Handle the event on the log view widget
371 372 373 374 375 376 377 378 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 |
# File 'library/log/src/modules/LogView.rb', line 371 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 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 |
#LogInit(_key) ⇒ Object
Initialize the displayed log
356 357 358 359 360 361 362 363 364 365 |
# File 'library/log/src/modules/LogView.rb', line 356 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", []) UI.ChangeWidget(Id(:cwm_log_files), :value, @current_index) if UI.WidgetExists(Id(:cwm_log_files)) LogSwitch(@current_index) nil end |
#LogSelectionHelp ⇒ String
Get the help for the log in case of multiple logs
105 106 107 108 109 110 111 112 |
# File 'library/log/src/modules/LogView.rb', line 105 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 |
#LogSwitch(index) ⇒ Object
Switch the displayed log
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'library/log/src/modules/LogView.rb', line 335 def LogSwitch(index) @current_index = index log_descr = Index2Descr(index) # logview caption = Ops.get_locale( log_descr, "log_label", Ops.get_locale(@param, "log_label", _("&Log")) ) UI.ReplaceWidget(:_cwm_log_rp, LogView(Id(:_cwm_log), , 15, 0)) InitLogReading(index) nil end |
#main ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'library/log/src/modules/LogView.rb', line 50 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 |
#SaveHelp ⇒ String
Get the second part of the help for the log in case of save support
154 155 156 157 158 159 160 161 |
# File 'library/log/src/modules/LogView.rb', line 154 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 |
#SingleLogHelp ⇒ String
Get the help for the log in case of a single log
116 117 118 119 |
# File 'library/log/src/modules/LogView.rb', line 116 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 |