Class: Yast::LogViewClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/LogView.rb

Instance Method Summary (collapse)

Instance Method Details

- (String) AdvancedHelp(label)

Get the second part of the help for the log in case of advanced functions

Parameters:

  • label (String)

    tge label of the menu button

Returns:

  • (String)

    part of the log



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

Parameters:

  • label (String)

    tge label of the menu button

Returns:

  • (String)

    part of the log



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

Parameters:

  • logs (Fixnum)

    integer count of displayed logs

  • parameters (Hash)

    map parameters of the log to display

Returns:

  • (String)

    help to the widget



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
213
# File '../../src/modules/LogView.rb', line 170

def CreateHelp(logs, parameters)
  parameters = deep_copy(parameters)
  help = Ops.get_string(parameters, "help", "")
  return help if help != "" && help != nil

  adv_button = Ops.get_string(parameters, "mb_label", "")
  if adv_button == "" || adv_button == nil
    # menu button
    adv_button = _("Ad&vanced")
  end

  if Builtins.regexpmatch(adv_button, "^.*&.*$")
    adv_button = Builtins.regexpsub(adv_button, "^(.*)&(.*)$", "\\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(adv_button))
    else
      help = Ops.add(help, AdvancedHelp(adv_button))
    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>

Parameters:

  • parameters (Hash{String => Object})

    map parameters of the widget to be created, will be unioned with the generated map

  • log_files (Array<Hash{String => Object>})

    a list of logs that will be displayed

Returns:

  • (Hash)

    the log widget



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
507
508
509
510
511
512
# File '../../src/modules/LogView.rb', line 470

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)
  top_bar = GetLogSelectionCombo(log_files)
  bottom_bar = GetButtonsBelowLog(false, parameters, log_files)

  Builtins.union(
    {
      "widget"              => :custom,
      "custom_widget"       => VBox(
        top_bar,
        ReplacePoint(
          Id(:_cwm_log_rp),
          LogView(Id(:_cwm_log), caption, height, 0)
        ),
        bottom_bar
      ),
      "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>

Parameters:

  • parameters (Hash{String => Object})

    map description of parameters, with following keys



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
600
601
602
603
604
605
606
607
608
609
610
# File '../../src/modules/LogView.rb', line 548

def Display(parameters)
  parameters = deep_copy(parameters)
  @param = deep_copy(parameters)

  # menubutton
  mb_label = Ops.get_locale(@param, "mb_label", _("Ad&vanced"))
  log_label = Ops.get_locale(@param, "log_label", _("&Log"))

  @logs = [@param]

  button_line = 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),
        button_line,
        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()
          )
        )
      )
      while ret != :close && ret != :cancel
        ret = UI.UserInput
      end
      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

Parameters:

  • file (String)

    string filename of file with the log

  • grep (String)

    string basic regular expression to be grepped in file



623
624
625
626
627
# File '../../src/modules/LogView.rb', line 623

def DisplayFiltered(file, grep)
  Display({ "file" => file, "grep" => grep })

  nil
end

- (Object) DisplaySimple(file)

Display specified file, list 100 lines

Parameters:

  • file (String)

    string filename of file with the log



614
615
616
617
618
# File '../../src/modules/LogView.rb', line 614

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

Parameters:

  • popup (Boolean)

    boolean true if running in popup (and Close is needed)

  • glob_param (Hash{String => Object})

    a map of global parameters of the log widget

  • log_maps (Array<Hash{String => Object>})

    a list of maps describing all the logs

Returns:

  • (Yast::Term)

    the widget with buttons



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File '../../src/modules/LogView.rb', line 296

def GetButtonsBelowLog(popup, glob_param, log_maps)
  glob_param = deep_copy(glob_param)
  log_maps = deep_copy(log_maps)
  left = Empty()
  center = Empty()
  right = 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

Parameters:

  • log_maps (Array<Hash{String => Object>})

    a list of maps describing all the logs

Returns:

  • (Fixnum)

    the index of the default entry in the combo box



329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File '../../src/modules/LogView.rb', line 329

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

Parameters:

  • log_maps (Array<Hash{String => Object>})

    a list of maps describing all the logs

Returns:

  • (Yast::Term)

    the combo box widget



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
244
# File '../../src/modules/LogView.rb', line 218

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

Parameters:

  • actions (Array<Array>)

    a list of all actions

  • save (Boolean)

    boolean true if the log should be offered to be saved

  • mb_label (String)

    label of the menu button, may be empty for default

Returns:

  • (Yast::Term)

    widget with the menu button



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
287
288
# File '../../src/modules/LogView.rb', line 252

def GetMenuButtonWidget(actions, save, mb_label)
  actions = deep_copy(actions)
  menubutton = []
  if save
    # menubutton entry
    menubutton = Builtins.add(menubutton, [:_cwm_log_save, _("&Save Log")])
  end

  if Ops.greater_than(Builtins.size(actions), 0)
    index = 0
    Builtins.foreach(actions) do |a|
      menubutton = Builtins.add(
        menubutton,
        [index, Ops.get_string(a, 0, "")]
      )
      index = Ops.add(index, 1)
    end
  end

  if Ops.greater_than(Builtins.size(menubutton), 1)
    menubutton = Builtins.filter(menubutton) do |m|
      Ops.is_list?(m) && Ops.get(Convert.to_list(m), 0) != nil
    end
    menubutton = Builtins.maplist(menubutton) 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, menubutton)
  elsif Builtins.size(menubutton) == 1
    return PushButton(
      Id(Ops.get(menubutton, [0, 0], "")),
      Ops.get_string(menubutton, [0, 1], "")
    )
  end
  Empty()
end

- (Object) Index2Descr(index)

Get the map describing the particular log file from its index

Parameters:

  • index (Fixnum)

    integer index of the log file

Returns:

  • a map describing the log file



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

Parameters:

  • index (Fixnum)

    integer the index of the log file



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

Parameters:

  • key (String)

    log widget key



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

Parameters:

  • key (String)

    log widget key

  • event (Hash)

    map event to handle

Returns:

  • (Symbol)

    always nil



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
420
421
422
423
424
# File '../../src/modules/LogView.rb', line 384

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

Parameters:

  • key (String)

    log widget key

  • key (String)

    table widget key



367
368
369
370
371
372
373
374
375
376
377
378
# File '../../src/modules/LogView.rb', line 367

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

Returns:

  • (String)

    part of the log



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

Parameters:

  • index (Fixnum)

    integer index of the log to display



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File '../../src/modules/LogView.rb', line 346

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

Returns:

  • (String)

    part of the log



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

Returns:

  • (String)

    part of the 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