/
add-on-workflow.rb
1929 lines (1664 loc) · 58.5 KB
/
add-on-workflow.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
# File:
# include/add-on/add-on-workflow.ycp
#
# Module:
# System installation
#
# Summary:
# Add-on product installation workflow
#
# Authors:
# Jiri Srain <jsrain@suse.cz>
# Lukas Ocilka <locilka@suse.cz>
#
#
require "y2packager/medium_type"
require "y2packager/resolvable"
module Yast
module AddOnAddOnWorkflowInclude
include Yast::Logger
def initialize_add_on_add_on_workflow(include_target)
Yast.import "UI"
Yast.import "Pkg"
textdomain "add-on"
Yast.import "AddOnProduct"
Yast.import "WorkflowManager"
Yast.import "Linuxrc"
Yast.import "InstURL"
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Report"
Yast.import "Sequencer"
Yast.import "SourceDialogs"
Yast.import "SourceManager"
Yast.import "PackageSystem"
Yast.import "ProductProfile"
Yast.import "SuSEFirewall"
Yast.import "Stage"
Yast.import "Wizard"
Yast.import "Confirm"
Yast.import "GetInstArgs"
Yast.import "Installation"
Yast.import "PackageCallbacks"
Yast.import "PackagesUI"
Yast.import "Packages"
Yast.include include_target, "packager/inst_source_dialogs.rb"
Yast.include include_target, "packager/repositories_include.rb"
Yast.include include_target, "add-on/misc.rb"
# Used for adding sources
@createResult = :again
@new_addon_name = ""
@product_infos = {}
# track the added repositories, using AddOnProduct.src_id does not work
# for multiple repository medium
# Arry<Fixnum>
@added_repos = []
end
# Initialize current inst. sources
def Read
Pkg.SourceStartManager(true)
:next
end
# Write (changed) inst. sources
def Write
Pkg.SourceSaveAll
:next
end
# used Add-Ons are stored in AddOnProduct::add_on_products
# bnc #393620
def AddAddOnToStore(src_id)
if src_id.nil?
log.error("Wrong src_id: #{src_id}")
return
end
# BNC #450274
# Prevent from adding one product twice
matching_product = AddOnProduct.add_on_products.find do |product|
product["media"] == src_id
end
if matching_product
log.info("Product already added: #{matching_product}")
return
end
source_data = Pkg.SourceGeneralData(src_id)
AddOnProduct.add_on_products <<
{
"media" => src_id,
# table cell
"product" => source_data["name"],
"media_url" => source_data["url"],
"product_dir" => source_data["product_dir"]
}
end
# Run dialog for selecting the media
# @return [Symbol] for wizard sequencer
def MediaSelect
aliases = {
"type" => lambda { media_type_selection },
"edit" => lambda { EditDialog() },
"store" => lambda do
StoreSource()
end
}
sources_before = Pkg.SourceGetCurrent(false)
Builtins.y2milestone("Sources before adding new one: %1", sources_before)
sequence = {
"ws_start" => "type",
"type" => {
:next => "edit",
# bnc #392083
:finish => "store",
:abort => :abort,
:skip => :skip
},
"edit" => {
:next => "store",
# bnc #392083
:finish => "store",
:abort => :abort
},
"store" => {
:next => :next,
# bnc #392083
:finish => :next,
:abort => :abort
}
}
Builtins.y2milestone("Starting repository sequence")
ret = Sequencer.Run(aliases, sequence)
log.info "Repository sequence result: #{ret}"
# activate the changes
activate_addon_changes(sources_before) if ret == :next
AddOnProduct.last_ret = ret
Builtins.y2milestone("MediaSelect Dialog ret: %1", ret)
ret
end
# bugzilla #304659
# Sets the Add-On's product name
#
# @param [Fixnum] src_id (source ID)
def SetAddOnProductName(src_id)
@new_addon_name = ""
if src_id == nil
Builtins.y2error("Cannot set name, no ID!")
return
end
@new_addon_name = SourceDialogs.GetRepoName
# no name to change to
if @new_addon_name == nil || @new_addon_name == ""
Builtins.y2milestone("No special name set")
return
end
new_addon_set = [{ "SrcId" => src_id, "name" => @new_addon_name }]
result = Pkg.SourceEditSet(new_addon_set)
Builtins.y2milestone(
"Adjusting Add-On: %1 returned: %2",
new_addon_set,
result
)
# do not use it next time
SourceDialogs.SetRepoName("")
nil
end
# Run dialog for selecting the catalog on the media (if more than one present)
# @return [Symbol] for wizard sequencer
def CatalogSelect
sources = deep_copy(SourceManager.newSources)
Builtins.y2milestone("New sources: %1", sources)
if Builtins.size(sources) == 0
# error report
Report.Error(_("No software repository found on medium."))
Builtins.y2milestone("CatalogSelect Dialog ret: %1", :back)
return :back
end
if Builtins.size(sources) == 1
if AddOnProduct.last_ret != :next
Builtins.y2milestone("Deleting source %1", Ops.get(sources, 0, 0))
Pkg.SourceDelete(Ops.get(sources, 0, 0))
Builtins.y2milestone(
"CatalogSelect Dialog ret: %1",
AddOnProduct.last_ret
)
return AddOnProduct.last_ret
end
# busy message
UI.OpenDialog(
Label(Id(:add_on_popup_id), _("Initializing new source..."))
)
src_id = Ops.get(SourceManager.newSources, 0, 0)
# BNC #481828: Using LABEL from content file as a repository name
Packages.AdjustSourcePropertiesAccordingToProduct(src_id)
# a little hack because of packager leaving
# windows open...
if UI.WidgetExists(:add_on_popup_id)
UI.CloseDialog
elsif UI.WidgetExists(:contents)
Builtins.y2warning("Already in base dialog!")
else
Builtins.y2error("Error in packager, closing current dialog!")
while !UI.WidgetExists(:contents)
Builtins.y2milestone("Calling UI::CloseDialog")
UI.CloseDialog
end
end
AddOnProduct.src_id = src_id
SourceManager.newSources = [src_id]
Builtins.y2milestone("Only one source available - skipping dialog")
Builtins.y2milestone(
"CatalogSelect Dialog ret: %1",
AddOnProduct.last_ret
)
return AddOnProduct.last_ret
end
Builtins.y2milestone("Running catalog select dialog")
catalogs = Builtins.maplist(sources) do |src|
data = Pkg.SourceGeneralData(src)
# placeholder for unknown directory
dir = Ops.get_locale(data, "product_dir", _("Unknown"))
dir = "/" if dir == ""
Item(
Id(src),
Builtins.sformat(
_("URL: %1, Directory: %2"),
Ops.get_locale(
# place holder for unknown URL
data,
"url",
_("Unknown")
),
dir
)
)
end
# dialog caption
title = _("Software Repository Selection")
# help text
help_text = _(
"<p><big><b>Software Repository Selection</b></big><br>\n" +
"Multiple repositories were found on the selected medium.\n" +
"Select the repository to use.</p>\n"
)
contents = HBox(
HSpacing(4),
VBox(
VSpacing(2),
SelectionBox(Id(:catalogs), _("Repositories &Found"), catalogs),
VSpacing(2)
),
HSpacing(4)
)
Wizard.SetContents(title, contents, help_text, true, true)
ret = nil
selected = nil
while ret == nil
ret = Convert.to_symbol(UI.UserInput)
if ret == :abort || ret == :cancel
ret = :abort
break if Popup.YesNo(_("Really abort add-on product installation?"))
next
elsif ret == :back
break
elsif ret == :next
selected = Convert.to_integer(
UI.QueryWidget(Id(:catalogs), :CurrentItem)
)
if selected == nil
ret = nil
# popup message
Popup.Message(_("Select a repository."))
end
end
end
if ret != :next
Builtins.foreach(SourceManager.newSources) do |src|
Builtins.y2milestone("Deleting source %1", src)
Pkg.SourceDelete(src)
end
else
Builtins.foreach(SourceManager.newSources) do |src|
if src != selected
Builtins.y2milestone("Deleting unused source %1", src)
Pkg.SourceDelete(src)
end
end
# BNC #481828: Using LABEL from content file as a repository name
Packages.AdjustSourcePropertiesAccordingToProduct(selected)
AddOnProduct.src_id = selected
SourceManager.newSources = [selected]
end
AddOnProduct.last_ret = ret
Builtins.y2milestone(
"CatalogSelect Dialog ret: %1",
AddOnProduct.last_ret
)
ret
end
# BNC #474745
# Installs all the products from just added add-on media
# @return [Symbol] always returns the :next symbol
def InstallProduct
log.info("Installing products from #{@added_repos.inspect}")
if @added_repos.empty?
log.error("No source has been added")
return :next
end
all_products = Y2Packager::Resolvable.find(kind: :product)
all_products.each do |product|
# Product doesn't match the new source ID
next unless @added_repos.include?(product.source)
# Product is not available (either `installed or `selected or ...)
if product.status != :available
log.info("Skipping product #{product.name} with status " \
"#{product.status}")
next
end
success = Pkg.ResolvableInstall(product.name, :product)
log.info("Selecting product '#{product.name}' for installation -> #{success}")
end
:next
end
def ProductSelect
# Do not use Y2Packager::Resolvable.find(kind: :product) because the
# returned Resolvables have not the variable "media".
# It is not so important because this function will be called in an
# installed system with the command "/sbin/yast2 add-on URL" only
all_products = Pkg.ResolvableProperties("", :product, "")
already_used_urls = {}
# getting all source urls and product_dirs
Builtins.foreach(all_products) do |p|
one_src_id = Builtins.tointeger(Ops.get(p, "source"))
next if one_src_id == nil
# the last source (just added)
next if one_src_id == AddOnProduct.src_id
src_general_data = Pkg.SourceGeneralData(one_src_id)
source_url = Ops.get_string(src_general_data, "url", "")
if source_url != "" && source_url != nil
Ops.set(
already_used_urls,
source_url,
Ops.get_string(src_general_data, "product_dir", "")
)
end
end
Builtins.y2milestone(
"Already used urls with product_dirs: %1",
already_used_urls
)
installed_products = Builtins.filter(all_products) do |p|
Ops.get(p, "status") == :selected || Ops.get(p, "status") == :installed
end
Builtins.y2milestone(
"Already installed/selected products: %1",
installed_products
)
products = Builtins.filter(all_products) do |p|
Ops.get_integer(p, "source", -1) == AddOnProduct.src_id
end
Builtins.y2milestone("Products on the media: %1", products)
# there are no product on the given url
if Builtins.size(products) == 0
Builtins.y2milestone(
"No poduct found on the media, but anyway, using it :-)"
)
# Display /media.1/info.txt if such file exists
# Display license and wait for agreement
# FIXME the same code is below
license_ret2 = AddOnProduct.AcceptedLicenseAndInfoFile(
AddOnProduct.src_id
)
if license_ret2 != true
Builtins.y2milestone(
"Removing the current source ID %1",
AddOnProduct.src_id
)
Pkg.SourceDelete(AddOnProduct.src_id)
Builtins.y2milestone("ProductSelect Dialog ret: %1", :abort)
return :abort
end
data = Pkg.SourceGeneralData(AddOnProduct.src_id)
url = Ops.get_string(data, "url", "")
product_dir = Ops.get_string(data, "product_dir", "")
# bugzilla #304659
SetAddOnProductName(AddOnProduct.src_id)
AddOnProduct.add_on_products = Builtins.add(
AddOnProduct.add_on_products,
{
"media" => AddOnProduct.src_id,
# table cell
"product" => @new_addon_name != "" &&
@new_addon_name != nil ?
@new_addon_name :
_("No product found in the repository."),
"media_url" => url,
"product_dir" => product_dir
}
)
if Mode.config
AddOnProduct.mode_config_sources = Builtins.add(
AddOnProduct.mode_config_sources,
AddOnProduct.src_id
)
end
Builtins.y2milestone("ProductSelect Dialog ret: %1", :next)
return :next
end
# Display /media.1/info.txt if such file exists
# Display license and wait for agreement
# FIXME the same code is above
license_ret = AddOnProduct.AcceptedLicenseAndInfoFile(AddOnProduct.src_id)
if license_ret != true
Builtins.y2milestone(
"Removing the current source ID %1",
AddOnProduct.src_id
)
Pkg.SourceDelete(AddOnProduct.src_id)
Builtins.y2milestone("ProductSelect Dialog ret: %1", :abort)
return :abort
end
# there is only one product on the given url
if Builtins.size(products) == 1
# bugzilla #227605
# this product with this url has been already installed or selected for installation
src_general_data = Pkg.SourceGeneralData(AddOnProduct.src_id)
current_url = Ops.get_string(src_general_data, "url", "")
Builtins.y2milestone("Only one product available - skipping dialog")
prod = Ops.get(products, 0, {})
if !AddOnProduct.CheckProductDependencies(
[Ops.get_string(prod, "name", "")]
)
Pkg.ResolvableRemove(Ops.get_string(prod, "name", ""), :product)
# message popup
Popup.Message(
_("Dependencies of the add-on product cannot be fulfilled.")
)
AddOnProduct.last_ret = :back
Builtins.y2milestone("ProductSelect Dialog ret: %1", :back)
return :back
end
# check whether the product is already available on some media - it is similar as below
found_source = -1
Builtins.foreach(all_products) do |p|
if Ops.get_string(p, "name", "") == Ops.get_string(prod, "name", "") &&
Ops.get_string(p, "version", "") ==
Ops.get_string(prod, "version", "") &&
Ops.get_integer(p, "media", -2) !=
Ops.get_integer(prod, "media", -3)
Builtins.y2milestone(
"Product %1 already available on media %2",
p,
Ops.get_integer(p, "media", -1)
)
found_source = Ops.get_integer(p, "media", -1)
raise Break
end
end
if found_source != -1
Builtins.y2milestone("Deleting source %1", AddOnProduct.src_id)
Pkg.SourceDelete(AddOnProduct.src_id)
AddOnProduct.src_id = found_source
end
Pkg.ResolvableInstall(Ops.get_string(prod, "name", ""), :product)
data = Pkg.SourceGeneralData(AddOnProduct.src_id)
url = Ops.get_string(data, "url", "")
product_dir = Ops.get_string(data, "product_dir", "")
# bugzilla #304659
SetAddOnProductName(AddOnProduct.src_id)
AddOnProduct.add_on_products = Builtins.add(
AddOnProduct.add_on_products,
{
"media" => AddOnProduct.src_id,
"product" => @new_addon_name != "" &&
@new_addon_name != nil ?
@new_addon_name :
Ops.get_string(
prod,
"display_name",
Ops.get_string(
prod,
"short_name",
Ops.get_string(prod, "name", "")
)
),
"autoyast_product" => Ops.get_string(prod, "name", ""),
"media_url" => url,
"product_dir" => product_dir
}
)
if found_source == -1 && Mode.config
AddOnProduct.mode_config_sources = Builtins.add(
AddOnProduct.mode_config_sources,
AddOnProduct.src_id
)
end
Builtins.y2milestone("ProductSelect Dialog ret: %1", :next)
return :next
end
# there are more than one products on the given url
Builtins.y2milestone("Running product selection dialog")
ret = nil
items = Builtins.maplist(products) do |product|
Item(
Id(Ops.get_string(product, "name", "")),
Ops.get_string(product, "name", "")
)
end
# dialog caption
title = _("Product Selection")
contents = HBox(
HStretch(),
VBox(
VStretch(),
# multi selection list
MultiSelectionBox(Id(:products), _("Available Products"), items),
VStretch()
),
HStretch()
)
# help text
help_text = _(
"<p><b><big>Product Selection</big></b><br/>\n" +
"Multiple products were found in the repository. Select the products\n" +
"to install.</p>\n"
)
Wizard.SetContents(title, contents, help_text, true, true)
while ret == nil
ret = Convert.to_symbol(UI.UserInput)
if ret == :cancel || ret == :abort
ret = :abort
# if (Stage::initial())
# {
# if (Popup::ConfirmAbort (`painless))
# break;
# }
# else
# {
# yes-no popup
break if Popup.YesNo(_("Really abort add-on product installation?"))
# }
next
end
if ret == :next
selected = Convert.convert(
UI.QueryWidget(Id(:products), :SelectedItems),
:from => "any",
:to => "list <string>"
)
# check whether the product is already available on some media - it is similar as above
prods = Builtins.filter(products) do |p|
Builtins.contains(selected, Ops.get_string(p, "name", ""))
end
all_found = true
prod2src = {}
Builtins.foreach(prods) do |prod|
product_found = false
Builtins.foreach(all_products) do |p|
if Ops.get_string(p, "name", "") ==
Ops.get_string(prod, "name", "") &&
Ops.get_string(p, "version", "") ==
Ops.get_string(prod, "version", "") &&
Ops.get_integer(p, "media", -2) !=
Ops.get_integer(prod, "media", -3)
product_found = true
Ops.set(
prod2src,
Ops.get_string(prod, "name", ""),
Ops.get_integer(p, "media", -3)
)
raise Break
end
end
all_found = all_found && product_found
end
if all_found
Builtins.y2milestone("Deleting source %1", AddOnProduct.src_id)
Pkg.SourceDelete(AddOnProduct.src_id)
AddOnProduct.src_id = -1
end
Builtins.foreach(selected) do |product|
Pkg.ResolvableInstall(product, :product)
end
if !AddOnProduct.CheckProductDependencies(selected)
Builtins.foreach(selected) do |product|
Pkg.ResolvableRemove(product, :product)
end
# message popup
Popup.Message(
_(
"Dependencies of the selected add-on products cannot be fulfilled."
)
)
ret = nil
next
end
data = Pkg.SourceGeneralData(AddOnProduct.src_id)
url = Ops.get_string(data, "url", "")
product_dir = Ops.get_string(data, "product_dir", "")
Builtins.foreach(selected) do |product|
src_id = AddOnProduct.src_id == -1 ?
Ops.get(prod2src, product, -1) :
AddOnProduct.src_id
# bugzilla #304659
SetAddOnProductName(AddOnProduct.src_id)
AddOnProduct.add_on_products = Builtins.add(
AddOnProduct.add_on_products,
{
"media" => src_id,
"product" => @new_addon_name != "" &&
@new_addon_name != nil ? @new_addon_name : product,
"autoyast_prouduct" => product,
"media_url" => url,
"product_dir" => product_dir
}
)
end
if AddOnProduct.src_id != -1 && Mode.config
AddOnProduct.mode_config_sources = Builtins.add(
AddOnProduct.mode_config_sources,
AddOnProduct.src_id
)
end
elsif ret != :back
ret = nil
end
end
if ret == :abort
Builtins.y2milestone("Deleting source %1", AddOnProduct.src_id)
Pkg.SourceDelete(AddOnProduct.src_id)
end
AddOnProduct.last_ret = ret
Builtins.y2milestone(
"ProductSelect Dialog ret: %1",
AddOnProduct.last_ret
)
ret
end
# Check new product compliance; may abort the installation
def CheckCompliance
compliant = @added_repos.all?{ |src_id| ProductProfile.CheckCompliance(src_id) }
compliant ? :next : :abort
end
def RunWizard
aliases = {
"media" => lambda { MediaSelect() },
"install_product" => lambda { InstallProduct() },
"check_compliance" => lambda { CheckCompliance() }
}
sequence = {
"ws_start" => "media",
"media" => {
:abort => :abort,
:next => "check_compliance",
:finish => "check_compliance",
:skip => :skip
},
"check_compliance" => {
:abort => :abort,
:next => "install_product"
},
"install_product" => {
:abort => :abort,
:next => :next,
:finish => :next
}
}
Sequencer.Run(aliases, sequence)
end
def RunAutorunWizard
aliases = {
"catalog" => lambda { CatalogSelect() },
"product" => lambda { ProductSelect() }
}
sequence = {
"ws_start" => "catalog",
"catalog" => { :abort => :abort, :next => "product", :finish => :next },
"product" => { :abort => :abort, :next => :next, :finish => :next }
}
Sequencer.Run(aliases, sequence)
end
def Redraw(enable_back, enable_next, enable_abort, back_button, next_button, abort_button)
Builtins.y2milestone("Called Redraw()")
# main screen heading
title = _("Add-On Product Installation")
# Help for add-on products
help = _(
"<p><big><b>Add-On Product Installation</b></big><br/>\n" +
"Here see all add-on products that are selected for installation.\n" +
"To add a new product, click <b>Add</b>. To remove an already added one,\n" +
"select it and click <b>Delete</b>.</p>"
)
Builtins.y2milestone("Current products: %1", AddOnProduct.add_on_products)
index = -1
items = Builtins.maplist(AddOnProduct.add_on_products) do |product|
Builtins.y2milestone("%1", product)
index = Ops.add(index, 1)
data = {}
# BNC #464162, In AytoYaST, there is no media nr. yet
if Builtins.haskey(product, "media") &&
Ops.greater_than(Ops.get_integer(product, "media", -1), -1)
data = Pkg.SourceGeneralData(Ops.get_integer(product, "media", -1))
else
data = deep_copy(product)
if Builtins.haskey(data, "media_url")
Ops.set(data, "url", Ops.get_string(data, "media_url", ""))
end
end
# placeholder for unknown path
dir = Ops.get_locale(data, "product_dir", _("Unknown"))
dir = "/" if dir == ""
# table cell, %1 is URL, %2 is directory name
media = Builtins.sformat(
_("%1, Directory: %2"),
Ops.get_locale(
# placeholder for unknown URL
data,
"url",
_("Unknown")
),
dir
)
Item(
Id(index),
product_label(product["product"]),
media
)
end
contents = VBox(
Table(
Id(:summary),
Header(
# table header
_("Product"),
# table header
_("Media")
),
items
),
Left(
HBox(
PushButton(Id(:add), Label.AddButton),
PushButton(Id(:delete), Label.DeleteButton),
HStretch()
)
)
)
Wizard.SetContentsButtons(title, contents, help, back_button, next_button)
Wizard.SetAbortButton(:abort, abort_button)
# Disable next button according to settings
Wizard.DisableNextButton if !enable_next
# If back or abort buttons should not be enabled, hide them
# -> [Cancel] [OK] dialog
Wizard.HideBackButton if !enable_back
Wizard.HideAbortButton if !enable_abort
Wizard.SetDesktopIcon("org.opensuse.yast.AddOn")
# disable delete button if no items listed
# bug #203809
UI.ChangeWidget(Id(:delete), :Enabled, false) if Builtins.size(items) == 0
nil
end
def RemoveSelectedAddOn(selected)
Builtins.y2milestone(
"Deleting %1 %2",
selected,
Ops.get(AddOnProduct.add_on_products, selected)
)
# remove whole media if the product is the only one on the media
media = Ops.get_integer(
AddOnProduct.add_on_products,
[selected, "media"],
-1
)
med_count = Builtins.size(Builtins.filter(AddOnProduct.add_on_products) do |prod|
Ops.get_integer(prod, "media", -1) == media
end)
if med_count == 1
Builtins.y2milestone("Deleting source %1", media)
Pkg.SourceDelete(media)
end
# Deselect product from libzypp
Pkg.ResolvableNeutral(AddOnProduct.add_on_products[selected]["product"], :product, false)
# remove the selected record
Ops.set(AddOnProduct.add_on_products, selected, nil)
AddOnProduct.add_on_products = Builtins.filter(
AddOnProduct.add_on_products
) { |prod| prod != nil }
# Remove product from add-ons
AddOnProduct.Disintegrate(media)
# remove product from list of product to register (FATE #301312)
AddOnProduct.RemoveRegistrationFlag(media)
nil
end
# bugzilla #221377
# the original control file is stored as /control.xml
# the other (added) control files are under the
# /tmp/$yast_tmp/control_files/ directory
# as $srcid.xml files
#
# bugzilla #237297
# in the installation workflow - back/ next buttons
# in the installation proposal - cancel / accept buttons
#
# bugzilla #449773
# added enable_abort, abort_button
#
def RunAddOnMainDialog(enable_back, enable_next, enable_abort, back_button, next_button, abort_button, confirm_abort)
ret = nil
not_enough_memory = Stage.initial && HasInsufficientMemory()
no_addons = Builtins.size(AddOnProduct.add_on_products) == 0
# bugzilla #239630
# It might be dangerous to add more installation sources in installation
# on machine with less memory
# Do not report when some add-ons are already in use
if not_enough_memory && !no_addons
if !ContinueIfInsufficientMemory()
# next time, it will be skipped too
Installation.add_on_selected = false
Installation.productsources_selected = false
return :next
end
end
# FATE #301928 - Saving one click
# Bugzilla #893103 be consistent, so always when there is no add-on skip
# Bugzilla #1102705 Do not redraw when skipping
if no_addons
Builtins.y2milestone("Skipping to media_select")
ret = :skip_to_add
else
# Show Add-Ons table
Redraw(
enable_back,
enable_next,
enable_abort,
back_button,
next_button,
abort_button
)
end
# store the initial settings, only once
WorkflowManager.SetBaseWorkflow(false)
# added / removed
some_addon_changed = false
begin
# FATE #301928 - Saving one click
ret = Convert.to_symbol(UI.UserInput) unless ret == :skip_to_add
# aborting
if ret == :abort || ret == :cancel
# User should confirm that
if confirm_abort == true
if Popup.ConfirmAbort(:incomplete)
ret = :abort
break
else
ret = nil
end
# Running system
else
break
end
# removing add-on
elsif ret == :delete
selected = Convert.to_integer(
UI.QueryWidget(Id(:summary), :CurrentItem)
)
if selected == nil
# message report
Report.Message(_("Select a product to delete."))
next
end
# bugzilla #305802
next if !Confirm.DeleteSelected
# TRANSLATORS: busy message
UI.OpenDialog(Label(_("Removing selected add-on...")))
RemoveSelectedAddOn(selected)
some_addon_changed = true
UI.CloseDialog
Redraw(
enable_back,
enable_next,
enable_abort,
back_button,
next_button,
abort_button