Class: Yast::ProductLicenseClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/ProductLicense.rb

Constant Summary

DOWNLOAD_URL_SCHEMA =
["http", "https", "ftp"]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) license_file_print

Returns the value of attribute license_file_print



17
18
19
# File '../../src/modules/ProductLicense.rb', line 17

def license_file_print
  @license_file_print
end

- (Object) license_patterns

Returns the value of attribute license_patterns



17
18
19
# File '../../src/modules/ProductLicense.rb', line 17

def license_patterns
  @license_patterns
end

Instance Method Details

- (Boolean) AcceptanceNeeded(id)

Returns whether accepting the license manually is requied.

Returns:

  • (Boolean)

    if required

See Also:

  • #448598


307
308
309
# File '../../src/modules/ProductLicense.rb', line 307

def AcceptanceNeeded(id)
  Ops.get(@license_acceptance_needed, id, true)
end

- (Object) AllLicensesAccepted



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
# File '../../src/modules/ProductLicense.rb', line 945

def AllLicensesAccepted
  # BNC #448598
  # If buttons don't exist, eula is automatically accepted
  accepted = true
  eula_id = nil

  Builtins.foreach(@license_ids) do |one_license_id|
    if AcceptanceNeeded(one_license_id) != true
      Builtins.y2milestone(
        "License %1 does not need to be accepted",
        one_license_id
      )
      next
    end
    eula_id = Builtins.sformat("eula_%1", one_license_id)
    if UI.WidgetExists(Id(eula_id)) != true
      Builtins.y2error("Widget %1 does not exist", eula_id)
      next
    end

    # All licenses have to be accepted
    license_accepted = UI.QueryWidget(Id(eula_id), :Value)

    Builtins.y2milestone(
      "License %1 accepted: %2",
      eula_id,
      license_accepted
    )

    if !license_accepted
      accepted = false
      raise Break
    end
  end

  accepted
end

- (Object) AllLicensesAcceptedOrDeclined



983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File '../../src/modules/ProductLicense.rb', line 983

def AllLicensesAcceptedOrDeclined
  ret = true

  eula_id = nil
  Builtins.foreach(@license_ids) do |one_license_id|
    next if AcceptanceNeeded(one_license_id) != true
    eula_id = Builtins.sformat("eula_%1", one_license_id)
    if UI.WidgetExists(Id(eula_id)) != true
      Builtins.y2error("Widget %1 does not exist", eula_id)
    end
  end

  ret
end

- (Object) AskAddOnLicenseAgreement(src_id)



1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
# File '../../src/modules/ProductLicense.rb', line 1382

def AskAddOnLicenseAgreement(src_id)
  AskLicenseAgreement(
    src_id,
    "",
    @license_patterns,
    "abort",
    # back button is disabled
    false,
    false,
    false,
    Builtins.tostring(src_id)
  )
end

- (Object) AskFirstStageLicenseAgreement(src_id, action)



1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
# File '../../src/modules/ProductLicense.rb', line 1396

def AskFirstStageLicenseAgreement(src_id, action)
  # bug #223258
  # disabling back button when the select-language dialog is skipped
  #
  enable_back = true
  enable_back = false if Language.selection_skipped

  AskLicenseAgreement(
    nil,
    "",
    @license_patterns,
    action,
    # back button is enabled
    enable_back,
    true,
    true,
    # unique id
    Builtins.tostring(src_id)
  )
end

- (Object) AskInstalledLicenseAgreement(directory, action)



1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
# File '../../src/modules/ProductLicense.rb', line 1541

def AskInstalledLicenseAgreement(directory, action)
  # patterns are hard-coded
  AskLicenseAgreement(
    nil,
    directory,
    [],
    action,
    false,
    true,
    false,
    directory
  )
end

- (Object) AskInstalledLicensesAgreement(directories, action)

FATE #306295: More licenses in one dialog



1556
1557
1558
1559
1560
# File '../../src/modules/ProductLicense.rb', line 1556

def AskInstalledLicensesAgreement(directories, action)
  directories = deep_copy(directories)
  # patterns are hard-coded
  AskLicensesAgreement(directories, [], action, false, true, false)
end

- (Object) AskLicenseAgreement(src_id, dir, patterns, action, enable_back, base_product, require_agreement, id)

Ask user to confirm license agreement

Parameters:

  • src_id (Fixnum, nil)

    integer repository to get the license from. If set to 'nil', the license is considered to belong to a base product

  • dir (String)

    string directory to look for the license in if src_id is nil and not 1st stage installation

  • patterns (Array<String>)

    a list of patterns for the files, regular expressions with %1 for the language

  • enable_back (Boolean)

    sets the back_button status

  • base_product (Boolean)

    defines whether it is a base or add-on product true means base product, false add-on product

  • require_agreement (Boolean)

    means that even if the license (or the very same license) has been already accepetd, ask user to accept it again (because of 'going back' in the installation proposal).

  • id (String)

    usually source id but it can be any unique id in UI



1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File '../../src/modules/ProductLicense.rb', line 1103

