Class: Yast::ProductLicenseClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) AcceptanceNeeded(id)

Returns whether accepting the license manually is requied.

Returns:

  • (Boolean)

    if required

See Also:

  • #448598


344
345
346
# File '../../src/modules/ProductLicense.rb', line 344

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

- (Object) AllLicensesAccepted



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

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 = Convert.to_string(
      UI.QueryWidget(Id(eula_id), :CurrentButton)
    )
    Builtins.y2milestone(
      "License %1 accepted: %2",
      eula_id,
      license_accepted
    )
    if !Builtins.regexpmatch(license_accepted, "^yes_")
      accepted = false
      raise Break
    end
  end

  accepted
end

- (Object) AllLicensesAcceptedOrDeclined



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

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
    current_button = Convert.to_string(
      UI.QueryWidget(Id(eula_id), :CurrentButton)
    )
    # license have to be accepted or declined
    if current_button == nil
      Builtins.y2warning(
        "License %1 hasn't been accepted or declined",
        eula_id
      )
      ret = false
      raise Break
    end
  end

  ret
end

- (Object) AskAddOnLicenseAgreement(src_id)



1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
# File '../../src/modules/ProductLicense.rb', line 1442

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)



1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
# File '../../src/modules/ProductLicense.rb', line 1456

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)



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
# File '../../src/modules/ProductLicense.rb', line 1601

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



1616
1617
1618
1619
1620
# File '../../src/modules/ProductLicense.rb', line 1616

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)

    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. Well, of course it must be string.



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
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
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
# File '../../src/modules/ProductLicense.rb', line 1189

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)
  DisplayLicenseDialog(
    available_langs, # license id
    enable_back,
    @lic_lang,
    licenses_ref,
    id
  )
  licenses = licenses_ref.value

  # 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
    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:

  • src_id

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

  • 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

  • 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).



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
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
# File '../../src/modules/ProductLicense.rb', line 1299

def AskLicensesAgreement(dirs, patterns, action, enable_back, base_product, require_agreement)
  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

  init_ret = nil

  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

  # dialog caption
  caption = _("License Agreement")

  license_idents = []

  # initial loop
  ret = nil

  licenses = []
  counter = -1
  contents = VBox()
  # 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 || !Stage.initial

  CleanUp()

  ret
end

- (Object) CleanUp

Generic cleanup



1164
1165
1166
1167
1168
1169
1170
# File '../../src/modules/ProductLicense.rb', line 1164

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:

  • string

    temporary directory path



502
503
504
505
506
507
508
509
510
511
# File '../../src/modules/ProductLicense.rb', line 502

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 with Help and ( ) Yes / ( ) No radio buttons

Parameters:

  • string

    file with the license



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

def DisplayLicenseDialog(languages, back, license_language, licenses, id)
  languages = deep_copy(languages)
  # dialog caption
  caption = _("License Agreement")

  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
  )

  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



96
97
98
99
100
101
# File '../../src/modules/ProductLicense.rb', line 96

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.



82
83
84
85
86
87
88
89
90
91
92
# File '../../src/modules/ProductLicense.rb', line 82

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)



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

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)



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

