Class: Yast::OnlineUpdateDialogsClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/OnlineUpdateDialogs.rb

Defined Under Namespace

Modules: RebootingPatches

Constant Summary

MAX_PATCHES_WIDGET_HEIGHT =
12

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) confirm_rebooting_patches

Shows dialog with patches that need rebooting and wait for user's decision whether to continue

Returns:

  • (Boolean)

    whether to continue installing patches (true: continue, false: go_back)



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File '../../src/modules/OnlineUpdateDialogs.rb', line 470

def confirm_rebooting_patches
  UI.OpenDialog(rebooting_patches_dialog)
  user_ret = UI.UserInput
  UI.CloseDialog

  case user_ret
    when RebootingPatches::Buttons::CONTINUE
      return true
    when RebootingPatches::Buttons::BACK
      return false
    when RebootingPatches::Buttons::SKIP
      return skip_rebooting_patches
    else
      raise RuntimeError.new "Unhandled return value: #{user_ret}"
  end
end

- (Object) ConfirmAbortUpdate(how_to)

ConfirmAbortUpdate has same layout as/but different text than ConfirmAbort



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
209
# File '../../src/modules/OnlineUpdateDialogs.rb', line 147

def ConfirmAbortUpdate(how_to)
  what_will_happen = ""

  if how_to == :painless
    # Warning text for aborting the update before a patch is installed
    what_will_happen = _(
      "If you abort the installation now, no patch will be installed.\nYour installation will remain untouched.\n"
    )
  elsif how_to == :incomplete
    # Warning text for aborting if some patches are installed, some not
    what_will_happen = _(
      "Patch download and installation in progress.\n" +
        "If you abort the installation now, the update is incomplete.\n" +
        "Repeat the update, including the download, if desired.\n"
    )
  elsif how_to == :unusable
    # Warning text for aborting an installation during the install process
    what_will_happen = _(
      "If you abort the installation now,\n" +
        "at least one patch is not installed correctly.\n" +
        "You will need to do the update again."
    )
  elsif how_to == :done
    Builtins.y2debug("Aborting after everything should be installed?")
  else
    Builtins.y2warning(
      "Unknown symbol for what will happen when aborting - please correct in calling module"
    )
  end

  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(1),
      VBox(
        VSpacing(0.2),
        HCenter(
          HSquash(
            VBox(
              # Confirm user request to abort installation
              Left(Label(_("Really abort YaST Online Update?"))),
              Left(Label(what_will_happen))
            )
          )
        ),
        HBox(
          # Button that will really abort the installation
          PushButton(Id(:really_abort), _("&Abort Update")),
          HStretch(),
          # Button that will continue with the installation
          PushButton(Id(:continue), Opt(:default), _("&Continue Update"))
        ),
        VSpacing(0.2)
      ),
      HSpacing(1)
    )
  )

  ret = UI.UserInput
  UI.CloseDialog

  ret == :really_abort
end

- (Object) DisplayMsgYou(message, header, yes_button, no_button)



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File '../../src/modules/OnlineUpdateDialogs.rb', line 211

def DisplayMsgYou(message, header, yes_button, no_button)
  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(1),
      VBox(
        Left(Heading(header)),
        VSpacing(0.2),
        Label(message),
        HBox(
          PushButton(Id(:yes), yes_button),
          PushButton(Id(:no), Opt(:default), no_button)
        ),
        VSpacing(0.2)
      ),
      HSpacing(1)
    )
  )
  ret = UI.UserInput
  UI.CloseDialog
  ret == :yes
end

- (Object) DisplayMsgYouOk(message, header, ok_button)



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File '../../src/modules/OnlineUpdateDialogs.rb', line 235

def DisplayMsgYouOk(message, header, ok_button)
  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(1),
      VBox(
        Left(Heading(header)),
        VSpacing(0.2),
        Label(message),
        HBox(PushButton(Id(:ok), Opt(:default), ok_button)),
        VSpacing(0.2)
      ),
      HSpacing(1)
    )
  )
  ret = UI.UserInput
  UI.CloseDialog
  ret == :ok
end

- (Object) ErrorPopup(message, details)



142
143
144
# File '../../src/modules/OnlineUpdateDialogs.rb', line 142

def ErrorPopup(message, details)
  Convert.to_symbol(ErrorPopupGeneric(message, details, :plain))
end

- (Object) ErrorPopupGeneric(message, details, type)



42
43
44
45
46
47
48
49
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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File '../../src/modules/OnlineUpdateDialogs.rb', line 42