def AskLicenseAgreement(src_id, dir, patterns, action, enable_back, base_product, require_agreement, id)
  patterns = deep_copy(patterns)
  @lic_lang = ""
  licenses = {}
  available_langs = []
  license_ident = ""

  init_ret = (
    licenses_ref = arg_ref(licenses);
    available_langs_ref = arg_ref(available_langs);
    license_ident_ref = arg_ref(license_ident);
    _InitLicenseData_result = InitLicenseData(
      src_id,
      dir,
      licenses_ref,
      available_langs_ref,
      require_agreement,
      license_ident_ref,
      id
    );
    licenses = licenses_ref.value;
    available_langs = available_langs_ref.value;
    license_ident = license_ident_ref.value;
    _InitLicenseData_result
  )

  if init_ret == :auto || init_ret == :accepted
    Builtins.y2milestone("Returning %1", init_ret)
    return init_ret
  end

  created_new_dialog = false

  # #459391
  # If a progress is running open another dialog
  if Progress.IsRunning
    Builtins.y2milestone(
      "Some progress is running, opening new dialog for license..."
    )
    Wizard.OpenNextBackDialog
    created_new_dialog = true
  end

  licenses_ref = arg_ref(licenses)

  title = _("License Agreement")

  if src_id
    repo_data = Pkg::SourceGeneralData(src_id)

    if repo_data
      label = repo_data["name"]
      # TRANSLATORS: %s is an extension name
      # e.g. "SUSE Linux Enterprise Software Development Kit"
      title = _("%s License Agreement") % label unless label.empty?
    end
  end

  DisplayLicenseDialogWithTitle(
    available_langs, # license id
    enable_back,
    @lic_lang,
    licenses_ref,
    id,
    title
  )
  licenses = licenses_ref.value

  update_license_archive_location(src_id) if src_id

  # Display info as a popup if exists
  InstShowInfo.show_info_txt(@info_file) if @info_file != nil

  # initial loop
  ret = nil

  # set timeout for autoinstallation
  # bugzilla #206706
  if Mode.autoinst || Mode.autoupgrade
    Builtins.y2milestone(
      "AutoYaST: License has been accepted automatically"
    )
    ret = :accepted
  else
    ret = (
      licenses_ref = arg_ref(licenses);
      _HandleLicenseDialogRet_result = HandleLicenseDialogRet(
        licenses_ref,
        base_product,
        action
      );
      licenses = licenses_ref.value;
      _HandleLicenseDialogRet_result
    )
  end

  if ret == :accepted && license_ident != nil
    # store already accepted license ID
    LicenseHasBeenAccepted(license_ident)
  end

  CleanUpLicense(@tmpdir)

  # bugzilla #303922
  if created_new_dialog || !Stage.initial && src_id != nil
    Wizard.CloseDialog
  end

  CleanUp()

  ret
end

- (Object) AskLicensesAgreement(dirs, patterns, action, enable_back, base_product, require_agreement)

Ask user to confirm license agreement

Parameters:

  • dirs (Array<String>)
    • directories to look for the licenses

  • patterns (Array<String>)

    a list of patterns for the files, regular expressions with %1 for the language

  • action (String)

    what to do if the license is declined, can be “continue”, “abort” or “halt”

  • enable_back (Boolean)

    sets the back_button status

  • base_product (Boolean)

    defines whether it is a base or add-on product true means base product, false add-on product

  • require_agreement (Boolean)

    means that even if the license (or the very same license) has been already accepetd, ask user to accept it again (because of 'going back' in the installation proposal).



1230
1231
1232
1233
1234
1235
1236
1237
# File '../../src/modules/ProductLicense.rb', line 1230

def AskLicensesAgreement(dirs, patterns, action, enable_back, base_product, require_agreement)
  # dialog caption
  caption = _("License Agreement")
  heading = nil

  AskLicensesAgreementWithHeading(dirs, patterns, action, enable_back,
      base_product, require_agreement, caption, heading)
end

- (Object) AskLicensesAgreementWithHeading(dirs, patterns, action, enable_back, base_product, require_agreement, caption, heading)

Parameters:

  • caption (String)

    custom dialog title

  • heading (String)

    optional heading displayed above the license text

See Also:

  • for details


1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
# File '../../src/modules/ProductLicense.rb', line 1242

def AskLicensesAgreementWithHeading(dirs, patterns, action, enable_back,
      base_product, require_agreement, caption, heading)
  dirs = deep_copy(dirs)
  patterns = deep_copy(patterns)
  if dirs == nil || dirs == []
    Builtins.y2error("No directories: %1", dirs)
    # error message
    Report.Error("Internal Error: No license to show")
    return :auto
  end

  created_new_dialog = false

  # #459391
  # If a progress is running open another dialog
  if Progress.IsRunning
    Builtins.y2milestone(
      "Some progress is running, opening new dialog for license..."
    )
    Wizard.OpenNextBackDialog
    created_new_dialog = true
  end

  license_idents = []

  # initial loop
  ret = nil

  licenses = []
  counter = -1
  contents = VBox(
    heading ? VBox(
      VSpacing(0.5),
      Left(Heading(heading)),
      VSpacing(0.5)
    ) : Empty()
  )
  # If acceptance is not needed, there's no need to disable the button
  # by default
  default_next_button_state = true

  Builtins.foreach(dirs) do |dir|
    counter = Ops.add(counter, 1)
    Ops.set(licenses, counter, {})
    @lic_lang = ""
    available_langs = []
    license_ident = ""
    tmp_licenses = {}
    init_ret2 = (
      tmp_licenses_ref = arg_ref(tmp_licenses);
      available_langs_ref = arg_ref(available_langs);
      license_ident_ref = arg_ref(license_ident);
      _InitLicenseData_result = InitLicenseData(
        nil,
        dir,
        tmp_licenses_ref,
        available_langs_ref,
        require_agreement,
        license_ident_ref,
        dir
      );
      tmp_licenses = tmp_licenses_ref.value;
      available_langs = available_langs_ref.value;
      license_ident = license_ident_ref.value;
      _InitLicenseData_result
    )
    if license_ident != nil
      license_idents = Builtins.add(license_idents, license_ident)
    end
    license_term = (
      tmp_licenses_ref = arg_ref(tmp_licenses);
      _GetLicenseDialog_result = GetLicenseDialog(
        available_langs,
        @lic_lang,
        tmp_licenses_ref,
        dir,
        true
      );
      tmp_licenses = tmp_licenses_ref.value;
      _GetLicenseDialog_result
    )
    if license_term == nil
      Builtins.y2error("Oops, license term is: %1", license_term)
    else
      contents = Builtins.add(contents, license_term)
    end
    # Display info as a popup if exists
    InstShowInfo.show_info_txt(@info_file) if @info_file != nil
    Ops.set(licenses, counter, tmp_licenses)
    default_next_button_state = false if AcceptanceNeeded(dir)
  end

  Wizard.SetContents(
    caption,
    contents,
    GetLicenseDialogHelp(),
    enable_back,
    default_next_button_state
  )

  Wizard.SetTitleIcon("yast-license")
  Wizard.SetFocusToNextButton

  # set timeout for autoinstallation
  # bugzilla #206706
  if Mode.autoinst
    Builtins.y2milestone(
      "AutoYaST: License has been accepted automatically"
    )
    ret = :accepted
  else
    tmp_licenses = {}
    ret = (
      tmp_licenses_ref = arg_ref(tmp_licenses);
      _HandleLicenseDialogRet_result = HandleLicenseDialogRet(
        tmp_licenses_ref,
        base_product,
        action
      );
      tmp_licenses = tmp_licenses_ref.value;
      _HandleLicenseDialogRet_result
    )
    Builtins.y2milestone("Dialog ret: %1", ret)
  end

  # store already accepted license IDs
  Builtins.foreach(license_idents) do |license_ident|
    LicenseHasBeenAccepted(license_ident)
  end if ret == :accepted

  CleanUpLicense(@tmpdir)

  # bugzilla #303922
  Wizard.CloseDialog if created_new_dialog

  CleanUp()

  ret
