/
autoyast_config_workflow.rb
180 lines (151 loc) · 5.24 KB
/
autoyast_config_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
require "yast"
require "registration/helpers"
require "registration/connect_helpers"
require "registration/url_helpers"
require "registration/ui/autoyast_addon_dialog"
require "registration/ui/autoyast_config_dialog"
require "registration/ui/addon_selection_registration_dialog"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_reg_codes_dialog"
module Registration
module UI
# this class runs the AutoYast configuration workflow
class AutoyastConfigWorkflow
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts
include Yast
Yast.import "Pkg"
Yast.import "Report"
Yast.import "Sequencer"
# run the AutoYast configuration workflow
# @param config [Registration::Storage::Config] AutoYaST configuration
def self.run(config)
workflow = AutoyastConfigWorkflow.new(config)
workflow.run
end
# constructor
# @param config [Registration::Storage::Config] AutoYaST configuration
def initialize(config)
textdomain "registration"
@config = config
end
# run the workflow
# @return [Symbol] the user input
def run
aliases = {
"general" => ->() { configure_registration },
"addons" => [->() { select_addons }, true],
"remote_addons" => [->() { select_remote_addons }, true],
"addons_eula" => [->() { addons_eula }, true],
"addons_regcodes" => [->() { addons_reg_codes }, true]
}
sequence = {
"ws_start" => "general",
"general" => {
abort: :abort,
next: :next,
addons: "addons"
},
"addons" => {
abort: :abort,
next: "general",
download: "remote_addons"
},
"remote_addons" => {
addons: "addons",
abort: :abort,
next: "addons_eula"
},
"addons_eula" => {
abort: :abort,
next: "addons_regcodes"
},
"addons_regcodes" => {
abort: :abort,
next: "addons"
}
}
log.info "Starting scc_auto sequence"
Sequencer.Run(aliases, sequence)
end
private
attr_reader :config
# run the dialog configuring the AutoYaST addons
# @return [Symbol] the user input
def select_addons
AutoyastAddonDialog.run(config.addons)
end
# download the addons from SCC, let the user select addons to install
# @return [Symbol] the user input
def select_remote_addons
SwMgmt.init
url = UrlHelpers.registration_url
registration = ::Registration::Registration.new(url)
ret = nil
success = ConnectHelpers.catch_registration_errors do
Popup.Feedback(
SccAutoClient::CONTACTING_MESSAGE,
_("Loading Available Extensions and Modules...")) do
# reset registration status to allow selecting all addons
::Registration::Addon.find_all(registration).each(&:unregistered)
end
ret = AddonSelectionRegistrationDialog.run(registration)
end
success ? ret : :addons
end
# display the EULAs for the selected addons
# @return [Symbol] the user input
def addons_eula
AddonEulaDialog.run(::Registration::Addon.selected)
end
# collect the known reg. codes from the current configuration
# @return [Hash] reg. codes hash
def collect_known_reg_codes
Hash[config.addons.map { |a| [a["name"], a["reg_code"]] }]
end
# add for reg. codes for selected paid extensions
# @return [Symbol] the user input
def addons_reg_codes
known_reg_codes = collect_known_reg_codes
if !::Registration::Addon.selected.all?(&:free)
ret = AddonRegCodesDialog.run(::Registration::Addon.selected, known_reg_codes)
return ret unless ret == :next
end
update_addons(known_reg_codes)
:next
end
# find the addon in the current config
# @param addon [Hash] addon to find
# @return [Hash, nil] found addon or nil
def find_addon(addon)
config.addons.find do |a|
a["name"] == addon["name"] && a["version"] == addon["version"] &&
a["arch"] == addon["arch"] && a["release_type"] == addon["release_type"]
end
end
# update the reg. codes config
def update_addons(known_reg_codes)
::Registration::Addon.selected.each do |addon|
# FIXME: use a separate class for handling Autoyast addons,
# define == operator, etc...
new_addon = addon.to_h
new_addon["reg_code"] = known_reg_codes[addon.identifier] || ""
# already known?
config_addon = find_addon(new_addon)
# add or edit
if config_addon
config_addon.merge!(new_addon)
else
config.addons << new_addon
end
end
end
# run the main AutoYaST configuration dialog
# @return [Symbol] the user input
def configure_registration
AutoyastConfigDialog.run(config)
end
end
end
end