def ErrorPopupGeneric(message, details, type)
  details = _("No details available.") if Builtins.size(details) == 0

  detailsStringOn = _("&Details <<")
  detailsStringOff = _("&Details >>")

  detailsButton = PushButton(Id(:details), detailsStringOff)

  heading = _("Error")

  buttons = nil
  if type == :skip
    buttons = HBox(
      detailsButton,
      PushButton(Id(:tryagain), _("Try again")),
      PushButton(Id(:skip), _("Skip Patch")),
      PushButton(Id(:all), _("Skip All")),
      PushButton(Id(:abort), _("Abort Update"))
    )
  elsif type == :ignore
    buttons = HBox(
      detailsButton,
      PushButton(Id(:ok), Label.IgnoreButton),
      PushButton(Id(:abort), _("Abort Update"))
    )
  elsif type == :ignorewarning
    heading = _("Warning")
    buttons = HBox(
      detailsButton,
      PushButton(Id(:retry), Label.RetryButton),
      PushButton(Id(:ok), Label.IgnoreButton),
      PushButton(Id(:abort), _("Abort Update"))
    )
  else
    buttons = HBox(detailsButton, PushButton(Id(:ok), Label.OKButton))
  end

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HBox(HSpacing(0.5), Left(Heading(heading))),
      VSpacing(0.2),
      Label(message),
      ReplacePoint(Id(:rp), HBox(HSpacing(0))),
      buttons
    )
  )

  ret = nil
  showDetails = false

  while ret != :ok && ret != :tryagain && ret != :all && ret != :abort &&
      ret != :skip &&
      ret != :retry
    ret = UI.UserInput

    if ret == :details
      if showDetails
        UI.ReplaceWidget(Id(:rp), VSpacing(0))
        UI.ChangeWidget(Id(:details), :Label, detailsStringOff)
      else
        UI.ReplaceWidget(
          Id(:rp),
          HBox(
            HSpacing(0.5),
            HWeight(1, RichText(Opt(:plainText), details)),
            HSpacing(0.5)
          )
        )
        UI.ChangeWidget(Id(:details), :Label, detailsStringOn)
      end
      showDetails = !showDetails
    end
  end

  UI.CloseDialog

  if type != :plain
    return deep_copy(ret)
  else
    if ret == :ok
      return true
    else
      return false
    end
  end
end

- (Array) formatted_rebooting_patches(options = {})

Returns formatted list of patches that need rebooting

Parameters:

  • options (Hash) (defaults to: {})

    , :use_html defines whether HTML can be used (default: false)

Returns:

  • (Array)

    of patches (name: summary)



400
401
402
403
404
405
406
407
408
# File '../../src/modules/OnlineUpdateDialogs.rb', line 400

def formatted_rebooting_patches(options = {})
  patches_needing_reboot.map do |patch|
    if options[:use_html]
      "<b>#{patch["name"]}</b>: #{patch["summary"]}"
    else
      "#{patch["name"]}: #{patch["summary"]}"
    end
  end
end

- (Object) IgnorePopup(message, details)



134
135
136
# File '../../src/modules/OnlineUpdateDialogs.rb', line 134

def IgnorePopup(message, details)
  Convert.to_symbol(ErrorPopupGeneric(message, details, :ignore))
end

- (Object) IgnoreWarningPopup(message, details)



130
131
132
# File '../../src/modules/OnlineUpdateDialogs.rb', line 130

def IgnoreWarningPopup(message, details)
  Convert.to_symbol(ErrorPopupGeneric(message, details, :ignorewarning))
end

- (Object) main



30
31
32
33
34
35
36
37
38
39
40
# File '../../src/modules/OnlineUpdateDialogs.rb', line 30

def main
  Yast.import "Pkg"
  Yast.import "UI"

  textdomain "online-update"

  Yast.import "Label"
  Yast.import "Package"
  Yast.import "Popup"
  Yast.import "Wizard"
end

- (Object) MessagePopup(patches, pre)



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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File '../../src/modules/OnlineUpdateDialogs.rb', line 255

def MessagePopup(patches, pre)
  patches = deep_copy(patches)
  message = ""
  details = ""

  i = 0
  while Ops.less_than(i, Builtins.size(patches))
    patch = Ops.get(patches, i, {})

    name = Ops.get_string(patch, "name", "")
    summary = Ops.get_string(patch, "summary", "")

    info = ""
    if pre
      info = Ops.get_string(patch, "preinformation", "")
    else
      info = Ops.get_string(patch, "postinformation", "")
    end

    header = Builtins.sformat(_("<b>Patch:</b> %1<br>"), name)
    header = Ops.add(
      header,
      Builtins.sformat(_("<b>Summary:</b> %1<br>"), summary)
    )

    message = Ops.add(message, header)
    message = Ops.add(Ops.add(Ops.add(message, "<pre>"), info), "</pre>")

    packages = Ops.get_list(patch, "packages", [])

    if Ops.greater_than(Builtins.size(packages), 0)
      details = Ops.add(details, header)

      details = Ops.add(details, _("<b>Packages:</b>"))

      details = Ops.add(details, "<ul>")

      Builtins.foreach(packages) do |p|
        details = Ops.add(Ops.add(Ops.add(details, "<li>"), p), "</li>")
      end

      details = Ops.add(details, "</ul>")
    end

    i = Ops.add(i, 1)
  end

  detailsStringOn = _("Patch &Details <<")
  detailsStringOff = _("Patch &Details >>")

  detailsButton = PushButton(Id(:details), detailsStringOff)

  detailsTerm = HBox(
    HSpacing(0.5),
    HWeight(1, RichText(Opt(:plainText), details)),
    HSpacing(0.5)
  )

  buttons = nil
  if pre
    buttons = HBox(
      details == "" ? VSpacing(0) : detailsButton,
      PushButton(Id(:ok), _("Install Patch")),
      PushButton(Id(:skip), _("Skip Patch"))
    )
  else
    buttons = HBox(
      details == "" ? VSpacing(0) : detailsButton,
      PushButton(Id(:ok), Label.OKButton)
    )
  end

  w = 20
  h = 5

  if Ops.greater_than(Builtins.size(message), 100)
    w = 60
    h = 15
  end

  Builtins.y2milestone("Going to open the message dialog")

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HSpacing(w),
      VSpacing(0.2),
      HBox(VSpacing(h), RichText(message)),
      ReplacePoint(Id(:rp), VSpacing(0)),
      buttons
    )
  )

  Builtins.y2milestone("Dialog opened")

  ret = nil
  showDetails = false

  while ret != :ok && ret != :skip
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :details
      if showDetails
        UI.ReplaceWidget(Id(:rp), HSpacing(0))
        UI.ChangeWidget(Id(:details), :Label, detailsStringOff)
      else
        UI.ReplaceWidget(
          Id(:rp),
          HBox(HSpacing(0.5), HWeight(1, RichText(details)), HSpacing(0.5))
        )
        UI.ChangeWidget(Id(:details), :Label, detailsStringOn)
      end
      showDetails = !showDetails
    end
  end

  UI.CloseDialog

  if ret == :ok
    return true
  else
    return false
  end