end

- (Object) CleanUp

Generic cleanup



1079
1080
1081
1082
1083
1084
1085
# File '../../src/modules/ProductLicense.rb', line 1079

def CleanUp
  # BNC #581933: All license IDs are cached while the module is in memory.
  # Removing them when leaving the license dialog.
  @license_ids = []

  nil
end

- (Object) CleanUpLicense(tmpdir)

Removes the temporary directory for licenses

Parameters:

  • tmpdir (String)

    temporary directory path



461
462
463
464
465
466
467
468
469
470
# File '../../src/modules/ProductLicense.rb', line 461

def CleanUpLicense(tmpdir)
  if tmpdir != nil && tmpdir != "/"
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("rm -rf '%1'", String.Quote(tmpdir))
    )
  end

  nil
end

- (Object) DisplayLicenseDialog(languages, back, license_language, licenses, id)

Displays License dialog



408
409
410
411
# File '../../src/modules/ProductLicense.rb', line 408

def DisplayLicenseDialog(languages, back, license_language, licenses, id)
  # dialog title
  DisplayLicenseDialogWithTitle(languages, back, license_language, licenses, id, _("License Agreement"))
end

- (Object) DisplayLicenseDialogWithTitle(languages, back, license_language, licenses, id, caption)

Displays License with Help and ( ) Yes / ( ) No radio buttons

Parameters:

  • languages (Array<String>)

    list of license translations

  • back (Boolean)

    enable “Back” button

  • license_language (String)

    default license language

  • licenses (Hash<String,String>)

    licenses (mapping “langugage_code” => “license”)

  • id (String)

    unique license ID

  • caption (String)

    dialog title



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
# File '../../src/modules/ProductLicense.rb', line 420

def DisplayLicenseDialogWithTitle(languages, back, license_language, licenses, id, caption)
  languages = deep_copy(languages)

  contents = (
    licenses_ref = arg_ref(licenses.value);
    _GetLicenseDialog_result = GetLicenseDialog(
      languages,
      license_language,
      licenses_ref,
      id,
      false
    );
    licenses.value = licenses_ref.value;
    _GetLicenseDialog_result
  )

  # If acceptance is not needed, there's no need to disable the button
  # by default
  default_next_button_state = AcceptanceNeeded(id) ? false : true

  Wizard.SetContents(
    caption,
    contents,
    GetLicenseDialogHelp(),
    back,
    default_next_button_state
  )

  # set the initial license download URL
  update_license_location(license_language, licenses)

  Wizard.SetTitleIcon("yast-license")
  Wizard.SetFocusToNextButton

  nil
end

- (Object) EnvLangToLangCode(env_lang)

Helper func. Cuts encoding suffix off the LANG env. variable i.e. foo_BAR.UTF-8 => foo_BAR



100
101
102
103
104
105
# File '../../src/modules/ProductLicense.rb', line 100

def EnvLangToLangCode(env_lang)
  tmp = []
  tmp = Builtins.splitstring(env_lang, ".@") if env_lang != nil

  Ops.get(tmp, 0, "")
end

- (Object) GetId(id_text)

Checks the string that might contain ID of a license and eventually returns that id. See also GetIdPlease for a better ratio of successful stories.



86
87
88
89
90
91
92
93
94
95
96
# File '../../src/modules/ProductLicense.rb', line 86

def GetId(id_text)
  id = nil

  if Builtins.regexpmatch(id_text, "^license_language_.+")
    id = Builtins.regexpsub(id_text, "^license_language_(.+)", "\\1")
  else
    Builtins.y2error("Cannot get ID from %1", id_text)
  end

  id
end

- (Object) GetLicenseContent(lic_lang, licenses, id)



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
# File '../../src/modules/ProductLicense.rb', line 135

def GetLicenseContent(lic_lang, licenses, id)
  license_file = (
    licenses_ref = arg_ref(licenses.value);
    _WhichLicenceFile_result = WhichLicenceFile(lic_lang, licenses_ref);
    licenses.value = licenses_ref.value;
    _WhichLicenceFile_result
  )

  license_text = Convert.to_string(
    SCR.Read(path(".target.string"), license_file)
  )
  if license_text == nil
    if Mode.live_installation
      license_text = Builtins.sformat(
        "<b>%1</b><br>%2",
        Builtins.sformat(_("Cannot read license file %1"), license_file),
        _(
          "To show the product license properly, put the license.tar.gz file to the root of the live media when building the image."
        )
      )
    else
      Report.Error(
        Builtins.sformat(_("Cannot read license file %1"), license_file)
      )
      license_text = ""
    end
  end
  rt = Empty()

  # License is HTML (or RichText)
  if Builtins.regexpmatch(license_text, "</.*>")
    rt = MinWidth(
      80,
      RichText(Id(Builtins.sformat("welcome_text_%1", id)), license_text)
    )
  else
    # License is plain text
    # details in BNC #449188
    rt = MinWidth(
      80,
      RichText(
        Id(Builtins.sformat("welcome_text_%1", id)),
        Ops.add(Ops.add("<pre>", String.EscapeTags(license_text)), "</pre>")
      )
    )
  end

  deep_copy(rt)
