/
PackageCallbacks.rb
3798 lines (3200 loc) · 108 KB
/
PackageCallbacks.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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# encoding: utf-8
# ***************************************************************************
#
# Copyright (c) 2002 - 2012 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#
# ***************************************************************************
# Module: PackageCallbacks.ycp
#
# Authors: Gabriele Strattner <gs@suse.de>
# Klaus Kaempf <kkaempf@suse.de>
# Arvin Schnell <arvin@suse.de>
#
# Purpose: provides the default Callbacks for Pkg::
#
# $Id$
#
require "yast"
require "uri"
module Yast
class PackageCallbacksClass < Module
include Yast::Logger
def main
Yast.import "Pkg"
Yast.import "UI"
textdomain "base"
Yast.import "Installation"
Yast.import "Directory"
Yast.import "Label"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "Popup"
Yast.import "URL"
Yast.import "CommandLine"
Yast.import "String"
Yast.import "Report"
Yast.import "Icon"
Yast.import "Wizard"
Yast.import "Progress"
Yast.import "FileUtils"
Yast.import "SignatureCheckCallbacks"
@_provide_popup = false
@_source_popup = false
@_package_popup = false
@_script_popup = false
@_scan_popup = false
@_package_name = ""
@_package_size = 0
@_deleting_package = false
@_current_source = 1
# make showLongInfo module-global so it gets remembered (cf. #14018)
@showLongInfo = false
# used to en-/disable StartPackage, ProgressPackage and DonePackage
@enable_asterix_package = true
@provide_aborted = false
@source_aborted = false
@back_string = "\b\b\b\b\b\b\b\b\b\b"
@clear_string = Ops.add(Ops.add(@back_string, " "), @back_string)
# max. length of the text in the repository popup window
@max_size = 60
@autorefreshing = false
@autorefreshing_aborted = false
# Location of the persistent storage
@conf_file = Ops.add(Directory.vardir, "/package_callbacks.conf")
@config = nil
# auto ejecting is in progress
@doing_eject = false
# seconds for automatic retry after a timeout
@retry_timeout = 30
# number of automatic retries
@retry_attempts = 100
# max. retry timeout (15 minutes)
@retry_max_timeout = 15 * 60
# current values for retry functionality
@retry_url = ""
@current_retry_timeout = @retry_timeout
@current_retry_attempt = 0
@vsize_no_details = 1
#=============================================================================
# MEDIA CHANGE
#=============================================================================
@detected_cd_devices = []
# reference couter to the open popup window
@_source_open = 0
@download_file = ""
# TODO: use the ID in the prgress popup callbacks,
# then callbacks may be nested...
@tick_labels = ["/", "-", "\\", "|"]
@tick_progress = false
@val_progress = false
@current_tick = 0
@progress_task = ""
# ProgressStart/End events may be nested, remember the types of progresses
@progress_stack = []
@last_stage = 0
@opened_wizard = []
PackageCallbacks()
end
def textmode
if Mode.commandline
true
else
Ops.get_boolean(UI.GetDisplayInfo, "TextMode", false)
end
end
def display_width
Mode.commandline ? 0 : Ops.get_integer(UI.GetDisplayInfo, "Width", 0)
end
# functions related to the persistent storage
def LoadConfig
if FileUtils.Exists(@conf_file) && FileUtils.IsFile(@conf_file)
Builtins.y2milestone("Reading config file %1", @conf_file)
read_conf = Convert.to_map(SCR.Read(path(".target.ycp"), @conf_file))
@config = !read_conf.nil? ? read_conf : {}
Builtins.y2milestone("Current config: %1", @config)
else
Builtins.y2milestone(
"No configuration found (file %1 is missing)",
@conf_file
)
end
@config = {} if @config.nil?
nil
end
def GetConfig(key)
LoadConfig() if @config.nil?
Ops.get(@config, key)
end
def SetConfig(key, value)
value = deep_copy(value)
LoadConfig() if @config.nil?
Builtins.y2milestone("Config: setting %1 to %2", key, value)
Ops.set(@config, key, value)
nil
end
def SaveConfig
Builtins.y2milestone("Saving the current config to %1", @conf_file)
SCR.Write(path(".target.ycp"), @conf_file, @config)
end
#--------------------------------------------------------------------------
# defaults
def ProgressBox(heading, name, sz)
progressbox = VBox(
HSpacing(40),
# popup heading
Heading(heading),
Left(
HBox(
VBox(
Left(Label(Opt(:boldFont), _("Package: "))),
Left(Label(Opt(:boldFont), _("Size: ")))
),
VBox(Left(Label(name)), Left(Label(sz)))
)
),
ProgressBar(Id(:progress), " ", 100, 0),
ButtonBox(
PushButton(Id(:abort), Opt(:key_F9, :cancelButton), Label.AbortButton)
)
)
deep_copy(progressbox)
end
def FullScreen
return false if Mode.commandline
ret = UI.WidgetExists(:progress_replace_point)
Builtins.y2debug("Running in fullscreen mode: %1", ret)
ret
end
def RetryLabel(timeout)
Builtins.sformat(
_("Remaining time to automatic retry: %1"),
String.FormatTime(timeout)
)
end
# at start of file providal
#
def StartProvide(name, archivesize, remote)
Builtins.y2milestone("StartProvide: name: %1, remote: %2", name, remote)
if remote
sz = String.FormatSizeWithPrecision(archivesize, 2, false)
if Mode.commandline
CommandLine.PrintVerbose(
Builtins.sformat(_("Downloading package %1 (%2)..."), name, sz)
)
else
UI.CloseDialog if @_provide_popup
if FullScreen()
Progress.SubprogressType(:progress, 100)
Progress.SubprogressTitle(
Builtins.sformat(_("Downloading package %1 (%2)..."), name, sz)
)
else
# popup heading
providebox = ProgressBox(_("Downloading Package"), name, sz)
UI.OpenDialog(providebox)
@_provide_popup = true
end
end
end
nil
end
# during file providal
#
def ProgressProvide(percent)
Builtins.y2milestone("ProgressProvide: %1", percent)
if @_provide_popup
UI.ChangeWidget(Id(:progress), :Value, percent)
@provide_aborted = UI.PollInput == :abort
return !@provide_aborted
elsif Mode.commandline
# there is no popup window, but command line mode is set
CommandLine.PrintVerboseNoCR(
Ops.add(@clear_string, Builtins.sformat("%1%%", percent))
)
end
true
end
# redirect ProgressDeltaApply callback (a different signature is required)
def ProgressDeltaApply(percent)
ProgressProvide(percent)
nil
end
# creates layout for ChangeMediumPopup
def LayoutPopup(message, button_box, vertical_size, info_on)
button_box = deep_copy(button_box)
dialog_layout = VBox(
HSpacing(50), # enforce width
VSpacing(0.1),
HBox(
# maybe more icon types could be used
# "info, "warning", "error"
Icon.Image("warning", "margin_right" => 2),
Left(Label(message))
),
VSpacing(0.1),
HBox(
HSpacing(0.6),
Left(
CheckBox(
Id(:show),
Opt(:notify),
# check box
_("Show &details"),
info_on
)
)
),
VSpacing(0.4),
HBox(
VSpacing(vertical_size),
HSpacing(0.1),
ReplacePoint(Id(:info), Empty()),
HSpacing(0.1)
),
HBox(HSpacing(0.1), button_box, HSpacing(0.1)),
VSpacing(0.2)
)
deep_copy(dialog_layout)
end
def ShowLogInfo(message, buttonbox)
buttonbox = deep_copy(buttonbox)
if UI.QueryWidget(Id(:show), :Value) == true
UI.CloseDialog
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, buttonbox, 10, true)
)
return true
else
UI.CloseDialog
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, buttonbox, @vsize_no_details, false)
)
UI.ReplaceWidget(Id(:info), Empty())
end
false
end
# during file providal
# *
# // return "I" for ignore
# // return "R" for retry
# // return "C" for abort
def DoneProvide(error, reason, name)
Builtins.y2milestone("DoneProvide: %1, %2, %3", error, reason, name)
if @_provide_popup
UI.CloseDialog
@_provide_popup = false
end
if Mode.commandline
# remove the progress
CommandLine.PrintVerboseNoCR(@clear_string)
end
if @provide_aborted
@provide_aborted = false
return "C"
end
# INVALID
if error == 3
# error message, %1 is a package name
message = Builtins.sformat(
_("Package %1 is broken, integrity check has failed."),
name
)
if Mode.commandline
CommandLine.Print(message)
# ask user in the interactive mode
if CommandLine.Interactive
CommandLine.Print("")
# command line mode - ask user whether installation of the failed package should be retried
CommandLine.Print(_("Retry installation of the package?"))
if CommandLine.YesNo
# return Retry
return "R"
end
# command line mode - ask user whether the installation should be aborted
CommandLine.Print(_("Abort the installation?"))
if CommandLine.YesNo
# return Abort
return "C"
end
# otherwise return Ignore (default)
return "I"
end
return "I"
end
button_box = ButtonBox(
PushButton(Id(:abort), Opt(:cancelButton, :key_F9), Label.AbortButton),
PushButton(Id(:retry), Opt(:customButton), Label.RetryButton),
PushButton(Id(:ignore), Opt(:okButton), Label.SkipButton)
)
if @showLongInfo
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, button_box, 10, true)
)
UI.ReplaceWidget(
Id(:info),
RichText(
Opt(:plainText),
Ops.add(Builtins.sformat(_("Error: %1:"), error), reason)
)
)
else
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, button_box, @vsize_no_details, false)
)
UI.ReplaceWidget(Id(:info), Empty())
end
r = nil
loop do
r = UI.UserInput
if r == :show
@showLongInfo = ShowLogInfo(message, button_box)
if @showLongInfo
error_symbol = "ERROR"
if error == 1
error_symbol = "NOT_FOUND"
elsif error == 2
error_symbol = "IO"
elsif error == 3
error_symbol = "INVALID"
end
UI.ReplaceWidget(
Id(:info),
RichText(
Opt(:plainText),
Ops.add(
# error message, %1 is code of the error,
# detail string is appended to the end
Builtins.sformat(_("Error: %1:"), error_symbol),
reason
)
)
)
else
UI.ReplaceWidget(Id(:info), Empty())
end
end
break if r == :abort || r == :retry || r == :ignore
end
Builtins.y2milestone("DoneProvide %1", r)
UI.CloseDialog
return "C" if r == :abort
return "R" if r == :retry
if r == :ignore
# don't show the warning when a refresh fails
if !@autorefreshing
# TODO: add "Don't show again" checkbox
# a warning popup displayed after pressing [Ignore] after a download error
Popup.Warning(
_(
"Ignoring a download failure may result in a broken system.\nVerify the system later by running the Software Management module.\n"
)
)
end
return "I"
end
Builtins.y2error("Unknown user input: %1", r)
end
"I"
end
# Enable or disable StartPackage, ProgressPackage and DonePackage
# callbacks, but only the progress bar and not the final error
# message. Returns old value.
def EnableAsterixPackage(f)
ret = @enable_asterix_package
@enable_asterix_package = f
ret
end
# At start of package install.
def StartPackage(name, _location, _summary, installsize, is_delete)
return if !@enable_asterix_package
@_package_name = name
@_package_size = installsize
@_deleting_package = is_delete
sz = String.FormatSizeWithPrecision(installsize, 2, false)
if Mode.commandline
CommandLine.PrintVerbose(
Builtins.sformat(
if is_delete
_("Uninstalling package %1 (%2)...")
else
_("Installing package %1 (%2)...")
end,
@_package_name,
sz
)
)
else
packagebox = ProgressBox(
is_delete ? _("Uninstalling Package") : _("Installing Package"),
@_package_name,
sz
)
UI.OpenDialog(Opt(:decorated), packagebox)
@_package_popup = true
end
nil
end
# During package install.
def ProgressPackage(percent)
if @_package_popup
UI.ChangeWidget(Id(:progress), :Value, percent)
return UI.PollInput != :abort
elsif Mode.commandline
CommandLine.PrintVerboseNoCR(
Ops.add(@clear_string, Builtins.sformat("%1%%", percent))
)
if percent == 100
# sleep for a wile
Builtins.sleep(200)
# remove the progress
CommandLine.PrintVerboseNoCR(@clear_string)
end
end
true
end
# After package install.
#
# return "I" for ignore
# return "R" for retry
# return "C" for abort (not implemented !)
def DonePackage(error, reason)
# remove invalid characters (bnc#876459)
if !reason.valid_encoding?
reason.encode!("UTF-16", undef: :replace, invalid: :replace, replace: "?")
reason.encode!("UTF-8")
log.warn "Invalid byte sequence found, fixed text: #{reason}"
end
UI.CloseDialog if @_package_popup
@_package_popup = false
if error != 0
Builtins.y2milestone(
"DonePackage(error: %1, reason: '%2')",
error,
reason
)
message = Builtins.sformat(
if @_deleting_package
# error popup during package installation, %1 is the name of the package
_("Removal of package %1 failed.")
else
# error popup during package installation, %1 is the name of the package
_("Installation of package %1 failed.")
end,
@_package_name
)
if Mode.commandline
CommandLine.Print(message)
CommandLine.Print(reason)
# ask user in the interactive mode
if CommandLine.Interactive
CommandLine.Print("")
# command line mode - ask user whether installation of the failed package should be retried
CommandLine.Print(_("Retry installation of the package?"))
if CommandLine.YesNo
# return Retry
return "R"
end
# command line mode - ask user whether the installation should be aborted
CommandLine.Print(_("Abort the installation?"))
if CommandLine.YesNo
# return Abort
return "C"
end
# otherwise return Ignore (default)
return "I"
end
else
button_box = ButtonBox(
PushButton(Id(:abort), Opt(:cancelButton), Label.AbortButton),
PushButton(Id(:retry), Opt(:customButton), Label.RetryButton),
PushButton(Id(:ignore), Opt(:okButton), Label.IgnoreButton)
)
if @showLongInfo
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, button_box, 10, true)
)
UI.ReplaceWidget(Id(:info), RichText(Opt(:plainText), reason))
else
UI.OpenDialog(
Opt(:decorated),
LayoutPopup(message, button_box, @vsize_no_details, false)
)
UI.ReplaceWidget(Id(:info), Empty())
end
r = nil
loop do
r = UI.UserInput
if r == :show
@showLongInfo = ShowLogInfo(message, button_box)
if @showLongInfo
UI.ReplaceWidget(Id(:info), RichText(Opt(:plainText), reason))
else
UI.ReplaceWidget(Id(:info), Empty())
end
end
break if r == :abort || r == :retry || r == :ignore
end
Builtins.y2milestone("DonePackage %1", r)
UI.CloseDialog
if r == :ignore
# TODO: add "Don't show again" checkbox
# a warning popup displayed after pressing [Ignore] after a package installation error
Popup.Warning(
_(
"Ignoring a package failure may result in a broken system.\nThe system should be later verified by running the Software Management module."
)
)
end
return "C" if r == :abort
return "R" if r == :retry
end
# default: ignore
else
# no error, there is additional info (rpm output), see bnc#456446
Builtins.y2milestone("Additional RPM otput: %1", reason)
CommandLine.Print(reason) if Mode.commandline
end
"I"
end
def CDdevices(preferred)
cds = Convert.convert(
SCR.Read(path(".probe.cdrom")),
from: "any",
to: "list <map>"
)
ret = []
Builtins.foreach(cds) do |cd|
dev = Ops.get_string(cd, "dev_name", "")
model = Ops.get_string(cd, "model", "")
deflt = preferred == dev
if !dev.nil? && dev != "" && !model.nil?
ret = Builtins.add(
ret,
Item(
Id(dev),
Ops.add(
Ops.add(deflt ? "\u27A4 " : "", model),
Builtins.sformat(" (%1)", dev)
)
)
)
end
end if !cds.nil?
Builtins.y2milestone("Detected CD devices: %1", ret)
deep_copy(ret)
end
# check and save the autoeject configuration if needed
def CheckAndSaveAutoEject
autoeject = Convert.to_boolean(UI.QueryWidget(Id(:auto_eject), :Value))
current = Convert.to_boolean(GetConfig("automatic_eject"))
current = false if current.nil?
if autoeject != current
SetConfig("automatic_eject", autoeject)
SaveConfig()
end
nil
end
#-------------------------------------------------------------------------
#
# media change callback
#
# if current == -1, show "Ignore"
#
# return "" for ok, retry
# return "E" for eject media
# return "I" for ignore bad media
# return "S" for skip this media
# return "C" for cancel (not implemented !)
# return url to change media URL
def MediaChange(error_code, error, url, product, current, current_label, wanted, wanted_label, double_sided, devices, current_device)
devices = deep_copy(devices)
if @autorefreshing && @autorefreshing_aborted
Builtins.y2milestone("Refresh aborted")
return "C"
end
Builtins.y2milestone(
"MediaChange error: err'%1', url'%2', prd'%3', cur'%4'/'%5', wan'%6'/'%7', devs: %8, curr_dev: %9",
Ops.add(Ops.add(error_code, ":"), error),
URL.HidePassword(url),
product,
current,
current_label,
wanted,
wanted_label,
devices,
current_device
)
url_tokens = URL.Parse(url)
url_scheme = Ops.get_string(url_tokens, "scheme", "")
url_scheme = Builtins.tolower(url_scheme)
# true if it makes sense to offer an eject button (for cd/dvd only ...)
offer_eject_button = url_scheme == "cd" || url_scheme == "dvd"
# do automatic eject
if offer_eject_button &&
Convert.to_boolean(GetConfig("automatic_eject")) == true
if !@doing_eject
Builtins.y2milestone("Automatically ejecting the medium...")
@doing_eject = true
return "E"
end
end
if Builtins.issubstring(error, "ERROR(InstSrc:E_bad_id)")
error =
# error report
_(
"<p>The repository at the specified URL now provides a different media ID.\n" \
"If the URL is correct, this indicates that the repository content has changed. To \n" \
"continue using this repository, start <b>Installation Repositories</b> from \n" \
"the YaST control center and refresh the repository.</p>\n"
)
end
if wanted_label == ""
# use only product name for network repository
# there is no medium 1, 2, ...
if double_sided
# media is double sided, we want the user to insert the 'Side A' of the media
# the complete string will be "<product> <media> <number>, <side>"
# e.g. "'SuSE Linux 9.0' DVD 1, Side A"
side = _("Side A")
if Ops.bitwise_and(wanted, 1) == 0
# media is double sided, we want the user to insert the 'Side B' of the media
side = _("Side B")
end
wanted = Ops.shift_right(Ops.add(wanted, 1), 1)
wanted_label = if ["cd", "dvd"].include(url_scheme)
# label for a repository - %1 product name (e.g. "openSUSE 10.2"), %2 medium number (e.g. 2)
# %3 side (e.g. "Side A")
Builtins.sformat("%1 (Disc %2, %3)", product, wanted, side)
else
# label for a repository - %1 product name (e.g. "openSUSE 10.2"), %2 medium number (e.g. 2)
# %3 side (e.g. "Side A")
Builtins.sformat("%1 (Medium %2, %3)", product, wanted, side)
end
else
wanted_label = if ["cd", "dvd"].include(Builtins.tolower(url_scheme))
# label for a repository - %1 product name (e.g. openSUSE 10.2), %2 medium number (e.g. 2)
Builtins.sformat(_("%1 (Disc %2)"), product, wanted)
else
# label for a repository - %1 product name (e.g. openSUSE 10.2), %2 medium number (e.g. 2)
Builtins.sformat(_("%1 (Medium %2)"), product, wanted)
end
end
end
# prompt to insert product (%1 == "SuSE Linux version 9.2 CD 2")
message = Builtins.sformat(_("Insert\n'%1'"), wanted_label)
# with network repository it doesn't make sense to ask for disk
if url_scheme == "dir"
# report error while accessing local directory with product (%1 = URL, %2 = "SuSE Linux ...")
message = Builtins.sformat(
_(
"Cannot access installation media\n" \
"%1\n" \
"%2.\n" \
"Check whether the directory is accessible."
),
URL.HidePassword(url),
wanted_label
)
elsif url_scheme != "cd" && url_scheme != "dvd"
# report error while accessing network media of product (%1 = URL, %2 = "SuSE Linux ...")
message = Builtins.sformat(
_(
"Cannot access installation media \n" \
"%1\n" \
"%2.\n" \
"Check whether the server is accessible."
),
URL.HidePassword(url),
wanted_label
)
end
# --------------------------------------
# build up button box
button_box = ButtonBox(
PushButton(Id(:retry), Opt(:default, :okButton), Label.RetryButton)
)
if current == -1 # wrong media id, offer "Ignore"
button_box = Builtins.add(
button_box,
PushButton(Id(:ignore), Opt(:customButton), Label.IgnoreButton)
)
end
button_box = Builtins.add(
button_box,
PushButton(
Id(:cancel),
Opt(:cancelButton),
@autorefreshing ? _("Skip Autorefresh") : Label.AbortButton
)
)
# push button label during media change popup, user can skip
# this media (CD) so no packages from this media will be installed
button_box = Builtins.add(
button_box,
PushButton(Id(:skip), Opt(:customButton), _("&Skip"))
)
if offer_eject_button
if !@doing_eject
@detected_cd_devices = CDdevices(Ops.get(devices, current_device, ""))
end
# detect the CD/DVD devices if the ejecting is not in progress,
# the CD detection closes the ejected tray!
cds = deep_copy(@detected_cd_devices)
# display a menu button if there are more CD devices
if Ops.greater_than(Builtins.size(cds), 1)
# menu button label - used for more then one device
button_box = HBox(button_box, MenuButton(_("&Eject"), cds))
else
# push button label - in the media change popup, user can eject the CD/DVD
button_box = Builtins.add(
button_box,
PushButton(Id(:eject), Opt(:customButton), _("&Eject"))
)
end
auto_eject = Convert.to_boolean(GetConfig("automatic_eject"))
auto_eject = false if auto_eject.nil?
button_box = VBox(
Left(
CheckBox(
Id(:auto_eject),
_("A&utomatically Eject CD or DVD Medium"),
auto_eject
)
),
button_box
)
end
@doing_eject = false
# Autoretry code
doing_auto_retry = false
if error_code == "IO_SOFT" ||
Builtins.contains(
["ftp", "sftp", "http", "https", "nfs", "smb"],
url_scheme
)
# this a different file, reset the retry counter
if @retry_url != url
@retry_url = url
@current_retry_attempt = 0
end
# is the maximum retry count reached?
if Ops.less_than(@current_retry_attempt, @retry_attempts)
# reset the counter, use logarithmic back-off with maximum limit
@current_retry_timeout = if @current_retry_attempt < 10
@retry_timeout * (1 << @current_retry_attempt)
else
@retry_max_timeout
end
if Ops.greater_than(@current_retry_timeout, @retry_max_timeout)
@current_retry_timeout = @retry_max_timeout
end
button_box = VBox(
# failed download will be automatically retried after the timeout, %1 = formatted time (MM:SS format)
Left(Label(Id(:auto_retry), RetryLabel(@current_retry_timeout))),
button_box
)
doing_auto_retry = true
else
Builtins.y2warning(
"Max. autoretry count (%1) reached, giving up...",
@retry_attempts
)
end
end
Builtins.y2milestone("Autoretry: %1", doing_auto_retry)
if doing_auto_retry
Builtins.y2milestone("Autoretry attempt: %1", @current_retry_attempt)
end
if Mode.commandline
CommandLine.Print(message)
CommandLine.Print(error)
# ask user in the interactive mode
if CommandLine.Interactive
CommandLine.Print("")
# command line mode - ask user whether installation of the failed package should be retried
CommandLine.Print(_("Retry the installation?"))
if CommandLine.YesNo
# return Retry
return ""
end
# command line mode - ask user whether the installation should be aborted
CommandLine.Print(_("Skip the medium?"))
if CommandLine.YesNo
# return Skip
return "S"
end
# otherwise ignore the medium
CommandLine.Print(_("Ignoring the bad medium..."))
return "I"
end
return "S"
end
Builtins.y2debug(
"Opening Dialog: %1",
LayoutPopup(message, button_box, 10, true)