-
Notifications
You must be signed in to change notification settings - Fork 43
/
ProductControl.rb
1669 lines (1435 loc) · 52.5 KB
/
ProductControl.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
#
# ***************************************************************************
# File: modules/ProductControl.rb
# Package: installation
# Summary: Product Control routines
# Authors: Anas Nashif <nashif@suse.de>
# Stanislav Visnovsky <visnov@suse.cz>
# Jiri Srain <jsrain@suse.cz>
# Lukas Ocilka <locilka@suse.cz>
#
require "yast"
module Yast
class ProductControlClass < Module
def main
Yast.import "UI"
textdomain "base"
Yast.import "XML"
Yast.import "ProductFeatures"
Yast.import "Mode"
Yast.import "Arch"
Yast.import "Stage"
Yast.import "Directory"
Yast.import "Label"
Yast.import "Wizard"
Yast.import "Report"
Yast.import "DebugHooks"
Yast.import "Popup"
Yast.import "FileUtils"
Yast.import "Installation"
Yast.import "Hooks"
# The complete parsed control file
@productControl = {}
# all workflows
@workflows = []
# all proposals
@proposals = []
# inst_finish steps
@inst_finish = []
# modules to be offered to clone configuration at the end of installation
@clone_modules = []
# additional workflow parameters
# workflow doesn't only match mode and stage but also these params
# bnc #427002
@_additional_workflow_params = {}
# Location of a custom control file
@custom_control_file = ""
# Control file in service packs
@y2update_control_file = "/y2update/control.xml"
# The custom control file location, usually copied from
# the root of the CD to the installation directory by linuxrc
@installation_control_file = "/control.xml"
# The file above get saved into the installed system for later
# processing
@saved_control_file = Ops.add(Directory.etcdir, "/control.xml")
# The control file we are using for this session.
@current_control_file = nil
# Current Wizard Step
@CurrentWizardStep = ""
# Last recently used stage_mode for RetranslateWizardSteps
@last_stage_mode = []
# List of module to disable in the current run
@DisabledModules = []
# List of proposals to disable in the current run
@DisabledProposals = []
@DisabledSubProposals = {}
# Log files for hooks
@logfiles = []
@first_step = nil
@restarting_step = nil
@_client_prefix = "inst_"
@stack = []
@first_id = ""
@current_step = 0
@localDisabledProposals = []
@localDisabledModules = []
@already_disabled_workflows = []
# Forces UpdateWizardSteps to redraw steps even if nothing seem to be changed
@force_UpdateWizardSteps = false
@lastDisabledModules = deep_copy(@DisabledModules)
ProductControl()
end
def CurrentStep
@current_step
end
# Set Client Prefix
def setClientPrefix(prefix)
@_client_prefix = prefix
nil
end
# Enable given disabled module
# @return current list of disabled modules
def EnableModule(modname)
@DisabledModules = Builtins.filter(@DisabledModules) do |mod|
mod != modname
end
deep_copy(@DisabledModules)
end
# Disable given module in installation workflow
# @return current list of disabled modules
def DisableModule(modname)
if modname.nil? || modname == ""
Builtins.y2error("Module to disable is '%1'", modname)
else
@DisabledModules = Convert.convert(
Builtins.union(@DisabledModules, [modname]),
from: "list",
to: "list <string>"
)
end
deep_copy(@DisabledModules)
end
# Returns list of modules disabled in workflow
#
# @return [Array<String>] DisabledModules
def GetDisabledModules
deep_copy(@DisabledModules)
end
# Enable given disabled proposal
# @return current list of disabled proposals
def EnableProposal(enable_proposal)
@DisabledProposals = Builtins.filter(@DisabledProposals) do |one_proposal|
one_proposal != enable_proposal
end
deep_copy(@DisabledProposals)
end
# Disable given proposal in installation workflow
# @return current list of disabled proposals
def DisableProposal(disable_proposal)
if disable_proposal.nil? || disable_proposal == ""
Builtins.y2error("Module to disable is '%1'", disable_proposal)
else
@DisabledProposals = Convert.convert(
Builtins.union(@DisabledProposals, [disable_proposal]),
from: "list",
to: "list <string>"
)
end
deep_copy(@DisabledProposals)
end
# Returns list of proposals disabled in workflow
#
# @return [Array<String>] DisabledProposals
def GetDisabledProposals
deep_copy(@DisabledProposals)
end
def EnableSubProposal(unique_id, enable_subproposal)
if Builtins.haskey(@DisabledSubProposals, unique_id)
Ops.set(
@DisabledSubProposals,
unique_id,
Builtins.filter(Ops.get(@DisabledSubProposals, unique_id, [])) do |one_subproposal|
one_subproposal != enable_subproposal
end
)
end
deep_copy(@DisabledSubProposals)
end
def DisableSubProposal(unique_id, disable_subproposal)
if Builtins.haskey(@DisabledSubProposals, unique_id)
Ops.set(
@DisabledSubProposals,
unique_id,
Convert.convert(
Builtins.union(
Ops.get(@DisabledSubProposals, unique_id, []),
[disable_subproposal]
),
from: "list",
to: "list <string>"
)
)
else
Ops.set(@DisabledSubProposals, unique_id, [disable_subproposal])
end
deep_copy(@DisabledSubProposals)
end
def GetDisabledSubProposals
deep_copy(@DisabledSubProposals)
end
# Check if a module is disabled
# @param map module map
# @return [Boolean]
def checkDisabled(mod)
mod = deep_copy(mod)
if mod.nil?
Builtins.y2error("Unknown module %1", mod)
return nil
end
# Proposal
if !Ops.get_string(mod, "proposal", "").nil? &&
Ops.get_string(mod, "proposal", "") != ""
if Builtins.contains(
@DisabledProposals,
Ops.get_string(mod, "proposal", "")
)
return true
end
# Normal step
elsif !Ops.get_string(mod, "name", "").nil? &&
Ops.get_string(mod, "name", "") != ""
if Builtins.contains(@DisabledModules, Ops.get_string(mod, "name", ""))
return true
end
end
false
end
def checkHeading(mod)
mod = deep_copy(mod)
Builtins.haskey(mod, "heading")
end
# Read XML Control File
# @param string control file
# @return [Boolean]
def ReadControlFile(controlfile)
@productControl = XML.XMLToYCPFile(controlfile)
return false if @productControl.nil?
@workflows = Ops.get_list(@productControl, "workflows", [])
@proposals = Ops.get_list(@productControl, "proposals", [])
@inst_finish = Ops.get_list(@productControl, "inst_finish_stages", [])
@clone_modules = Ops.get_list(@productControl, "clone_modules", [])
Builtins.foreach(
["software", "globals", "network", "partitioning", "texts"]
) do |section|
if Builtins.haskey(@productControl, section)
ProductFeatures.SetSection(
section,
Ops.get_map(@productControl, section, {})
)
end
end
# FIXME: would be nice if it could be done generic way
if Ops.greater_than(
Builtins.size(
Ops.get_list(@productControl, ["partitioning", "partitions"], [])
),
0
)
partitioning = Ops.get_map(@productControl, "partitioning", {})
ProductFeatures.SetBooleanFeature(
"partitioning",
"flexible_partitioning",
true
)
ProductFeatures.SetFeature(
"partitioning",
"FlexiblePartitioning",
partitioning
)
end
true
end
def Check(allowed, current)
# create allowed list
allowedlist = Builtins.filter(
Builtins.splitstring(Builtins.deletechars(allowed, " "), ",")
) { |s| s != "" }
Builtins.y2debug("allowedlist: %1", allowedlist)
Builtins.y2debug("current: %1", current)
if Builtins.size(allowedlist) == 0
return true
elsif Builtins.contains(allowedlist, current)
return true
else
return false
end
end
# Check if valid architecture
# @param map module data
# @param map default data
# @return [Boolean] true if arch match
def checkArch(mod, def_)
mod = deep_copy(mod)
def_ = deep_copy(def_)
Builtins.y2debug("Checking architecture: %1", mod)
archs = Ops.get_string(mod, "archs", "")
archs = Ops.get_string(def_, "archs", "all") if archs == ""
return true if archs == "all"
Builtins.y2milestone("short arch desc: %1", Arch.arch_short)
Builtins.y2milestone("supported archs: %1", archs)
return true if Builtins.issubstring(archs, Arch.arch_short)
false
end
# Returns name of the script to call. If 'execute' is defined,
# the client name is taken from there. Then, if a custom control
# file is defined, client name is defined as 'name'. Then, inst_'name'
# or just 'name' is returned if it does not match the 'inst_' regexp.
#
# @param [String] name
# @param [String] execute
# @see #custom_control_file
def getClientName(name, execute)
return "inst_test_workflow" if Mode.test
# BNC #401319
# 'execute; is defined and thus returned
if !execute.nil? && execute != ""
Builtins.y2milestone("Step name '%1' executes '%2'", name, execute)
return execute
end
# Defined custom control file
if @custom_control_file != ""
return name
# All standard clients start with "inst_"
else
if Builtins.issubstring(name, @_client_prefix)
return name
else
return Ops.add(@_client_prefix, name)
end
end
end
# Return term to be used to run module with CallFunction
# @param map module data
# @param map default data
# @return [Yast::Term] module data with params
def getClientTerm(step, def_, former_result)
step = deep_copy(step)
def_ = deep_copy(def_)
former_result = deep_copy(former_result)
client = getClientName(
Ops.get_string(step, "name", "dummy"),
Ops.get_string(step, "execute", "")
)
result = Builtins.toterm(client)
arguments = {}
Builtins.foreach(["enable_back", "enable_next"]) do |button|
default_setting = Ops.get_string(def_, button, "yes")
Ops.set(
arguments,
button,
Ops.get_string(step, button, default_setting) == "yes"
)
end
if Builtins.haskey(step, "proposal")
Ops.set(arguments, "proposal", Ops.get_string(step, "proposal", ""))
end
other_args = Ops.get_map(step, "arguments", {})
if Ops.greater_than(Builtins.size(other_args), 0)
arguments = Convert.convert(
Builtins.union(arguments, other_args),
from: "map",
to: "map <string, any>"
)
end
if Ops.is_symbol?(former_result) && former_result == :back
Ops.set(arguments, "going_back", true)
end
if Mode.test
Ops.set(arguments, "step_name", Ops.get_string(step, "name", ""))
Ops.set(arguments, "step_id", Ops.get_string(step, "id", ""))
end
result = Builtins.add(result, arguments)
deep_copy(result)
end
# Checks all params set by SetAdditionalWorkflowParams() whether they match the
# workfow got as parameter.
#
# @param [map &] check_workflow
# @see #SetAdditionalWorkflowParams()
def CheckAdditionalParams(check_workflow)
if @_additional_workflow_params.nil? ||
@_additional_workflow_params == {}
return true
end
ret = true
Builtins.foreach(@_additional_workflow_params) do |key_to_check, value_to_check|
# exception
# If 'add_on_mode' key is not set in the workflow at all
# it is considered to be matching that parameter
if key_to_check == "add_on_mode" &&
!Builtins.haskey(check_workflow.value, key_to_check)
Builtins.y2debug(
"No 'add_on_mode' defined, matching %1",
value_to_check
)
elsif Ops.get(check_workflow.value, key_to_check) != value_to_check
ret = false
raise Break
end
end
ret
end
# Returns workflow matching the selected stage and mode and additiona parameters
# if set by SetAdditionalWorkflowParams()
#
# @param [String] stage
# @param [String] mode
# @return [Hash] workflow
def FindMatchingWorkflow(stage, mode)
Builtins.y2debug("workflows: %1", @workflows)
tmp = Builtins.filter(@workflows) do |wf|
Check(Ops.get_string(wf, "stage", ""), stage) &&
Check(Ops.get_string(wf, "mode", ""), mode) &&
(
wf_ref = arg_ref(wf)
CheckAdditionalParams(wf_ref)
)
end
Builtins.y2debug("Workflow: %1", Ops.get(tmp, 0, {}))
Ops.get(tmp, 0, {})
end
# Get workflow defaults
# @param [String] stage
# @param [String] mode
# @return [Hash] defaults
def getModeDefaults(stage, mode)
workflow = FindMatchingWorkflow(stage, mode)
Ops.get_map(workflow, "defaults", {})
end
# Prepare Workflow Scripts
# @param [Hash] m Workflow module map
# @return [void]
def PrepareScripts(m)
m = deep_copy(m)
tmp_dir = Convert.to_string(WFM.Read(path(".local.tmpdir"), []))
if Builtins.haskey(m, "prescript")
interpreter = Ops.get_string(m, ["prescript", "interpreter"], "shell")
source = Ops.get_string(m, ["prescript", "source"], "")
type = interpreter == "shell" ? "sh" : "pl"
f = Builtins.sformat(
"%1/%2_pre.%3",
tmp_dir,
Ops.get_string(m, "name", ""),
type
)
WFM.Write(path(".local.string"), f, source)
@logfiles = Builtins.add(
@logfiles,
Builtins.sformat(
"%1.log",
Builtins.sformat("%1_pre.%2", Ops.get_string(m, "name", ""), type)
)
)
end
if Builtins.haskey(m, "postscript")
interpreter = Ops.get_string(m, ["postscript", "interpreter"], "shell")
source = Ops.get_string(m, ["postscript", "source"], "")
type = interpreter == "shell" ? "sh" : "pl"
f = Builtins.sformat(
"%1/%2_post.%3",
tmp_dir,
Ops.get_string(m, "name", ""),
type
)
WFM.Write(path(".local.string"), f, source)
@logfiles = Builtins.add(
@logfiles,
Builtins.sformat(
"%1.log",
Builtins.sformat("%1_post.%2", Ops.get_string(m, "name", ""), type)
)
)
end
nil
end
# Get list of required files for the workflow.
# @return [Array<String>] Required files list.
# FIXME: this function seems to be unused, remove it?
def RequiredFiles(stage, mode)
# Files needed during installation.
needed_client_files = []
workflow = FindMatchingWorkflow(stage, mode)
modules = Ops.get_list(workflow, "modules", [])
modules = Builtins.filter(modules) do |m|
Ops.get_boolean(m, "enabled", true)
end
Builtins.foreach(modules) do |m|
client = ""
if Stage.firstboot
client = Ops.get_string(m, "name", "dummy")
else
if Builtins.issubstring(Ops.get_string(m, "name", "dummy"), "inst_")
client = Ops.get_string(m, "name", "dummy")
else
client = Ops.add("inst_", Ops.get_string(m, "name", "dummy"))
end
end
# FIXME: what about the ruby files?
client = Ops.add(
Ops.add(Ops.add(Directory.clientdir, "/"), client),
".ycp"
)
needed_client_files = Builtins.add(needed_client_files, client)
end
needed_client_files = Builtins.toset(needed_client_files)
deep_copy(needed_client_files)
end
# Get Workflow
# @param [String] stage Stage
# @param [String] mode Mode
# @return [Hash] Workflow map
def getCompleteWorkflow(stage, mode)
FindMatchingWorkflow(stage, mode)
end
# Get modules of current Workflow
# @param [String] stage
# @param [String] mode
# @param boolean all enabled and disabled or enabled only
# @return [Array<Hash>] modules
def getModules(stage, mode, which)
workflow = FindMatchingWorkflow(stage, mode)
modules = Ops.get_list(workflow, "modules", [])
Builtins.y2debug("M1: %1", modules)
# Unique IDs have to always keep the same because some steps
# can be disabled while YaST is running
# @see BNC #575092
id = 1
modules = Builtins.maplist(modules) do |m|
Ops.set(m, "id", Builtins.sformat("%1_%2", stage, id))
id = Ops.add(id, 1)
deep_copy(m)
end
modules = Builtins.filter(modules) do |m|
Ops.get_boolean(m, "enabled", true) && !checkDisabled(m)
end if which == :enabled
Builtins.y2debug("M2: %1", modules)
modules = Builtins.maplist(modules) do |m|
PrepareScripts(m)
deep_copy(m)
end
Builtins.y2debug("M3: %1", modules)
Builtins.y2debug("Log files: %1", @logfiles)
deep_copy(modules)
end
# Returns whether is is required to run YaST in the defined
# stage and mode
#
# @param [String] stage
# @param [String] mode
# @return [Boolean] if needed
def RunRequired(stage, mode)
modules = getModules(stage, mode, :enabled)
if modules.nil?
Builtins.y2error("Undefined %1/%2", stage, mode)
return nil
end
modules = Builtins.filter(modules) do |one_module|
# modules
if !Ops.get_string(one_module, "name").nil? &&
Ops.get_string(one_module, "name", "") != ""
next true
# proposals
elsif !Ops.get_string(one_module, "proposal").nil? &&
Ops.get_string(one_module, "proposal", "") != ""
next true
end
# the rest
false
end
# for debugging purposes
Builtins.y2milestone("Enabled: (%1) %2", Builtins.size(modules), modules)
Ops.greater_than(Builtins.size(modules), 0)
end
# Get Workflow Label
# @param [String] stage
# @param [String] mode
# @return [String]
def getWorkflowLabel(stage, mode, wz_td)
workflow = FindMatchingWorkflow(stage, mode)
label = Ops.get_string(workflow, "label", "")
return "" if label == ""
if Builtins.haskey(workflow, "textdomain")
return Builtins.dgettext(
Ops.get_string(workflow, "textdomain", ""),
label
)
else
return Builtins.dgettext(wz_td, label)
end
end
def DisableAllModulesAndProposals(mode, stage)
this_workflow = { "mode" => mode, "stage" => stage }
if Builtins.contains(@already_disabled_workflows, this_workflow)
Builtins.y2milestone("Workflow %1 already disabled", this_workflow)
return
end
# stores modules and proposals disabled before
# this 'general' disabling
@localDisabledProposals = deep_copy(@DisabledProposals)
@localDisabledModules = deep_copy(@DisabledModules)
Builtins.y2milestone(
"localDisabledProposals: %1",
@localDisabledProposals
)
Builtins.y2milestone("localDisabledModules: %1", @localDisabledModules)
Builtins.foreach(getModules(stage, mode, :all)) do |m|
if !Ops.get_string(m, "proposal").nil? &&
Ops.get_string(m, "proposal", "") != ""
Builtins.y2milestone("Disabling proposal: %1", m)
@DisabledProposals = Convert.convert(
Builtins.union(
@DisabledProposals,
[Ops.get_string(m, "proposal", "")]
),
from: "list",
to: "list <string>"
)
elsif !Ops.get_string(m, "name").nil? &&
Ops.get_string(m, "name", "") != ""
Builtins.y2milestone("Disabling module: %1", m)
@DisabledModules = Convert.convert(
Builtins.union(@DisabledModules, [Ops.get_string(m, "name", "")]),
from: "list",
to: "list <string>"
)
end
end
@already_disabled_workflows = Convert.convert(
Builtins.union(@already_disabled_workflows, [this_workflow]),
from: "list",
to: "list <map>"
)
nil
end
def UnDisableAllModulesAndProposals(mode, stage)
this_workflow = { "mode" => mode, "stage" => stage }
# Such mode/stage not disabled
if !Builtins.contains(@already_disabled_workflows, this_workflow)
Builtins.y2milestone(
"Not yet disabled, not un-disabling: %1",
this_workflow
)
return
end
Builtins.y2milestone("Un-Disabling workflow %1", this_workflow)
@already_disabled_workflows = Builtins.filter(@already_disabled_workflows) do |one_workflow|
one_workflow != this_workflow
end
# Note: This might be done by a simple reverting with 'X = localX'
# but some of these modules don't need to be in a defined mode and stage
Builtins.foreach(getModules(stage, mode, :all)) do |m|
# A proposal
# Enable it only if it was enabled before
if !Ops.get_string(m, "proposal").nil? &&
Ops.get_string(m, "proposal", "") != "" &&
!Builtins.contains(
@localDisabledProposals,
Ops.get_string(m, "proposal", "")
)
Builtins.y2milestone("Enabling proposal: %1", m)
@DisabledProposals = Builtins.filter(@DisabledProposals) do |one_proposal|
Ops.get_string(m, "proposal", "") != one_proposal
end
# A module
# Enable it only if it was enabled before
elsif !Ops.get_string(m, "name").nil? &&
Ops.get_string(m, "name", "") != "" &&
!Builtins.contains(
@localDisabledModules,
Ops.get_string(m, "name", "")
)
Builtins.y2milestone("Enabling module: %1", m)
@DisabledModules = Builtins.filter(@DisabledModules) do |one_module|
Ops.get_string(m, "name", "") != one_module
end
end
end
nil
end
# Add Wizard Steps
# @param [Array<Hash>] stagemode A List of maps containing info about complete
# installation workflow.
# @return [void]
def AddWizardSteps(stagemode)
stagemode = deep_copy(stagemode)
debug_workflow = ProductFeatures.GetBooleanFeature(
"globals",
"debug_workflow"
)
@last_stage_mode = deep_copy(stagemode)
# UI::WizardCommand() can safely be called even if the respective UI
# doesn't support the wizard widget, but for optimization it makes sense
# to do expensive operations only when it is available.
# if ( ! UI::HasSpecialWidget(`Wizard ) )
# return;
wizard_textdomain = Ops.get_string(
@productControl,
"textdomain",
"control"
)
Builtins.y2debug(
"Using textdomain '%1' for wizard steps",
wizard_textdomain
)
first_id = ""
# UI::WizardCommand(`SetVerboseCommands( true ) );
Builtins.foreach(stagemode) do |sm|
Builtins.y2debug("Adding wizard steps for %1", sm)
# only for debugging
Builtins.y2milestone("Adding wizard steps for %1", sm)
slabel = getWorkflowLabel(
Ops.get_string(sm, "stage", ""),
Ops.get_string(sm, "mode", ""),
wizard_textdomain
)
UI.WizardCommand(term(:AddStepHeading, slabel)) if slabel != ""
# just to check whether there are some steps to display
enabled_modules = getModules(
Ops.get_string(sm, "stage", ""),
Ops.get_string(sm, "mode", ""),
:enabled
)
enabled_modules = Builtins.filter(enabled_modules) do |m|
Ops.get_string(m, "heading", "") == ""
end
if Builtins.size(enabled_modules) == 0
Builtins.y2milestone(
"There are no (more) steps for %1, section will be disabled",
sm
)
next
end
last_label = ""
last_domain = ""
Builtins.foreach(
getModules(
Ops.get_string(sm, "stage", ""),
Ops.get_string(sm, "mode", ""),
:enabled
)
) do |m|
# only for debugging
Builtins.y2debug("Adding wizard step: %1", m)
heading = ""
label = ""
id = ""
# Heading
if Builtins.haskey(m, "heading") &&
Ops.get_string(m, "label", "") != ""
heading = if Builtins.haskey(m, "textdomain")
Builtins.dgettext(
Ops.get_string(m, "textdomain", ""),
Ops.get_string(m, "label", "")
)
else
Builtins.dgettext(
wizard_textdomain,
Ops.get_string(m, "label", "")
)
end
# Label
elsif Ops.get_string(m, "label", "") != ""
first_id = Ops.get_string(m, "id", "") if first_id == ""
label = if Builtins.haskey(m, "textdomain")
Builtins.dgettext(
Ops.get_string(m, "textdomain", ""),
Ops.get_string(m, "label", "")
)
else
Builtins.dgettext(
wizard_textdomain,
Ops.get_string(m, "label", "")
)
end
id = Ops.get_string(m, "id", "")
last_label = Ops.get_string(m, "label", "")
last_domain = Ops.get_string(m, "textdomain", "")
# The rest
else
first_id = Ops.get_string(m, "id", "") if first_id == ""
if last_label != ""
if last_domain != ""
label = Builtins.dgettext(last_domain, last_label)
id = Ops.get_string(m, "id", "")
else
label = Builtins.dgettext(wizard_textdomain, last_label)
end
id = Ops.get_string(m, "id", "")
end
end
if !heading.nil? && heading != ""
UI.WizardCommand(term(:AddStepHeading, heading))
end
if !label.nil? && label != ""
if debug_workflow == true
label = Ops.add(
label,
Builtins.sformat(" [%1]", Ops.get_string(m, "name", ""))
)
end
Builtins.y2debug("AddStep: %1/%2", label, id)
UI.WizardCommand(term(:AddStep, label, id))
end
end
end
UI.WizardCommand(term(:SetCurrentStep, @CurrentWizardStep))
nil
end
# Update Steps
def UpdateWizardSteps(stagemode)
stagemode = deep_copy(stagemode)
if @force_UpdateWizardSteps == true
Builtins.y2milestone("UpdateWizardSteps forced")
@force_UpdateWizardSteps = false
elsif @DisabledModules != @lastDisabledModules
Builtins.y2milestone("Disabled modules were changed")
elsif @last_stage_mode == stagemode
Builtins.y2milestone("No changes in Wizard steps")
return
end
@last_stage_mode = deep_copy(stagemode)
@lastDisabledModules = deep_copy(@DisabledModules)
UI.WizardCommand(term(:DeleteSteps))
# Also redraws the wizard and sets the current step
AddWizardSteps(stagemode)
nil
end
# Retranslate Wizard Steps
def RetranslateWizardSteps
if Ops.greater_than(Builtins.size(@last_stage_mode), 0)
Builtins.y2debug("Retranslating wizard steps")
@force_UpdateWizardSteps = true
UpdateWizardSteps(@last_stage_mode)
end
nil
end
def getMatchingProposal(stage, mode, proptype)
Builtins.y2milestone(
"Stage: %1 Mode: %2, Type: %3",
stage,
mode,
proptype
)
# First we search for proposals for current stage if there are
# any.
props = Builtins.filter(@proposals) do |p|
Check(Ops.get_string(p, "stage", ""), stage)
end
Builtins.y2debug("1. proposals: %1", props)
# Then we check for mode: installation or update
props = Builtins.filter(props) do |p|
Check(Ops.get_string(p, "mode", ""), mode)
end
Builtins.y2debug("2. proposals: %1", props)
# Now we check for architecture
Builtins.y2debug(
"Architecture: %1, Proposals: %2",
Arch.architecture,
props
)