end

- (Object) GetLicenseDialog(languages, license_language, licenses, id, spare_space)



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
# File '../../src/modules/ProductLicense.rb', line 335

def GetLicenseDialog(languages, license_language, licenses, id, spare_space)
  space = UI.TextMode ? 1 : 3

  license_buttons = VBox(
    VSpacing(spare_space ? 0 : 1),
    HCenter(
      CheckBox(
        Id("eula_#{id}"),
        Opt(:notify),
        # check box label
        _("I &Agree to the License Terms.")
      )
    )
  )

  VBox(
    VSpacing(spare_space ? 0 : 1),
    HBox(
      HSpacing(2 * space),
      (
        licenses_ref = arg_ref(licenses.value);
        _GetLicenseDialogTerm_result = GetLicenseDialogTerm(
          languages,
          license_language,
          licenses_ref,
          id
        );
        licenses.value = licenses_ref.value;
        _GetLicenseDialogTerm_result
      ),
      HSpacing(2 * space)
    ),
    # BNC #448598
    # yes/no buttons exist only if needed
    # if they don't exist, user is not asked to accept the license later
    AcceptanceNeeded(id) ? license_buttons : Empty(),
    VSpacing(spare_space ? 0.5 : 1),
    HBox(
      HSpacing(2 * space),
      @license_file_print != nil ?
        Left(
          # FATE #302018
          ReplacePoint(
            Id(:printing_hint),
            Label(
              # TRANSLATORS: addition license information
              # %1 is replaced with the filename
              Builtins.sformat(
                _(
                  "If you want to print this EULA, you can find it\non the first media in the file %1"
                ),
                @license_file_print
              )
            )
          )
        ) :
        Empty(),
      HSpacing(2 * space)
    ),
    VSpacing(spare_space ? 0 : 1)
  )
end

- (Object) GetLicenseDialogHelp



398
399
400
401
402
403
404
405
# File '../../src/modules/ProductLicense.rb', line 398

def GetLicenseDialogHelp
  # help text
  _(
    "<p>Read the license agreement carefully and select\n" +
      "one of the available options. If you do not agree to the license agreement,\n" +
      "the configuration will be aborted.</p>\n"
  )
end

- (Object) GetLicenseDialogTerm(languages, license_language, licenses, id)



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
# File '../../src/modules/ProductLicense.rb', line 186

def GetLicenseDialogTerm(languages, license_language, licenses, id)
  languages = deep_copy(languages)
  license_text = ""
  rt = (
    licenses_ref = arg_ref(licenses.value);
    _GetLicenseContent_result = GetLicenseContent(
      license_language,
      licenses_ref,
      id
    );
    licenses.value = licenses_ref.value;
    _GetLicenseContent_result
  )

  # bug #204791, no more "languages.ycp" client
  lang_names_orig = Language.GetLanguagesMap(false)
  if lang_names_orig == nil
    Builtins.y2error("Wrong definition of languages")
    lang_names_orig = {}
  end

  lang_names = {}

  # $[ "en" : "English (US)", "de" : "Deutsch" ]
  lang_names = Builtins.mapmap(lang_names_orig) do |code, descr|
    { code => Ops.get_string(descr, 4, "") }
  end

  # for the default fallback
  if Ops.get(lang_names, "") == nil
    # language name
    Ops.set(
      lang_names,
      "",
      Ops.get_string(lang_names_orig, ["en_US", 4], "")
    )
  end

  if Ops.get(lang_names, "en") == nil
    # language name
    Ops.set(
      lang_names,
      "en",
      Ops.get_string(lang_names_orig, ["en_US", 4], "")
    )
  end

  lang_pairs = Builtins.maplist(languages) do |l|
    name_print = Ops.get(lang_names, l, "")
    if name_print == ""
      # TODO FIXME: the language code might be longer than 2 characters,
      # e.g. "ast_ES"
      l_short = Builtins.substring(l, 0, 2)

      Builtins.foreach(lang_names) do |k, v|
        if Builtins.substring(k, 0, 2) == l_short
          name_print = v
          next true
        end
        false
      end
    end
    [l, name_print]
  end

  # filter-out languages that don't have any name
  lang_pairs = Builtins.filter(lang_pairs) do |lang_pair|
    if Ops.get(lang_pair, 1, "") == ""
      Builtins.y2warning(
        "Unknown license language '%1', filtering out...",
        lang_pair
      )
      next false
    else
      next true
    end
  end

  lang_pairs = Builtins.sort(lang_pairs) do |a, b|
    # bnc#385172: must use < instead of <=, the following means:
    # strcoll(x) <= strcoll(y) && strcoll(x) != strcoll(y)
    lsorted = Builtins.lsort([Ops.get(a, 1, ""), Ops.get(b, 1, "")])
    lsorted_r = Builtins.lsort([Ops.get(b, 1, ""), Ops.get(a, 1, "")])
    Ops.get_string(lsorted, 0, "") == Ops.get(a, 1, "") &&
      lsorted == lsorted_r
  end
  langs = Builtins.maplist(lang_pairs) do |descr|
    Item(
      Id(Ops.get(descr, 0, "")),
      Ops.get(descr, 1, ""),
      Ops.get(descr, 0, "") == license_language
    )
  end

  lang_selector_options = Opt(:notify)
  # Disable in case there is no language to select
  # bugzilla #203543
  if Ops.less_or_equal(Builtins.size(langs), 1)
    lang_selector_options = Builtins.add(lang_selector_options, :disabled)
  end

  @license_ids = Builtins.toset(Builtins.add(@license_ids, id))

  VBox(
    # combo box
    Left(
      ComboBox(
        Id(Builtins.sformat("license_language_%1", id)),
        lang_selector_options,
        _("&Language"),
        langs
      )
    ),
    ReplacePoint(Id(Builtins.sformat("license_contents_rp_%1", id)), rt)
  )
