-
Notifications
You must be signed in to change notification settings - Fork 22
/
SlideShowCallbacks.rb
655 lines (544 loc) · 19.4 KB
/
SlideShowCallbacks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
210
211
212
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
240
241
242
243
244
245
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
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
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
require "yast"
require "pathname"
# Yast namespace
module Yast
# Provides the Callbacks for SlideShow
class SlideShowCallbacksClass < Module
include Yast::Logger
def main
Yast.import "Pkg"
Yast.import "UI"
textdomain "packager"
Yast.import "Installation"
Yast.import "Label"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "PackageCallbacks"
Yast.import "Popup"
Yast.import "SlideShow"
Yast.import "PackageSlideShow"
Yast.import "Message"
Yast.import "Directory"
Yast.import "URL"
@_remote_provide = false
@pkg_inprogress = ""
# never show the disk space warning popup during autoinstallation
@ask_again = !Mode.autoinst
# true == continue with the installtion
@user_input = true
end
# Check for user button presses and handle them.
#
# @return true if user wishes to abort
#
def HandleInput
button = UI.PollInput
# in case of cancel ask user if he really wants to quit installation
if [:abort, :cancel].include?(button)
if Mode.normal
SlideShow.SetUserAbort(
Popup.AnyQuestion(
Popup.NoHeadline,
# popup yes-no
_("Do you really want\nto quit the installation?"),
Label.YesButton,
Label.NoButton,
:focus_no
)
)
elsif Stage.initial
SlideShow.SetUserAbort(Popup.ConfirmAbort(:unusable)) # Mode::update (), Stage::cont ()
else
SlideShow.SetUserAbort(Popup.ConfirmAbort(:incomplete))
end
SlideShow.AppendMessageToInstLog(_("Aborted")) if SlideShow.GetUserAbort
else
SlideShow.HandleInput(button)
end
nil
end
# at start of file providal
def StartProvide(name, archivesize, remote)
@pkg_inprogress = name
@_remote_provide = remote
PackageSlideShow.DownloadStart(name, archivesize) if @_remote_provide
nil
end
# during file providal
def ProgressProvide(percent)
PackageSlideShow.DownloadProgress(percent) if @_remote_provide
HandleInput()
!SlideShow.GetUserAbort
end
# Update during package download: Percent, average and current bytes per second.
def ProgressDownload(percent, _bps_avg, _bps_current)
!SlideShow.GetUserAbort
end
# during file providal
def DoneProvide(error, reason, name)
if @_remote_provide
if error
PackageSlideShow.DownloadError(error, reason, name)
else
PackageSlideShow.DownloadEnd
end
@_remote_provide = false
end
return "C" if SlideShow.GetUserAbort
return PackageCallbacks.DoneProvide(error, reason, name) if error.nonzero?
""
end
def ScriptStart(patch_name, patch_version, patch_arch, script_path)
patch_full_name = PackageCallbacks.FormatPatchName(
patch_name,
patch_version,
patch_arch
)
Builtins.y2milestone(
"ScriptStart: patch:%1, script:%2",
patch_full_name,
script_path
)
# reset the progressbar
if UI.WidgetExists(:progressCurrentPackage)
UI.ChangeWidget(:progressCurrentPackage, :Label, patch_full_name)
UI.ChangeWidget(:progressCurrentPackage, :Value, 0)
end
# message in the installation log widget, %1 is a patch name which contains the script
log_line = Builtins.sformat(_("Starting script %1"), patch_full_name)
SlideShow.AppendMessageToInstLog(log_line)
nil
end
def ScriptProgress(ping, output)
Builtins.y2milestone("ScriptProgress: ping:%1, output: %2", ping, output)
if !output.nil? && output != ""
# remove the trailing new line character
if Builtins.substring(output, Ops.subtract(Builtins.size(output), 1), 1) == "\n"
output = Builtins.substring(
output,
0,
Ops.subtract(Builtins.size(output), 1)
)
end
# add the output to the log widget
SlideShow.AppendMessageToInstLog(output)
end
input = UI.PollInput
Builtins.y2milestone("input: %1", input)
![:abort, :close].include?(input)
end
def ScriptProblem(description)
# display Abort/Retry/Ignore popup
PackageCallbacks.ScriptProblem(description)
end
def ScriptFinish
Builtins.y2milestone("ScriptFinish")
nil
end
def Message(patch_name, patch_version, patch_arch, message)
patch_full_name = PackageCallbacks.FormatPatchName(
patch_name,
patch_version,
patch_arch
)
Builtins.y2milestone("Message (%1): %2", patch_full_name, message)
if patch_full_name != ""
# label, %1 is patch name with version and architecture
patch_full_name = Builtins.sformat(_("Patch %1\n\n"), patch_full_name)
end
Popup.LongMessage(Ops.add(patch_full_name, message))
nil
end
#--------------------------------------------------------------------------
# slide show
def YesNoButtonBox
yes_button = PushButton(Id(:yes), Opt(:key_F10), Label.YesButton)
no_button = PushButton(
Id(:no),
Opt(:default, :key_F9),
Label.NoButton
)
HBox(
HStretch(),
HWeight(1, yes_button),
HSpacing(2),
HWeight(1, no_button),
HStretch()
)
end
def YesNoAgainWarning(message)
return @user_input if !@ask_again
icon = Empty()
# show the warning icon if possible
ui_capabilities = UI.GetDisplayInfo
if Ops.get_boolean(ui_capabilities, "HasLocalImageSupport", false)
icon = Image("dialog-warning", "")
end
content = MarginBox(
1.5,
0.5,
VBox(
HBox(
VCenter(icon),
HSpacing(1),
VCenter(Heading(Label.WarningMsg)),
HStretch()
),
VSpacing(0.2),
Left(Label(message)),
VSpacing(0.2),
Left(CheckBox(Id(:dont_ask), Message.DoNotShowMessageAgain)),
VSpacing(0.5),
YesNoButtonBox()
)
)
UI.OpenDialog(Opt(:decorated), content)
ret = UI.UserInput
@ask_again = !Convert.to_boolean(UI.QueryWidget(Id(:dont_ask), :Value))
if !@ask_again
# remember the user input
@user_input = ret == :yes
end
UI.CloseDialog
ret == :yes
end
# Callback that will be called by the packager for each RPM as it is being installed or deleted.
# Note: The packager doesn't call this directly - the corresponding wrapper callbacks do
# and pass the "deleting" flag as appropriate.
#
def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting)
PackageSlideShow.PkgInstallStart(
pkg_name,
pkg_location,
pkg_description,
pkg_size,
deleting
)
HandleInput()
# warn user about exhausted diskspace during installation (not if deleting packages)
if !deleting && @ask_again
pkgdu = Pkg.PkgDU(@pkg_inprogress)
Builtins.y2debug("PkgDU(%1): %2", @pkg_inprogress, pkgdu)
if pkgdu.nil?
# disk usage for each partition is not known
# assume that all files will be installed into the root directory,
# this is the current free space (in bytes)
disk_available = Pkg.TargetAvailable(Installation.destdir)
Builtins.y2milestone(
"Available space (%1): %2",
Installation.destdir,
disk_available
)
if disk_available < 0
log.debug("Data overflow, too much free space available, skipping the check")
elsif disk_available < pkg_size
Builtins.y2warning(
"Not enough free space in %1: available: %2, required: %3",
Installation.destdir,
disk_available,
pkg_size
)
cont = YesNoAgainWarning(
# yes-no popup
_(
"The disk space is nearly exhausted.\nContinue with the installation?"
)
)
SlideShow.SetUserAbort(true) if !cont
end
else
# check each mount point
Builtins.foreach(pkgdu) do |part, data|
# disk sizes from libzypp, in KiB!
_disk_size, used_now, used_future, read_only = *data
# the size difference, how much the package needs on this partition
required_space = used_future - used_now
# skip read-only partitions, the package cannot be installed anyway
if read_only == 1
Builtins.y2debug("Skipping read-only partition %1", part)
next
end
# nothing to install on this partition, skip it (bsc#926841)
if required_space <= 0
log.debug("Nothing to install at #{part}, skipping")
next
end
target_dir = File.join(Installation.destdir, part)
# handle missing directories (not existing yet or incorrect metadata),
# if the directory does not exist then go up, normally it should
# stop at Installation.destdir (but it will stop at "/" at last)
until File.exist?(target_dir)
log.warn("Directory #{target_dir} does not exist")
target_dir = Pathname.new(target_dir).parent.to_s
log.info("Checking the parent directory (#{target_dir})")
end
disk_available = Pkg.TargetAvailable(target_dir)
Builtins.y2debug(
"partition: %1 (%2), available: %3",
part,
target_dir,
disk_available
)
if disk_available < 0
log.debug("Data overflow, too much free space available, skipping the check")
next
end
# we need to convert the size to KiB to compare it with the libzypp size
if (disk_available / 1024) < required_space
Builtins.y2warning(
"Not enough free space in %1 (%2): available: %3, required: %4",
part,
target_dir,
disk_available,
required_space
)
cont = YesNoAgainWarning(
# warning popup - %1 is directory name (e.g. /boot)
Builtins.sformat(
_(
"The disk space in partition %1 is nearly exhausted.\n" \
"Continue with the installation?"
),
part
)
)
SlideShow.SetUserAbort(true) if !cont
# don't check the other partitions
raise Break
end
end
end
end
nil
end
# Notification that a package starts being installed, updated or removed.
def StartPackage(name, location, summary, install_size, is_delete)
PackageCallbacks._package_name = name
PackageCallbacks._package_size = install_size
PackageCallbacks._deleting_package = is_delete
DisplayStartInstall(name, location, summary, install_size, is_delete)
nil
end
# Progress while a package is being installed, updated or removed.
def ProgressPackage(pkg_percent)
PackageSlideShow.PkgInstallProgress(pkg_percent)
HandleInput()
Builtins.y2milestone("Aborted at %1%%", pkg_percent) if SlideShow.GetUserAbort
!SlideShow.GetUserAbort
end
# Notification that a package is finished being installed, updated or removed.
#
# just to override the PackageCallbacks default (which does a 'CloseDialog' :-})
def DonePackage(error, reason)
return "I" if SlideShow.GetUserAbort
ret = ""
if error.nonzero?
ret = PackageCallbacks.DonePackage(error, reason)
# put additional rpm output to the installation log
elsif !reason.nil? && Ops.greater_than(Builtins.size(reason), 0)
Builtins.y2milestone("Additional RPM output: %1", reason)
SlideShow.AppendMessageToInstLog(reason)
end
if Builtins.size(ret).zero? ||
Builtins.tolower(Builtins.substring(ret, 0, 1)) != "r"
PackageSlideShow.PkgInstallDone(
PackageCallbacks._package_name,
PackageCallbacks._package_size,
PackageCallbacks._deleting_package
)
end
ret
end
# at start of file providal
def StartDeltaProvide(_name, _archivesize)
nil
end
# at start of file providal
def StartDeltaApply(_name)
nil
end
# during file providal
def ProgressDeltaApply(_percent)
nil
end
# at end of file providal
def FinishDeltaProvide
nil
end
def ProblemDeltaDownload(descr)
# error in installation log, %1 is detail error description
SlideShow.AppendMessageToInstLog(
Builtins.sformat(_("Failed to download delta RPM: %1"), descr)
)
nil
end
def ProblemDeltaApply(descr)
# error in installation log, %1 is detail error description
SlideShow.AppendMessageToInstLog(
Builtins.sformat(_("Failed to apply delta RPM: %1"), descr)
)
nil
end
# change of repository
# source: 0 .. n-1
# media: 1 .. n
#
def CallbackSourceChange(source, media)
PackageCallbacks.SourceChange(source, media) # inform PackageCallbacks about the change
# display remaining packages
PackageSlideShow.DisplayGlobalProgress
nil
end
def MediaChange(error_code, error, url, product, current, current_label,
wanted, wanted_label, double_sided, devices, current_device)
devices = deep_copy(devices)
PackageCallbacks.MediaChange(
error_code,
error,
url,
product,
current,
current_label,
wanted,
wanted_label,
double_sided,
devices,
current_device
)
end
# Install callbacks for slideshow.
def InstallSlideShowCallbacks
Builtins.y2milestone("InstallSlideShowCallbacks")
Pkg.CallbackStartPackage(
fun_ref(
method(:StartPackage),
"void (string, string, string, integer, boolean)"
)
)
Pkg.CallbackProgressPackage(
fun_ref(method(:ProgressPackage), "boolean (integer)")
)
Pkg.CallbackDonePackage(
fun_ref(method(:DonePackage), "string (integer, string)")
)
Pkg.CallbackStartProvide(
fun_ref(method(:StartProvide), "void (string, integer, boolean)")
)
Pkg.CallbackProgressProvide(
fun_ref(method(:ProgressProvide), "boolean (integer)")
)
Pkg.CallbackDoneProvide(
fun_ref(method(:DoneProvide), "string (integer, string, string)")
)
Pkg.CallbackProgressDownload(
fun_ref(
method(:ProgressDownload),
"boolean (integer, integer, integer)"
)
)
Pkg.CallbackSourceChange(
fun_ref(method(:CallbackSourceChange), "void (integer, integer)")
)
Pkg.CallbackStartDeltaDownload(
fun_ref(method(:StartDeltaProvide), "void (string, integer)")
)
Pkg.CallbackProgressDeltaDownload(
fun_ref(method(:ProgressProvide), "boolean (integer)")
)
Pkg.CallbackProblemDeltaDownload(
fun_ref(method(:ProblemDeltaDownload), "void (string)")
)
Pkg.CallbackFinishDeltaDownload(
fun_ref(method(:FinishDeltaProvide), "void ()")
)
Pkg.CallbackStartDeltaApply(
fun_ref(method(:StartDeltaApply), "void (string)")
)
Pkg.CallbackProgressDeltaApply(
fun_ref(method(:ProgressDeltaApply), "void (integer)")
)
Pkg.CallbackProblemDeltaApply(
fun_ref(method(:ProblemDeltaApply), "void (string)")
)
Pkg.CallbackFinishDeltaApply(
fun_ref(method(:FinishDeltaProvide), "void ()")
)
Pkg.CallbackScriptStart(
fun_ref(method(:ScriptStart), "void (string, string, string, string)")
)
Pkg.CallbackScriptProgress(
fun_ref(method(:ScriptProgress), "boolean (boolean, string)")
)
Pkg.CallbackScriptProblem(
fun_ref(method(:ScriptProblem), "string (string)")
)
Pkg.CallbackScriptFinish(fun_ref(method(:ScriptFinish), "void ()"))
Pkg.CallbackMessage(
fun_ref(
PackageCallbacks.method(:Message),
"boolean (string, string, string, string)"
)
)
Pkg.CallbackMediaChange(
fun_ref(
method(:MediaChange),
"string (string, string, string, string, integer, string, integer, " \
"string, boolean, list <string>, integer)"
)
)
nil
end
# Remove callbacks for slideshow. Should be in SlideShowCallbacks but
# that doesn't work at the moment.
def RemoveSlideShowCallbacks
Builtins.y2milestone("RemoveSlideShowCallbacks")
Pkg.CallbackStartPackage(nil)
Pkg.CallbackProgressPackage(nil)
Pkg.CallbackDonePackage(nil)
Pkg.CallbackStartProvide(nil)
Pkg.CallbackProgressProvide(nil)
Pkg.CallbackDoneProvide(nil)
Pkg.CallbackSourceChange(nil)
Pkg.CallbackStartDeltaDownload(nil)
Pkg.CallbackProgressDeltaDownload(nil)
Pkg.CallbackProblemDeltaDownload(nil)
Pkg.CallbackFinishDeltaDownload(nil)
Pkg.CallbackStartDeltaApply(nil)
Pkg.CallbackProgressDeltaApply(nil)
Pkg.CallbackProblemDeltaApply(nil)
Pkg.CallbackFinishDeltaApply(nil)
Pkg.CallbackScriptStart(nil)
Pkg.CallbackScriptProgress(nil)
Pkg.CallbackScriptProblem(nil)
Pkg.CallbackScriptFinish(nil)
Pkg.CallbackMessage(nil)
nil
end
publish function: :StartProvide, type: "void (string, integer, boolean)"
publish function: :ProgressProvide, type: "boolean (integer)"
publish function: :ProgressDownload, type: "boolean (integer, integer, integer)"
publish function: :DoneProvide, type: "string (integer, string, string)"
publish function: :ScriptStart, type: "void (string, string, string, string)"
publish function: :ScriptProgress, type: "boolean (boolean, string)"
publish function: :ScriptProblem, type: "string (string)"
publish function: :ScriptFinish, type: "void ()"
publish function: :Message, type: "void (string, string, string, string)"
publish function: :DisplayStartInstall, type: "void (string, string, string, integer, boolean)"
publish function: :StartPackage, type: "void (string, string, string, integer, boolean)"
publish function: :ProgressPackage, type: "boolean (integer)"
publish function: :DonePackage, type: "string (integer, string)"
publish function: :StartDeltaProvide, type: "void (string, integer)"
publish function: :StartDeltaApply, type: "void (string)"
publish function: :ProgressDeltaApply, type: "void (integer)"
publish function: :ProblemDeltaDownload, type: "void (string)"
publish function: :ProblemDeltaApply, type: "void (string)"
publish function: :CallbackSourceChange, type: "void (integer, integer)"
publish function: :MediaChange,
type: "string (string, string, string, string, integer, string, integer, " \
"string, boolean, list <string>, integer)"
publish function: :InstallSlideShowCallbacks, type: "void ()"
publish function: :RemoveSlideShowCallbacks, type: "void ()"
end
SlideShowCallbacks = SlideShowCallbacksClass.new
SlideShowCallbacks.main
end