def GetLicenseDialog(languages, license_language, licenses, id, spare_space)
  languages = deep_copy(languages)
  display = UI.GetDisplayInfo
  space = Ops.get_boolean(display, "TextMode", true) ? 1 : 3

  license_buttons = VBox(
    VSpacing(spare_space ? 0 : 2),
    RadioButtonGroup(
      Id(Builtins.sformat("eula_%1", id)),
      HBox(
        HSpacing(Ops.multiply(2, space)),
        VBox(
          Left(
            RadioButton(
              Id(Builtins.sformat("yes_%1", id)),
              Opt(:notify),
              # radio button
              _("&Yes, I Agree to the License Agreement")
            )
          ),
          Left(
            RadioButton(
              Id(Builtins.sformat("no_%1", id)),
              Opt(:notify),
              # radio button
              _("N&o, I Do not Agree")
            )
          )
        ),
        HSpacing(Ops.multiply(2, space))
      )
    )
  )

  VBox(
    VSpacing(spare_space ? 0 : 1),
    HBox(
      HSpacing(Ops.multiply(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(Ops.multiply(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(Ops.multiply(2, space)),
      @license_file_print != nil ?
        Left(
          # FATE #302018
          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(Ops.multiply(2, space))
    ),
    VSpacing(spare_space ? 0 : 1)
  )
end

- (Object) GetLicenseDialogHelp



451
452
453
454
455
456
457
458
# File '../../src/modules/ProductLicense.rb', line 451

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)



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

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 == ""
      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

- (String) GetLicenseIdentString(filename)

Creates a unique identification from filename (MD5sum + file size)

Parameters:

  • filename (String)

Returns:

  • (String)

    unique ID



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File '../../src/modules/ProductLicense.rb', line 108

def GetLicenseIdentString(filename)
  if !FileUtils.Exists(filename)
    Builtins.y2error("License '%1' doesn't exist", filename)
    return nil
  end

  filemd5 = FileUtils.MD5sum(filename)
  return nil if filemd5 == nil

  ret = Builtins.sformat("%1-%2", filemd5, FileUtils.GetSize(filename))

  Builtins.y2milestone("License ident for '%1' is '%2'", filename, ret)

  ret
end

- (Object) GetSourceLicenseDirectory(src_id, fallback_dir)

Functions for handling different locations of licenses <–



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

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)



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
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
# File '../../src/modules/ProductLicense.rb', line 1065

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

  while true
    ret = UI.UserInput

    if Ops.is_string?(ret) &&
        Builtins.regexpmatch(Builtins.tostring(ret), "^license_language_")
      licenses_ref = arg_ref(licenses.value)
      UpdateLicenseContent(licenses_ref, GetId(Builtins.tostring(ret)))
      licenses.value = licenses_ref.value
      ret = :language 
      # bugzilla #303828
      # disabled next button unless yes/no is selected
    elsif Ops.is_string?(ret) &&
        (Builtins.regexpmatch(Builtins.tostring(ret), "^yes_") ||
          Builtins.regexpmatch(Builtins.tostring(ret), "^no_"))
      Wizard.EnableNextButton if AllLicensesAcceptedOrDeclined() 
      # Aborting the license dialog
    elsif ret == :abort
      # bugzilla #218677
      if base_product
        if Popup.ConfirmAbort(:painless)
          Builtins.y2milestone("Aborting...")
          ret = :abort
          break
        end
      else
        # popup question
        if Popup.YesNo(_("Really abort the add-on product installation?"))
          Builtins.y2milestone("Aborting...")
          ret = :abort
          break
        end
      end
    elsif ret == :next
      # License declined
      if AllLicensesAccepted() != true
        # message is void in case not accepting license doesn't stop the installation
        if action == "continue"
          Builtins.y2milestone(
            "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?"
          )
        if !Popup.YesNo(refuse_popup_text)
          next
        else
          Builtins.y2milestone("License has been declined.")
          if action == "abort"
            ret = :abort
            break
          elsif action == "continue"
            ret = :accepted
            break
          elsif action == "halt"
            ret = :halt
            break
            # timed ok/cancel popup
            if !Popup.TimedOKCancel(_("The system is shutting down..."), 10)
              next
            else
              ret = :halt
              break
            end
          else
            Builtins.y2error("Unknown action %1", action)
            ret = :abort
            break
          end
        end
      else
        Builtins.y2milestone("All licenses have been accepted.")
        ret = :accepted
        break
      end
    elsif ret == :back
      ret = :back
      break
    else
      Builtins.y2error("Unhandled input: %1", ret)
    end
  end

  Convert.to_symbol(ret)
end

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



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

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
  )
  license_ident.value = GetLicenseIdentString(base_license)

  # agreement might be required even if license has been already accepted
  # defined, properly ($md5sum(32)-(1)$size(1..n))
  #
  # see also BNC #448598
  # Even if it it shown it sometimes doesn't need to be even accepted by
  # selecting "yes, I agree"
  if require_agreement != true &&
      Builtins.tostring(license_ident.value) != nil &&
      Ops.greater_than(Builtins.size(license_ident.value), 33) &&
      IsLicenseAlreadyAccepted(license_ident.value)
    Builtins.y2milestone("License has been already accepted/shown")

    CleanUpLicense(@tmpdir)
    return :accepted
  else
    Builtins.y2milestone("License needs to be shown")
  end

  # 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

- (Boolean) IsLicenseAlreadyAccepted(license_ident)

Checks whether the license (file) has been already accepted

Parameters:

  • string

    filename

Returns:

  • (Boolean)

    whether the license has been accepted before



128
129
130
131
132
133
134
135
# File '../../src/modules/ProductLicense.rb', line 128

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

  Builtins.contains(@already_accepted_licenses, license_ident)
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 ]



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

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:

  • string

    filename



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File '../../src/modules/ProductLicense.rb', line 140

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

  Builtins.y2milestone(
    "Adding License ID '%1' as already accepted",
    license_ident
  )
  @already_accepted_licenses = Builtins.add(
    @already_accepted_licenses,
    license_ident
  )

  nil
end

- (Object) main



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

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"

  # list of already accepted licenses
  @already_accepted_licenses = []

  @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)



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

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)



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

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)



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

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)



677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File '../../src/modules/ProductLicense.rb', line 677

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)



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File '../../src/modules/ProductLicense.rb', line 348

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



1478
1479
1480
1481
1482
1483
1484
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
1540
1541
1542
# File '../../src/modules/ProductLicense.rb', line 1478

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



1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
# File '../../src/modules/ProductLicense.rb', line 1545

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)



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

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' :->



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

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

  nil
end

- (Object) WhichLicenceFile(license_language, licenses)



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File '../../src/modules/ProductLicense.rb', line 158

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