end

- (Object) GetSourceLicenseDirectory(src_id, fallback_dir)

Functions for handling different locations of licenses <–



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
# File '../../src/modules/ProductLicense.rb', line 744

def GetSourceLicenseDirectory(src_id, fallback_dir)
  Builtins.y2milestone(
    "Searching for licenses... (src_id: %1, fallback_dir: %2, mode: %3, stage: %4)",
    src_id,
    fallback_dir,
    Mode.mode,
    Stage.stage
  )

  @license_file_print = nil

  # Bugzilla #299732
  # Base Product - LiveCD installation
  if Mode.live_installation
    SearchForLicense_LiveCDInstallation(src_id, fallback_dir)

    # Base-product - license not in installation
    #   * Stage is not initial
    #   * source ID is not defined
  elsif !Stage.initial && src_id == nil
    SearchForLicense_NormalRunBaseProduct(src_id, fallback_dir)

    # Base-product - first-stage installation
    #   * Stage is initial
    #   * Source ID is not set
    # bugzilla #298342
  elsif Stage.initial && src_id == nil
    SearchForLicense_FirstStageBaseProduct(
      src_id == nil ? Ops.get(Pkg.SourceGetCurrent(true), 0, 0) : src_id,
      fallback_dir
    )

    # Add-on-product license
    #   * Source ID is set
  elsif src_id != nil && Ops.greater_than(src_id, -1)
    SearchForLicense_AddOnProduct(src_id, fallback_dir)

    # Fallback
  else
    Builtins.y2warning(
      "Source ID not defined, using fallback dir '%1'",
      fallback_dir
    )
    @license_dir = fallback_dir
  end

  Builtins.y2milestone(
    "ProductLicense settings: license_dir: %1, tmpdir: %2, info_file: %3",
    @license_dir,
    @tmpdir,
    @info_file
  )

  nil
end

- (Object) HandleLicenseDialogRet(licenses, base_product, action)



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File '../../src/modules/ProductLicense.rb', line 998

def HandleLicenseDialogRet(licenses, base_product, action)
  ret = nil

  while true
    ret = UI.UserInput
    log.info "User ret: #{ret}"

    if ret.is_a?(::String) && ret.start_with?("license_language_")
      licenses_ref = arg_ref(licenses.value)
      UpdateLicenseContent(licenses_ref, GetId(ret))
      licenses.value = licenses_ref.value
      ret = :language
    # bugzilla #303828
    # disabled next button unless yes/no is selected
    elsif ret.is_a?(::String) && ret.start_with?("eula_")
      Wizard.EnableNextButton if AllLicensesAcceptedOrDeclined()
    # Aborting the license dialog
    elsif ret == :abort
      # bnc#886662
      if Stage.initial
        next unless Popup.ConfirmAbort(:painless)
      else
        # popup question
        next unless Popup.YesNo(_("Really abort the add-on product installation?"))
      end

      log.warn "Aborting..."
      break
    elsif ret == :next
      if AllLicensesAccepted()
        log.info "All licenses have been accepted."
        ret = :accepted
        break
      end

      # License declined

      # message is void in case not accepting license doesn't stop the installation
      if action == "continue"
        log.info "action in case of license refusal is continue, not asking user"
        ret = :accepted
        break
      end

      # text changed due to bug #162499
      refuse_popup_text = base_product ?
        # text asking whether to refuse a license (Yes-No popup)
        _("Refusing the license agreement cancels the installation.\nReally refuse the agreement?")
        :
        # text asking whether to refuse a license (Yes-No popup)
        _("Refusing the license agreement cancels the add-on\nproduct installation. Really refuse the agreement?")
      next unless Popup.YesNo(refuse_popup_text)

      log.info "License has been declined."

      case action
      when "abort"
        ret = :abort
      when "halt"
        # timed ok/cancel popup
        next unless Popup.TimedOKCancel(_("The system is shutting down..."), 10)
        ret = :halt
      else
        log.error "Unknown action #{action}"
        ret = :abort
      end

      break
    elsif ret == :back
      ret = :back
      break
    else
      log.error "Unhandled input: #{ret}"
    end
  end

  log.info "Returning #{ret}"
  ret
end

- (Object) InitLicenseData(src_id, dir, licenses, available_langs, require_agreement, license_ident, id)



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
# File '../../src/modules/ProductLicense.rb', line 801

