/
WorkflowManager.rb
1438 lines (1247 loc) · 47.5 KB
/
WorkflowManager.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/WorkflowManager.ycp
# Package: yast2
# Summary: Provides API for configuring workflows
# Authors: Lukas Ocilka <locilka@suse.cz>
#
# Provides API for managing and configuring installation and
# configuration workflow.
#
# Module was created as a solution for
# FATE #129: Framework for pattern based Installation/Deployment
#
# Module unifies Add-Ons and Patterns modifying the workflow.
#
# $Id: $
require "yast"
module Yast
class WorkflowManagerClass < Module
include Yast::Logger
def main
Yast.import "UI"
Yast.import "Pkg"
textdomain "base"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
Yast.import "Label"
Yast.import "Wizard"
Yast.import "Directory"
Yast.import "FileUtils"
Yast.import "Stage"
Yast.import "String"
Yast.import "XML"
Yast.import "Report"
Yast.import "Mode"
Yast.import "AutoinstGeneral"
#
# This API uses some new terms that need to be explained:
#
# * Workflow Store
# - Kind of database of installation or configuration workflows
#
# * Base Workflow
# - The initial workflow defined by the base product
# - In case of running system, this will be probably empty
#
# * Additional Workflow
# - Any workflow defined by Add-On or Pattern in installation
# or Pattern in running system
#
# * Final Workflow
# - Workflow that contains the base workflow modified by all
# additional workflows
#
# Base Workflow Store
@wkf_initial_workflows = []
@wkf_initial_proposals = []
@wkf_initial_inst_finish = []
@wkf_initial_clone_modules = []
@wkf_initial_product_features = {}
# Additional inst_finish settings defined by additional control files.
# They are always empty at the begining.
@additional_finish_steps_before_chroot = []
@additional_finish_steps_after_chroot = []
@additional_finish_steps_before_umount = []
# FATE #305578: Add-On Product Requiring Registration
# $[ "workflow filename" : (boolean) require_registration ]
@workflows_requiring_registration = []
@workflows_to_sources = {}
@base_workflow_stored = false
# Contains all currently workflows added to the Workflow Store
@used_workflows = []
# Some workflow changes need merging
@unmerged_changes = false
# Have system proposals already been prepared for merging?
@system_proposals_prepared = false
# Have system workflows already been prepared for merging?
@system_workflows_prepared = false
@control_files_dir = "additional-control-files"
end
# Returns list of additional inst_finish steps requested by
# additional workflows.
#
# @param [String] which_steps (type) of finish ("before_chroot", "after_chroot" or "before_umount")
# @return [Array<String>] steps to be called ...see which_steps parameter
def GetAdditionalFinishSteps(which_steps)
if which_steps == "before_chroot"
return deep_copy(@additional_finish_steps_before_chroot)
elsif which_steps == "after_chroot"
return deep_copy(@additional_finish_steps_after_chroot)
elsif which_steps == "before_umount"
return deep_copy(@additional_finish_steps_before_umount)
else
Builtins.y2error("Unknown FinishSteps type: %1", which_steps)
return nil
end
end
# Stores the current ProductControl settings as the initial settings.
# These settings are: workflows, proposals, inst_finish, and clone_modules.
#
# @param [Boolean] force storing even if it was already stored, in most cases, it should be 'false'
def SetBaseWorkflow(force)
if @base_workflow_stored && !force
Builtins.y2milestone("Base Workflow has been already set")
return
end
@wkf_initial_product_features = ProductFeatures.Export
@wkf_initial_workflows = deep_copy(ProductControl.workflows)
@wkf_initial_proposals = deep_copy(ProductControl.proposals)
@wkf_initial_inst_finish = deep_copy(ProductControl.inst_finish)
@wkf_initial_clone_modules = deep_copy(ProductControl.clone_modules)
@additional_finish_steps_before_chroot = []
@additional_finish_steps_after_chroot = []
@additional_finish_steps_before_umount = []
@base_workflow_stored = true
nil
end
# Check all proposals, split those ones which have multiple modes or
# architectures or stages into multiple proposals.
#
# @param list <map> current proposals
# @return [Array<Hash>] updated proposals
#
#
# **Structure:**
#
#
# Input: [
# $["label":"Example", "name":"example","proposal_modules":["one","two"],"stage":"initial,firstboot"]
# ]
# Output: [
# $["label":"Example", "name":"example","proposal_modules":["one","two"],"stage":"initial"]
# $["label":"Example", "name":"example","proposal_modules":["one","two"],"stage":"firstboot"]
# ]
def PrepareProposals(proposals)
proposals = deep_copy(proposals)
new_proposals = []
# Going through all proposals
Builtins.foreach(proposals) do |one_proposal|
mode = Ops.get_string(one_proposal, "mode", "")
modes = Builtins.splitstring(mode, ",")
modes = [""] if Builtins.size(modes) == 0
# Going through all modes in proposal
Builtins.foreach(modes) do |one_mode|
mp = deep_copy(one_proposal)
Ops.set(mp, "mode", one_mode)
arch = Ops.get_string(one_proposal, "archs", "")
archs = Builtins.splitstring(arch, ",")
archs = [""] if Builtins.size(archs) == 0
# Going through all architectures
Builtins.foreach(archs) do |one_arch|
amp = deep_copy(mp)
Ops.set(amp, "archs", one_arch)
stage = Ops.get_string(amp, "stage", "")
stages = Builtins.splitstring(stage, ",")
stages = [""] if Builtins.size(stages) == 0
# Going through all stages
Builtins.foreach(stages) do |one_stage|
single_proposal = deep_copy(amp)
Ops.set(single_proposal, "stage", one_stage)
new_proposals = Builtins.add(new_proposals, single_proposal)
end
end
end
end
deep_copy(new_proposals)
end
# Check all proposals, split those ones which have multiple modes or
# architectures or stages into multiple proposals.
# Works with base product proposals.
def PrepareSystemProposals
return if @system_proposals_prepared
ProductControl.proposals = PrepareProposals(ProductControl.proposals)
@system_proposals_prepared = true
nil
end
# Check all workflows, split those ones which have multiple modes or
# architectures or stages into multiple workflows
# @param [Array<Hash>] workflows
# @return [Array<Hash>] updated workflows
def PrepareWorkflows(workflows)
workflows = deep_copy(workflows)
new_workflows = []
# Going through all workflows
Builtins.foreach(workflows) do |one_workflow|
mode = Ops.get_string(one_workflow, "mode", "")
modes = Builtins.splitstring(mode, ",")
modes = [""] if Builtins.size(modes) == 0
# Going through all modes
Builtins.foreach(modes) do |one_mode|
mw = deep_copy(one_workflow)
Ops.set(mw, "mode", one_mode)
Ops.set(mw, "defaults", Ops.get_map(mw, "defaults", {}))
arch = Ops.get_string(mw, ["defaults", "archs"], "")
archs = Builtins.splitstring(arch, ",")
archs = [""] if Builtins.size(archs) == 0
# Going through all architercures
Builtins.foreach(archs) do |one_arch|
amw = deep_copy(mw)
Ops.set(amw, ["defaults", "archs"], one_arch)
stage = Ops.get_string(amw, "stage", "")
stages = Builtins.splitstring(stage, ",")
stages = [""] if Builtins.size(stages) == 0
# Going through all stages
Builtins.foreach(stages) do |one_stage|
single_workflow = deep_copy(amw)
Ops.set(single_workflow, "stage", one_stage)
new_workflows = Builtins.add(new_workflows, single_workflow)
end
end
end
end
deep_copy(new_workflows)
end
# Check all workflows, split those ones which have multiple modes or
# architectures or stages into multiple worlflows.
# Works with base product workflows.
def PrepareSystemWorkflows
return if @system_workflows_prepared
ProductControl.workflows = PrepareWorkflows(ProductControl.workflows)
@system_workflows_prepared = true
nil
end
# Fills the workflow with initial settings to start merging from scratch.
# Used workflows mustn't be cleared automatically, merging would fail!
def FillUpInitialWorkflowSettings
if !@base_workflow_stored
Builtins.y2error(
"Base Workflow has never been stored, you should have called SetBaseWorkflow() before!"
)
end
ProductFeatures.Import(@wkf_initial_product_features)
ProductControl.workflows = deep_copy(@wkf_initial_workflows)
ProductControl.proposals = deep_copy(@wkf_initial_proposals)
ProductControl.inst_finish = deep_copy(@wkf_initial_inst_finish)
ProductControl.clone_modules = deep_copy(@wkf_initial_clone_modules)
@additional_finish_steps_before_chroot = []
@additional_finish_steps_after_chroot = []
@additional_finish_steps_before_umount = []
@workflows_requiring_registration = []
@workflows_to_sources = {}
# reset internal variable to force the Prepare... function
@system_proposals_prepared = false
PrepareSystemProposals()
# reset internal variable to force the Prepare... function
@system_workflows_prepared = false
PrepareSystemWorkflows()
nil
end
# Resets the Workflow (and proposals) to use the base workflow. It must be stored.
# Clears also all additional workflows.
def ResetWorkflow
FillUpInitialWorkflowSettings()
@used_workflows = []
nil
end
# Returns the current (default) directory where workflows are stored in.
def GetWorkflowDirectory
Builtins.sformat("%1/%2", Directory.tmpdir, @control_files_dir)
end
# Creates path to a control file from parameters. For add-on products,
# the 'ident' parameter is empty.
#
# @param [Fixnum] src_id with source ID
# @param [String] ident with pattern name (or another unique identification), empty for Add-Ons
# @return [String] path to a control file based on src_id and ident params
def GenerateAdditionalControlFilePath(src_id, ident)
# special handling for Add-Ons (they have no special ident)
ident = "__AddOnProduct-ControlFile__" if ident == ""
Builtins.sformat("%1/%2:%3.xml", GetWorkflowDirectory(), src_id, ident)
end
# Stores the workflow file to a cache
#
# @param [String] file_from filename
# @param [String] file_to filename
# @return [String] final filename
def StoreWorkflowFile(file_from, file_to)
if file_from.nil? || file_from == "" || file_to.nil? || file_to == ""
Builtins.y2error("Cannot copy '%1' to '%2'", file_from, file_to)
return nil
end
# Return nil if cannot copy
file_location = nil
Builtins.y2milestone(
"Copying workflow from '%1' to '%2'",
file_from,
file_to
)
cmd = Convert.to_map(
SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"\n" \
"test -d '%1' || /bin/mkdir -p '%1';\n" \
"/bin/cp -v '%2' '%3';\n",
GetWorkflowDirectory(),
String.Quote(file_from),
String.Quote(file_to)
)
)
)
# successfully copied
if Ops.get_integer(cmd, "exit", -1) == 0
file_location = file_to
else
Builtins.y2error("Error occurred while copying control file: %1", cmd)
# Not in installation, try to skip the error
if !Stage.initial && FileUtils.Exists(file_from)
Builtins.y2milestone("Using fallback file %1", file_from)
file_location = file_from
end
end
file_location
end
# Returns requested control filename. Parameter 'name' is ignored
# for Add-Ons.
#
# @param [Symbol] type `addon or `pattern
# @param [Fixnum] src_id with Source ID
# @param [String] name with unique identification
# @return [String] path to already cached workflow file, control file is downloaded if not yet chached
def GetCachedWorkflowFilename(type, src_id, _name)
if type == :addon
disk_filename = GenerateAdditionalControlFilePath(src_id, "")
# A cached copy exists
if FileUtils.Exists(disk_filename)
Builtins.y2milestone("Using cached file %1", disk_filename)
return disk_filename
# Trying to get the file from source
else
Builtins.y2milestone("File %1 not cached", disk_filename)
# using a file from source
use_filename = Pkg.SourceProvideDigestedFile(
src_id,
1,
"/installation.xml",
true
)
# File exists
if !use_filename.nil?
return StoreWorkflowFile(use_filename, disk_filename)
# No such file
else
return nil
end
end
# New workflow types can be added here
else
Builtins.y2error("Unknown workflow type: %1", type)
return nil
end
end
# Stores new workflow (if such workflow exists) into the Worflow Store.
#
# @param [Symbol] type `addon or `pattern
# @param intger src_id with source ID
# @param [String] name with unique identification name of the object
# ("" for `addon, pattern name for `pattern)
# @return [Boolean] whether successful (true also in case of no workflow file)
#
# @example
# AddWorkflow (`addon, 4, "");
def AddWorkflow(type, src_id, name)
Builtins.y2milestone(
"Adding Workflow: Type %1, ID %2, Name %3",
type,
src_id,
name
)
if !Builtins.contains([:addon, :pattern], type)
Builtins.y2error("Unknown workflow type: %1", type)
return false
end
# new xml filename
used_filename = nil
if type == :addon
used_filename = GetCachedWorkflowFilename(:addon, src_id, "")
elsif type == :pattern
Builtins.y2error("Not implemented yet")
return false
end
if !used_filename.nil? && used_filename != ""
@unmerged_changes = true
@used_workflows = Builtins.add(@used_workflows, used_filename)
Ops.set(@workflows_to_sources, used_filename, src_id)
end
true
end
# Removes workflow (if such workflow exists) from the Worflow Store.
# Alose removes the cached file but in the installation.
#
# @param [Symbol] type `addon or `pattern
# @param intger src_id with source ID
# @param [String] name with unique identification name of the object
#
# @return [Boolean] whether successful (true also in case of no workflow file)
#
# @example
# RemoveWorkflow (`addon, 4, "");
def RemoveWorkflow(type, src_id, name)
Builtins.y2milestone(
"Removing Workflow: Type %1, ID %2, Name %3",
type,
src_id,
name
)
if !Builtins.contains([:addon, :pattern], type)
Builtins.y2error("Unknown workflow type: %1", type)
return false
end
# cached xml file
used_filename = nil
if type == :addon
used_filename = GenerateAdditionalControlFilePath(src_id, "")
else
Builtins.y2error("Not implemented yet")
return false
end
if !used_filename.nil? && used_filename != ""
@unmerged_changes = true
@used_workflows = Builtins.filter(@used_workflows) do |one_workflow|
one_workflow != used_filename
end
if Builtins.haskey(@workflows_to_sources, used_filename)
@workflows_to_sources = Builtins.remove(
@workflows_to_sources,
used_filename
)
end
if !Stage.initial
if FileUtils.Exists(used_filename)
Builtins.y2milestone(
"Removing cached file '%1': %2",
used_filename,
SCR.Execute(path(".target.remove"), used_filename)
)
end
end
end
true
end
# Removes all xml and ycp files from directory where
#
# FIXME: this function seems to be unused, remove it?
def CleanWorkflowsDirectory
directory = GetWorkflowDirectory()
Builtins.y2milestone(
"Removing all xml and ycp files from '%1' directory",
directory
)
if FileUtils.Exists(directory)
# doesn't add RPM dependency on tar
cmd = Convert.to_map(
SCR.Execute(
path(".target.bash_ouptut"),
"\n" \
"cd '%1';\n" \
"test -x /bin/tar && /bin/tar -zcf workflows_backup.tgz *.xml *.ycp *.rb;\n" \
"rm -rf *.xml *.ycp *.rb",
String.Quote(directory)
)
)
if Ops.get_integer(cmd, "exit", -1) != 0
Builtins.y2error("Removing failed: %1", cmd)
end
end
nil
end
# Replace a module in a proposal with a set of other modules
#
# @param [Hash] proposal a map describing the proposal
# @param [String] old string the old item to be replaced
# @param [Array<String>] new a list of items to be put into instead of the old one
# @return a map with the updated proposal
def ReplaceProposalModule(proposal, old, new)
proposal = deep_copy(proposal)
new = deep_copy(new)
found = false
modules = Builtins.maplist(Ops.get_list(proposal, "proposal_modules", [])) do |m|
if Ops.is_string?(m) && Convert.to_string(m) == old ||
Ops.is_map?(m) &&
Ops.get_string(Convert.to_map(m), "name", "") == old
found = true
if Ops.is_map?(m)
next Builtins.maplist(new) do |it|
Builtins.union(Convert.to_map(m), "name" => it)
end
else
next deep_copy(new)
end
else
next [m]
end
end
if !found
Builtins.y2internal("Replace/Remove proposal item %1 not found", old)
end
Ops.set(proposal, "proposal_modules", Builtins.flatten(modules))
if Builtins.haskey(proposal, "proposal_tabs")
Ops.set(
proposal,
"proposal_tabs",
Builtins.maplist(Ops.get_list(proposal, "proposal_tabs", [])) do |tab|
modules2 = Builtins.maplist(
Ops.get_list(tab, "proposal_modules", [])
) do |m|
if m == old
next deep_copy(new)
else
next [m]
end
end
Ops.set(tab, "proposal_modules", Builtins.flatten(modules2))
deep_copy(tab)
end
)
end
deep_copy(proposal)
end
# Merge add-on proposal to a base proposal
#
# @param [Hash] base with the current product proposal
# @param [Hash] additional_control with additional control file settings
# @param [String] prod_name a name of the add-on product
# @return [Hash] merged proposals
def MergeProposal(base, additional_control, prod_name, domain)
base = deep_copy(base)
additional_control = deep_copy(additional_control)
# Additional proposal settings - Replacing items
replaces = Builtins.listmap(
Ops.get_list(additional_control, "replace_modules", [])
) do |one_addon|
old = Ops.get_string(one_addon, "replace", "")
new = Ops.get_list(one_addon, "modules", [])
{ old => new }
end
Builtins.foreach(replaces) do |old, new|
base = ReplaceProposalModule(base, old, new)
end if Ops.greater_than(
Builtins.size(replaces),
0
)
# Additional proposal settings - Removing settings
removes = Ops.get_list(additional_control, "remove_modules", [])
Builtins.foreach(removes) { |r| base = ReplaceProposalModule(base, r, []) } if Ops.greater_than(
Builtins.size(removes),
0
)
# Additional proposal settings - - Appending settings
appends = Ops.get_list(additional_control, "append_modules", [])
if Ops.greater_than(Builtins.size(appends), 0)
append2 = deep_copy(appends)
if Ops.is_map?(Ops.get(base, ["proposal_modules", 0]))
append2 = Builtins.maplist(appends) do |m|
{ "name" => m, "presentation_order" => 9999 }
end
end
Ops.set(
base,
"proposal_modules",
Builtins.merge(Ops.get_list(base, "proposal_modules", []), append2)
)
if Builtins.haskey(base, "proposal_tabs")
new_tab = {
"label" => prod_name,
"proposal_modules" => appends,
"textdomain" => domain
}
Ops.set(
base,
"proposal_tabs",
Builtins.add(Ops.get_list(base, "proposal_tabs", []), new_tab)
)
end
end
if Ops.get_string(additional_control, "enable_skip", "yes") == "no"
Ops.set(base, "enable_skip", "no")
end
deep_copy(base)
end
# Update system proposals according to proposal update metadata
#
# @param [Array<Hash>] proposals a list of update proposals
# @param [String] prod_name string the product name (used in case of tabs)
# @param [String] domain string the text domain (for translations)
# @return [Boolean] true on success
def UpdateProposals(proposals, prod_name, domain)
proposals = deep_copy(proposals)
Builtins.foreach(proposals) do |proposal|
name = Ops.get_string(proposal, "name", "")
stage = Ops.get_string(proposal, "stage", "")
mode = Ops.get_string(proposal, "mode", "")
arch = Ops.get_string(proposal, "archs", "")
found = false
new_proposals = []
arch_all_prop = {}
Builtins.foreach(ProductControl.proposals) do |p|
if Ops.get_string(p, "stage", "") != stage ||
Ops.get_string(p, "mode", "") != mode ||
Ops.get_string(p, "name", "") != name
new_proposals = Builtins.add(new_proposals, p)
next
end
if Ops.get_string(p, "archs", "") == arch || arch == "" ||
arch == "all"
p = MergeProposal(p, proposal, prod_name, domain)
found = true
elsif Ops.get_string(p, "archs", "") == "" ||
Ops.get_string(p, "archs", "") == "all"
arch_all_prop = deep_copy(p)
end
new_proposals = Builtins.add(new_proposals, p)
end
if !found
if arch_all_prop != {}
Ops.set(arch_all_prop, "archs", arch)
proposal = MergeProposal(arch_all_prop, proposal, prod_name, domain)
# completly new proposal
else
Ops.set(proposal, "textdomain", domain)
end
new_proposals = Builtins.add(new_proposals, proposal)
end
ProductControl.proposals = deep_copy(new_proposals)
end
true
end
# Replace a module in a workflow with a set of other modules
#
# @param [Hash] workflow a map describing the workflow
# @param [String] old string the old item to be replaced
# @param [Array<Hash>] new a list of items to be put into instead of the old one
# @param [String] domain string a text domain
# @param [Boolean] keep boolean true to keep original one (and just insert before)
# @return a map with the updated workflow
def ReplaceWorkflowModule(workflow, old, new, domain, keep)
workflow = deep_copy(workflow)
new = deep_copy(new)
found = false
modules = Builtins.maplist(Ops.get_list(workflow, "modules", [])) do |m|
if Ops.get_string(m, "name", "") == old
new_list = Builtins.maplist(new) do |n|
Ops.set(n, "textdomain", domain)
deep_copy(n)
end
found = true
new_list = Builtins.add(new_list, m) if keep
next deep_copy(new_list)
else
next [m]
end
end
if !found
Builtins.y2internal(
"Insert/Replace/Remove workflow module %1 not found",
old
)
end
Ops.set(workflow, "modules", Builtins.flatten(modules))
deep_copy(workflow)
end
# Merge add-on workflow to a base workflow
#
# @param [Hash] base map the base product workflow
# @param [Hash] addon map the workflow of the addon product
# @param [String] prod_name a name of the add-on product
# @return [Hash] merged workflows
def MergeWorkflow(base, addon, _prod_name, domain)
base = deep_copy(base)
addon = deep_copy(addon)
# Merging - removing steps, settings
removes = Ops.get_list(addon, "remove_modules", [])
if Ops.greater_than(Builtins.size(removes), 0)
Builtins.y2milestone("Remove: %1", removes)
Builtins.foreach(removes) do |r|
base = ReplaceWorkflowModule(base, r, [], domain, false)
end
end
# Merging - replacing steps, settings
replaces = Builtins.listmap(Ops.get_list(addon, "replace_modules", [])) do |a|
old = Ops.get_string(a, "replace", "")
new = Ops.get_list(a, "modules", [])
{ old => new }
end
if Ops.greater_than(Builtins.size(replaces), 0)
Builtins.y2milestone("Replace: %1", replaces)
Builtins.foreach(replaces) do |old, new|
base = ReplaceWorkflowModule(base, old, new, domain, false)
end
end
# Merging - inserting steps, settings
inserts = Builtins.listmap(Ops.get_list(addon, "insert_modules", [])) do |i|
before = Ops.get_string(i, "before", "")
new = Ops.get_list(i, "modules", [])
{ before => new }
end
if Ops.greater_than(Builtins.size(inserts), 0)
Builtins.y2milestone("Insert: %1", inserts)
Builtins.foreach(inserts) do |old, new|
base = ReplaceWorkflowModule(base, old, new, domain, true)
end
end
# Merging - appending steps, settings
appends = Ops.get_list(addon, "append_modules", [])
if Ops.greater_than(Builtins.size(appends), 0)
Builtins.y2milestone("Append: %1", appends)
Builtins.foreach(appends) do |new|
Ops.set(new, "textdomain", domain)
Ops.set(
base,
"modules",
Builtins.add(Ops.get_list(base, "modules", []), new)
)
end
end
deep_copy(base)
end
# Update system workflows according to workflow update metadata
#
# @param [Array<Hash>] workflows a list of update workflows
# @param [String] prod_name string the product name (used in case of tabs)
# @param [String] domain string the text domain (for translations)
# @return [Boolean] true on success
def UpdateWorkflows(workflows, prod_name, domain)
workflows = deep_copy(workflows)
Builtins.foreach(workflows) do |workflow|
stage = Ops.get_string(workflow, "stage", "")
mode = Ops.get_string(workflow, "mode", "")
arch = Ops.get_string(workflow, "archs", "")
found = false
new_workflows = []
arch_all_wf = {}
Builtins.foreach(ProductControl.workflows) do |w|
if Ops.get_string(w, "stage", "") != stage ||
Ops.get_string(w, "mode", "") != mode
new_workflows = Builtins.add(new_workflows, w)
next
end
if Ops.get_string(w, ["defaults", "archs"], "") == arch || arch == "" ||
arch == "all"
w = MergeWorkflow(w, workflow, prod_name, domain)
found = true
elsif Ops.get_string(w, ["defaults", "archs"], "") == "" ||
Ops.get_string(w, ["default", "archs"], "") == "all"
arch_all_wf = deep_copy(w)
end
new_workflows = Builtins.add(new_workflows, w)
end
if !found
if arch_all_wf != {}
Ops.set(arch_all_wf, ["defaults", "archs"], arch)
workflow = MergeWorkflow(arch_all_wf, workflow, prod_name, domain)
# completly new workflow
else
Ops.set(workflow, "textdomain", domain)
Ops.set(
workflow,
"modules",
Builtins.maplist(Ops.get_list(workflow, "modules", [])) do |mod|
Ops.set(mod, "textdomain", domain)
deep_copy(mod)
end
)
end
new_workflows = Builtins.add(new_workflows, workflow)
end
ProductControl.workflows = deep_copy(new_workflows)
end
true
end
# Add specified steps to inst_finish.
# Just modifies internal variables, inst_finish grabs them itself
#
# @param [Hash{String => Array<String>}] additional_steps a map specifying the steps to be added
# @return [Boolean] true on success
def UpdateInstFinish(additional_steps)
additional_steps = deep_copy(additional_steps)
before_chroot = Ops.get(additional_steps, "before_chroot", [])
after_chroot = Ops.get(additional_steps, "after_chroot", [])
before_umount = Ops.get(additional_steps, "before_umount", [])
@additional_finish_steps_before_chroot = Convert.convert(
Builtins.merge(@additional_finish_steps_before_chroot, before_chroot),
from: "list",
to: "list <string>"
)
@additional_finish_steps_after_chroot = Convert.convert(
Builtins.merge(@additional_finish_steps_after_chroot, after_chroot),
from: "list",
to: "list <string>"
)
@additional_finish_steps_before_umount = Convert.convert(
Builtins.merge(@additional_finish_steps_before_umount, before_umount),
from: "list",
to: "list <string>"
)
true
end
# Adapts the current workflow according to specified XML file content
#
# @param [Hash] update_file a map containing the additional product control file
# @param [String] name string the name of the additional product
# @param [String] domain string the text domain for the additional control file
#
# @return [Boolean] true on success
def UpdateInstallation(update_file, name, domain)
update_file = deep_copy(update_file)
PrepareSystemProposals()
PrepareSystemWorkflows()
proposals = Ops.get_list(update_file, "proposals", [])
proposals = PrepareProposals(proposals)
UpdateProposals(proposals, name, domain)
workflows = Ops.get_list(update_file, "workflows", [])
workflows = PrepareWorkflows(workflows)
UpdateWorkflows(workflows, name, domain)
true
end
# Add new defined proposal to the list of system proposals
#
# @param [Array<Hash>] proposals a list of proposals to be added
# @return [Boolean] true on success
def AddNewProposals(proposals)
proposals = deep_copy(proposals)
forbidden = Builtins.maplist(ProductControl.proposals) do |p|
Ops.get_string(p, "name", "")
end
forbidden = Builtins.toset(forbidden)
Builtins.foreach(proposals) do |proposal|
if !Builtins.contains(forbidden, Ops.get_string(proposal, "name", ""))
Builtins.y2milestone(
"Adding new proposal %1",
Ops.get_string(proposal, "name", "")
)
ProductControl.proposals = Builtins.add(
ProductControl.proposals,
proposal
)
else
Builtins.y2warning(
"Proposal '%1' already exists, not adding",
Ops.get_string(proposal, "name", "")
)
end
end
true
end