end

- (Object) patches_needing_reboot



390
391
392
393
394
# File '../../src/modules/OnlineUpdateDialogs.rb', line 390

def patches_needing_reboot
  Pkg.ResolvableProperties("", :patch, "").select do |patch|
    patch["status"] == :selected && patch["reboot_needed"]
  end
end

- (Object) rebooting_patches_dialog

Returns dialog definition for listing all patches that need rebooting

Returns:

  • dialog layout



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File '../../src/modules/OnlineUpdateDialogs.rb', line 413

def rebooting_patches_dialog
  patches_desc = formatted_rebooting_patches(:use_html => true)

  # 2 is an additional constant for borders
  min_richtext_heigth = [patches_desc.size, MAX_PATCHES_WIDGET_HEIGHT].min + 2

  return HBox(
    HSpacing(2),
    VBox(
      HSpacing(70),
      # Dialog label above a list of patches
      Label(_("These patches will need rebooting after installation")),
      MinHeight(
        min_richtext_heigth,
        RichText(Opt(:vstretch), patches_desc.join("<br>"))
      ),
      ButtonBox(
        PushButton(Id(RebootingPatches::Buttons::CONTINUE), Opt(:default), Label.ContinueButton),
        PushButton(Id(RebootingPatches::Buttons::BACK), Label.BackButton),
        # Push button for Skipping all patches that require rebooting
        PushButton(Id(RebootingPatches::Buttons::SKIP), _("&Skip All"))
      )
    ),
    HSpacing(2)
  )
end

- (Boolean) report_eol_products

Reports products that have reached their end of life (EOL) support

Returns:

  • (Boolean)

    whether all products are still alive



502
503
504
505
506
507
508
509
510
511
512
513
# File '../../src/modules/OnlineUpdateDialogs.rb', line 502

def report_eol_products
  products_to_report = eol_products
  return true if products_to_report.empty?

  product_names = products_to_report.map do |product|
    log.warn "Product out of support: #{product.inspect}"
    product["display_name"] || product["name"] || product["short_name"]
  end

  show_eol_products(product_names)
  false
end

- (Boolean) skip_rebooting_patches

Tries to neutralize all patches that need rebooting. Returns whether it was successful.

Returns:

  • (Boolean)

    whether skipping rebooting patches was successful



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File '../../src/modules/OnlineUpdateDialogs.rb', line 444

def skip_rebooting_patches
  patches_needing_reboot.each do |patch|
    log.info "Removing patch #{patch["name"]} from selection"
    Pkg.ResolvableNeutral(patch["name"], :patch, true)
  end

  # Solver can't solve it automatically
  return false unless Pkg.PkgSolve(true)

  rebooting_patches = formatted_rebooting_patches

  if ! rebooting_patches.empty?
    Popup.MessageDetails(
      _("Online update was unable to unselect some patches that need rebooting."),
      rebooting_patches.join("\n")
    )
    return false
  end

  true
end

- (Object) SkipPopup(message, details)



138
139
140
# File '../../src/modules/OnlineUpdateDialogs.rb', line 138

def SkipPopup(message, details)
  Convert.to_symbol(ErrorPopupGeneric(message, details, :skip))
end

- (Boolean) validate_selected_patches

Returns boolean whether to continue with patches installation

Returns:

  • (Boolean)

    whether to continue



490
491
492
493
494
495
496
497
# File '../../src/modules/OnlineUpdateDialogs.rb', line 490

def validate_selected_patches
  patches = patches_needing_reboot
  log.info "Patches that need rebooting: #{patches.map{|p| p["name"]}}"

  return true if patches.empty?

  confirm_rebooting_patches
end