def InitLicenseData(src_id, dir, licenses, available_langs, require_agreement, license_ident, id)
  GetSourceLicenseDirectory(src_id, dir)

  # License does not need to be accepted. Well, I mean, manually selected "Yes, of course, I agree..."
  if FileUtils.Exists(
      Builtins.sformat("%1/no-acceptance-needed", @license_dir)
    )
    if id == nil
      Builtins.y2error("Parameter id not set")
    else
      SetAcceptanceNeeded(id, false)
    end
  end

  licenses.value = LicenseFiles(@license_dir, @license_patterns)

  # all other 'licenses' could be replaced by this one
  Ops.set(@all_licenses, id, licenses.value)

  return :auto if @info_file == nil && Builtins.size(licenses.value) == 0

  # Let's do getenv here. Language::language may not be initialized
  # by now (see bnc#504803, c#28). Language::Language does only
  # sysconfig reading, which is not too useful in cases like
  # 'LANG=foo_BAR yast repositories'
  language = EnvLangToLangCode(Builtins.getenv("LANG"))

  # Preferencies how the client selects from available languages
  langs = [
    language,
    Builtins.substring(language, 0, 2), # "it_IT" -> "it"
    "en_US",
    "en_GB",
    "en",
    ""
  ] # license.txt fallback
  available_langs.value = Builtins.maplist(licenses.value) do |lang, fn|
    lang
  end

  # "en" is the same as "", we don't need to have them both
  if Builtins.contains(available_langs.value, "en") &&
      Builtins.contains(available_langs.value, "")
    Builtins.y2milestone(
      "Removing license fallback '' as we already have 'en'..."
    )
    available_langs.value = Builtins.filter(available_langs.value) do |one_lang|
      one_lang != "en"
    end
  end

  Builtins.y2milestone("Preffered lang: %1", language)
  return :auto if Builtins.size(available_langs.value) == 0 # no license available
  @lic_lang = Builtins.find(langs) { |l| Builtins.haskey(licenses.value, l) }
  @lic_lang = Ops.get(available_langs.value, 0, "") if @lic_lang == nil

  Builtins.y2milestone("Preselected language: '%1'", @lic_lang)

  if @lic_lang == nil
    CleanUpLicense(@tmpdir) if @tmpdir != nil
    return :auto
  end

  # Check whether such license hasn't been already accepted
  # Bugzilla #305503
  license_ident_lang = nil

  # We need to store the original -- not localized license ID (if possible)
  Builtins.foreach(["", "en", @lic_lang]) do |check_this|
    if Builtins.contains(available_langs.value, check_this)
      license_ident_lang = check_this
      Builtins.y2milestone(
        "Using localization '%1' (for license ID)",
        license_ident_lang
      )
      raise Break
    end
  end

  # fallback
  license_ident_lang = @lic_lang if license_ident_lang == nil

  base_license = (
    licenses_ref = arg_ref(licenses.value);
    _WhichLicenceFile_result = WhichLicenceFile(
      license_ident_lang,
      licenses_ref
    );
    licenses.value = licenses_ref.value;
    _WhichLicenceFile_result
  )
  log.info "License needs to be shown"

  # bugzilla #303922
  # src_id == nil (the initial product license)
  if src_id != nil
    # use wizard with steps
    if Stage.initial
      # Wizard::OpenNextBackStepsDialog();
      # WorkflowManager::RedrawWizardSteps();
      Builtins.y2milestone("Initial stage, not opening any window...")
      # use normal wizard
    else
      Wizard.OpenNextBackDialog
    end
  end

  :cont
end

- (Object) LicenseFiles(dir, patterns)

Get all files with license existing in specified directory

Parameters:

  • dir (String)

    string directory to look into

  • patterns (Array<String>)

    a list of patterns for the files, regular expressions with %1 for the language

Returns:

  • a map $[ lang_code : filename ]



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
# File '../../src/modules/ProductLicense.rb', line 477

def LicenseFiles(dir, patterns)
  patterns = deep_copy(patterns)
  ret = {}

  return deep_copy(ret) if dir == nil

  files = Convert.convert(
    SCR.Read(path(".target.dir"), dir),
    :from => "any",
    :to   => "list <string>"
  )
  Builtins.y2milestone("All files in license directory: %1", files)

  # no license
  return {} if files == nil

  Builtins.foreach(patterns) do |p|
    if !Builtins.issubstring(p, "%")
      Builtins.foreach(files) do |file|
        #Possible license file names are regexp patterns
        #(see list <string> license_patterns)
        #so we should treat them as such (bnc#533026)
        if Builtins.regexpmatch(file, p)
          Ops.set(ret, "", Ops.add(Ops.add(dir, "/"), file))
        end
      end
    else
      regpat = Builtins.sformat(p, "(.+)")
      Builtins.foreach(files) do |file|
        if Builtins.regexpmatch(file, regpat)
          key = Builtins.regexpsub(file, regpat, "\\1")
          Ops.set(ret, key, Ops.add(Ops.add(dir, "/"), file))
        end
      end
    end
  end
  Builtins.y2milestone("Files containing license: %1", ret)
  deep_copy(ret)
end

- (Object) LicenseHasBeenAccepted(license_ident)

Sets that the license (file) has been already accepted

Parameters:

  • license_ident (String)

    file name



110
111
112
113
114
115
116
117
# File '../../src/modules/ProductLicense.rb', line 110

def LicenseHasBeenAccepted(license_ident)
  if license_ident == nil || license_ident == ""
    Builtins.y2error("Wrong license ID '%1'", license_ident)
    return
  end

  nil
end

- (Object) main



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
# File '../../src/modules/ProductLicense.rb', line 23

def main
  Yast.import "Pkg"
  Yast.import "UI"

  Yast.import "Directory"
  Yast.import "InstShowInfo"
  Yast.import "Language"
  Yast.import "Popup"
  Yast.import "Report"
  Yast.import "Stage"
  Yast.import "Wizard"
  Yast.import "Mode"
  Yast.import "FileUtils"
  Yast.import "ProductFeatures"
  Yast.import "String"
  Yast.import "WorkflowManager"
  Yast.import "Progress"

  # IMPORTANT: maintainer of yast2-installation is responsible for this module

  textdomain "packager"

  @license_patterns = [
    "license\\.html",
    "license\\.%1\\.html",
    "license\\.htm",
    "license\\.%1\\.htm",
    "license\\.txt",
    "license\\.%1\\.txt"
  ]
  # no more wildcard patterns here, UI can display only html and txt anyway

  # All licenses have their own unique ID
  @license_ids = []

  # License files by their eula_ID
  #
  # **Structure:**
  #
  #     $["ID":$[licenses]]
  @all_licenses = {}

  # filename printed in the license dialog
  @license_file_print = nil

  # BNC #448598
  # no-acceptance-needed file in license.tar.gz means the license
  # doesn't have to be accepted by user, just displayed
  @license_acceptance_needed = {}

  @tmpdir = nil
  @license_dir = nil
  @info_file = nil

  @lic_lang = ""

  # FIXME: map <string, boolean> ...
  @info_file_already_seen = {}
end

- (Object) SearchForLicense_AddOnProduct(src_id, fallback_dir)



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
# File '../../src/modules/ProductLicense.rb', line 651

def SearchForLicense_AddOnProduct(src_id, fallback_dir)
  Builtins.y2milestone("Getting license info from repository %1", src_id)

  @info_file = Pkg.SourceProvideDigestedFile(
    src_id, # optional
    1,
    "/media.1/info.txt",
    true
  )

  # using a separate license directory for all products
  @tmpdir = Builtins.sformat(
    "%1/product-license/%2/",
    Convert.to_string(SCR.Read(path(".target.tmpdir"))),
    src_id
  )

  # FATE #302018 comment #54
  license_file_location = "/license.tar.gz"
  license_file = Pkg.SourceProvideDigestedFile(
    src_id, # optional
    1,
    license_file_location,
    true
  )

  if license_file != nil
    Builtins.y2milestone("Using file %1 with licenses", license_file)

    if UnpackLicenseTgzFileToDirectory(license_file, @tmpdir)
      @license_dir = @tmpdir
      @license_file_print = "license.tar.gz"
    else
      @license_dir = nil
    end

    return
  end

  Builtins.y2milestone(
    "Licenses in %1... not supported",
    license_file_location
  )

  # New format didn't work, try the old one 1stMedia:/media.1/license.zip
  @license_dir = @tmpdir
  license_file = Pkg.SourceProvideDigestedFile(
    src_id, # optional
    1,
    "/media.1/license.zip",
    true
  )

  # no license present
  if license_file == nil
    Builtins.y2milestone("No license present")
    @license_dir = nil
    @tmpdir = nil
    # return from the function
    return
  end

  Builtins.y2milestone("Product has a license")
  out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat(
        "\nrm -rf '%1' && mkdir -p '%1' && cd '%1' && unzip -qqo '%2'\n",
        String.Quote(@tmpdir),
        String.Quote(license_file)
      )
    )
  )

  # Extracting license failed, cannot accept the license
  if Ops.get_integer(out, "exit", 0) != 0
    Builtins.y2error("Cannot unzip license -> %1", out)
    # popup error
    Report.Error(
      _("An error occurred while preparing the installation system.")
    )
    CleanUpLicense(@tmpdir)
    @license_dir = nil
  else
    @license_dir = @tmpdir
    @license_file_print = "/media.1/license.zip"
  end

  nil
end

- (Object) SearchForLicense_FirstStageBaseProduct(src_id, fallback_dir)



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
# File '../../src/modules/ProductLicense.rb', line 555

def SearchForLicense_FirstStageBaseProduct(src_id, fallback_dir)
  Builtins.y2milestone("Getting license from installation product")

  license_file = "/license.tar.gz"

  if FileUtils.Exists(license_file)
    Builtins.y2milestone("Installation Product has a license")

    @tmpdir = Builtins.sformat(
      "%1/product-license/base-product/",
      Convert.to_string(SCR.Read(path(".target.tmpdir")))
    )

    if UnpackLicenseTgzFileToDirectory(license_file, @tmpdir)
      @license_dir = @tmpdir
      @license_file_print = "license.tar.gz"
    else
      license_file = nil
    end
  else
    Builtins.y2milestone("Installation Product doesn't have a license")

    license_file = nil
  end

  @info_file = "/info.txt" if FileUtils.Exists("/info.txt")

  nil
end

- (Object) SearchForLicense_LiveCDInstallation(src_id, fallback_dir)



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
# File '../../src/modules/ProductLicense.rb', line 585

def SearchForLicense_LiveCDInstallation(src_id, fallback_dir)
  Builtins.y2milestone("LiveCD License")

  # BNC #594042: Multiple license locations
  license_locations = ["/usr/share/doc/licenses/", "/"]

  @license_dir = nil
  @info_file = nil

  Builtins.foreach(license_locations) do |license_location|
    license_location = Builtins.sformat(
      "%1/license.tar.gz",
      license_location
    )
    if FileUtils.Exists(license_location)
      Builtins.y2milestone("Using license: %1", license_location)
      @tmpdir = Builtins.sformat(
        "%1/product-license/LiveCD/",
        Convert.to_string(SCR.Read(path(".target.tmpdir")))
      )

      if UnpackLicenseTgzFileToDirectory(license_location, @tmpdir)
        @license_dir = @tmpdir
        @license_file_print = "license.tar.gz"
      else
        CleanUpLicense(@tmpdir)
      end
      raise Break
    end
  end

  if @license_dir == nil
    Builtins.y2milestone("No license found in: %1", license_locations)
  end

  Builtins.foreach(license_locations) do |info_location|
    info_location = Builtins.sformat("%1/README.BETA", info_location)
    if FileUtils.Exists(info_location)
      Builtins.y2milestone("Using info file: %1", info_location)
      @info_file = info_location
      raise Break
    end
  end

  if @info_file == nil
    Builtins.y2milestone("No info file found in: %1", license_locations)
  end

  nil
end

- (Object) SearchForLicense_NormalRunBaseProduct(src_id, fallback_dir)



636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File '../../src/modules/ProductLicense.rb', line 636

def SearchForLicense_NormalRunBaseProduct(src_id, fallback_dir)
  Builtins.y2milestone("Using default license directory %1", fallback_dir)

  if FileUtils.Exists(fallback_dir)
    @license_dir = fallback_dir
  else
    Builtins.y2warning("Fallback dir doesn't exist %1", fallback_dir)
    @license_dir = nil
  end

  @info_file = "/info.txt" if FileUtils.Exists("/info.txt")

  nil
end

- (Object) SetAcceptanceNeeded(id, new_value)



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File '../../src/modules/ProductLicense.rb', line 311

def SetAcceptanceNeeded(id, new_value)
  if new_value == nil
    Builtins.y2error(
      "Undefined behavior (License ID %1), AcceptanceNeeded: %2",
      id,
      new_value
    )
    return
  end

  Ops.set(@license_acceptance_needed, id, new_value)

  if new_value == true
    Builtins.y2milestone("License agreement (ID %1) WILL be required", id)
  else
    Builtins.y2milestone(
      "License agreement (ID %1) will NOT be required",
      id
    )
  end

  nil
end

- (Object) ShowFullScreenLicenseInInstallation(replace_point_ID, src_id)

Called from the first stage Welcome dialog by clicking on a button



1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File '../../src/modules/ProductLicense.rb', line 1418

def ShowFullScreenLicenseInInstallation(replace_point_ID, src_id)
  replace_point_ID = deep_copy(replace_point_ID)
  @lic_lang = ""
  licenses = {}
  available_langs = []
  license_ident = ""

  init_ret = (
    licenses_ref = arg_ref(licenses);
    available_langs_ref = arg_ref(available_langs);
    license_ident_ref = arg_ref(license_ident);
    _InitLicenseData_result = InitLicenseData(
      nil,
      "",
      licenses_ref,
      available_langs_ref,
      true,
      license_ident_ref,
      Builtins.tostring(src_id)
    );
    licenses = licenses_ref.value;
    available_langs = available_langs_ref.value;
    license_ident = license_ident_ref.value;
    _InitLicenseData_result
  )

  # Replaces the dialog content with Languages combo-box
  # and the current license text (richtext)
  UI.ReplaceWidget(
    Id(replace_point_ID),
    (
      licenses_ref = arg_ref(licenses);
      _GetLicenseDialogTerm_result = GetLicenseDialogTerm(
        available_langs,
        @lic_lang,
        licenses_ref,
        Builtins.tostring(src_id)
      );
      licenses = licenses_ref.value;
      _GetLicenseDialogTerm_result
    )
  )

  ret = nil

  while true
    ret = UI.UserInput

    if Ops.is_string?(ret) &&
        Builtins.regexpmatch(
          Builtins.tostring(ret),
          "^license_language_[[:digit:]]+"
        )
      licenses_ref = arg_ref(licenses)
      UpdateLicenseContent(licenses_ref, GetId(Builtins.tostring(ret)))
      licenses = licenses_ref.value
    else
      break
    end
  end

  CleanUp()

  true
end

- (Object) ShowLicenseInInstallation(replace_point_ID, src_id)

Used in the first-stage Welcome dialog



1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
# File '../../src/modules/ProductLicense.rb', line 1485

def ShowLicenseInInstallation(replace_point_ID, src_id)
  replace_point_ID = deep_copy(replace_point_ID)
  @lic_lang = ""
  licenses = {}
  available_langs = []
  license_ident = ""

  init_ret = (
    licenses_ref = arg_ref(licenses);
    available_langs_ref = arg_ref(available_langs);
    license_ident_ref = arg_ref(license_ident);
    _InitLicenseData_result = InitLicenseData(
      nil,
      "",
      licenses_ref,
      available_langs_ref,
      true,
      license_ident_ref,
      Builtins.tostring(src_id)
    );
    licenses = licenses_ref.value;
    available_langs = available_langs_ref.value;
    license_ident = license_ident_ref.value;
    _InitLicenseData_result
  )

  rt = (
    licenses_ref = arg_ref(licenses);
    _GetLicenseContent_result = GetLicenseContent(
      @lic_lang,
      licenses_ref,
      Builtins.tostring(src_id)
    );
    licenses = licenses_ref.value;
    _GetLicenseContent_result
  )
  UI.ReplaceWidget(Id(replace_point_ID), rt)

  id = Builtins.tostring(src_id)

  # Display info as a popup if exists
  if @info_file != nil &&
      Ops.get(@info_file_already_seen, id, false) != true
    if Mode.autoinst
      Builtins.y2milestone("Autoinstallation: Skipping info file...")
    else
      InstShowInfo.show_info_txt(@info_file)
      Ops.set(@info_file_already_seen, id, true)
    end
  end

  CleanUp()

  true
end

- (Object) UnpackLicenseTgzFileToDirectory(unpack_file, to_directory)



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
# File '../../src/modules/ProductLicense.rb', line 520

def UnpackLicenseTgzFileToDirectory(unpack_file, to_directory)
  # License file exists
  if FileUtils.Exists(unpack_file)
    out = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat(
          "\nrm -rf '%1' && mkdir -p '%1' && cd '%1' && tar -xzf '%2'\n",
          String.Quote(to_directory),
          String.Quote(unpack_file)
        )
      )
    )

    # Extracting license failed, cannot accept the license
    if Ops.get_integer(out, "exit", 0) != 0
      Builtins.y2error("Cannot untar license -> %1", out)
      # popup error
      Report.Error(
        _("An error occurred while preparing the installation system.")
      )
      CleanUpLicense(to_directory)
      return false
    end

    # Success
    return true

    # Nothing to unpack
  else
    Builtins.y2error("No such file: %1", unpack_file)
    return false
  end
end

- (Object) UpdateLicenseContent(licenses, id)

Should have been named 'UpdateLicenseContentBasedOnSelectedLanguage' :->



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
# File '../../src/modules/ProductLicense.rb', line 912

def UpdateLicenseContent(licenses, id)
  # read the selected language
  @lic_lang = Convert.to_string(
    UI.QueryWidget(Id(Builtins.sformat("license_language_%1", id)), :Value)
  )
  rp_id = Id(Builtins.sformat("license_contents_rp_%1", id))

  licenses.value = Ops.get(@all_licenses, id, {}) if licenses.value == {}

  if UI.WidgetExists(rp_id)
    UI.ReplaceWidget(
      rp_id,
      (
        licenses_ref = arg_ref(licenses.value);
        _GetLicenseContent_result = GetLicenseContent(
          @lic_lang,
          licenses_ref,
          id
        );
        licenses.value = licenses_ref.value;
        _GetLicenseContent_result
      )
    )
  else
    Builtins.y2error("No such widget: %1", rp_id)
  end

  # update displayed license URL after changing the license translation
  update_license_location(@lic_lang, licenses)

  nil
end

- (Object) WhichLicenceFile(license_language, licenses)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File '../../src/modules/ProductLicense.rb', line 119

def WhichLicenceFile(license_language, licenses)
  license_file = Ops.get(licenses.value, license_language, "")

  if license_file == nil || license_file == ""
    Builtins.y2error(
      "No license file defined for language '%1' in %2",
      license_language,
      licenses.value
    )
  else
    Builtins.y2milestone("Using license file: %1", license_file)
  end

  license_file
end