Class: Yast::InstProductsourcesClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/clients/inst_productsources.rb,
src/lib/y2packager/clients/inst_productsources.rb

Overview

This is a stand-alone YaST client that allows you to add suggested repositories (repositories) to the libzypp. How it works:

  • First a list of servers/links is extracted from the YaST control file (/etc/YaST2/control.xml)

  • Then servers/links are asked one by one to provide the suggested sources

Only installation_repo=true (trusted) links are used during installation. See Bugzilla #293811.

Examples:

Format of the initial list of servers:

<?xml version="1.0"?>
<productDefines xmlns="http://www.suse.com/1.0/yast2ns"
    xmlns:config="http://www.suse.com/1.0/configns">
  <servers config:type="list">
    <item>
      <link>http://some.server/some_link.xml</link>
     <official config:type="boolean">true</official>
      <installation_repo config:type="boolean">true</installation_repo>
    </item>
    <item>
      <link>ftp://some.other.server/some_link.xml</link>
      <official config:type="boolean">false</official>
    </item>
  </servers>
</productDefines>

Format of Suggested sources:

<?xml version="1.0"?>
<metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install"
    xmlns="http://opensuse.org/Standards/One_Click_Install">
  <group distversion="openSUSE Factory">
    <repositories>
      <repository recommended="true" format="yast">
        <name>Some name</name>
        <name lang="en_GB">Some name</name>
        <summary>Summary...</summary>
        <summary lang="en_GB">Summary...</summary>
        <description>Description...</description>
        <url>http://some.server/some.dir/10.3/</url>
      </repository>
      <repository recommended="false" format="yast">
        <name>Another name</name>
        <summary>Summary...</summary>
        <description>Description...</description>
        <url>http://another.server/another.dir/10.3/</url>
      </repository>
    </repositories>
  </group>
</metapackage>

Constant Summary collapse

LOW_MEMORY_MIB =

too low memory for using online repositories (in MiB), at least 1GiB is recommended

1024
RELEASEVER_ENV =

variable to set target release version ( useful during upgrade when we want new target in releaseversion and not old one )

"ZYPP_REPO_RELEASEVER".freeze
@@posted_low_memory_warning =
false
@@ask_activate_online_repos_result =
nil

Instance Method Summary collapse

Instance Method Details

#CreateAndAdjustWriteProgress(actions_todo, actions_doing) ⇒ Object


1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
# File 'src/clients/inst_productsources.rb', line 1352

def CreateAndAdjustWriteProgress(actions_todo, actions_doing)
  actions_doing = deep_copy(actions_doing)
  Builtins.y2milestone("Creating new Write() progress")

  Progress.New(
    # TRANSLATORS: dialog caption
    _("Writing List of Online Repositories"),
    " ",
    Builtins.size(actions_todo.value),
    actions_todo.value,
    actions_doing,
    # TRANSLATORS: dialog help
    _("<p>The repository manager is downloading repository details...</p>")
  )

  Wizard.SetTitleIcon("yast-sw_source")

  nil
end

#CreateRepoId(s_url, s_path) ⇒ Object


180
181
182
# File 'src/clients/inst_productsources.rb', line 180

def CreateRepoId(s_url, s_path)
  Builtins.sformat("(%1|%2)", s_url, s_path)
end

#CreateSource(url, pth, repo_name, alias_s) ⇒ nil, false

Creates source from passed parameters


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
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
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
# File 'src/lib/y2packager/clients/inst_productsources.rb', line 1386

def CreateSource(url, pth, repo_name, _actions_todo, _actions_doing, _no_progress_updates)
  src_id = nil

  repo_type = Pkg.RepositoryProbe(url, pth)
  Builtins.y2milestone("Probed repository type: %1", repo_type)

  # probing succeeded?
  if !repo_type.nil? && repo_type != "NONE"
    # create alias in form "<hostname>-<last_path_element>"
    parsed_url = URL.Parse(url)
    alias_name = Ops.get_string(parsed_url, "host", "")

    path_parts = Builtins.splitstring(
      Ops.get_string(parsed_url, "path", ""),
      "/"
    )
    # remove empty parts
    path_parts = Builtins.filter(path_parts) do |p|
      Ops.greater_than(Builtins.size(p), 0)
    end

    if Ops.greater_than(Builtins.size(path_parts), 0)
      suffix = Ops.get(
        path_parts,
        Ops.subtract(Builtins.size(path_parts), 1),
        ""
      )

      if Builtins.regexpmatch(suffix, "[0-9]+$") &&
          Ops.greater_than(Builtins.size(path_parts), 1)
        Builtins.y2milestone("Version string detected in path element")
        suffix = Ops.get(
          path_parts,
          Ops.subtract(Builtins.size(path_parts), 2),
          ""
        )
      end

      alias_name = Ops.add(Ops.add(alias_name, "-"), suffix)
    end

    alias_name = GetUniqueAlias(alias_name)
    Builtins.y2milestone("Using alias: %1", alias_name)

    src_id = Pkg.RepositoryAdd(
      "enabled"   => false,
      "name"      => repo_name,
      "base_urls" => [url],
      "prod_dir"  => pth,
      # alias needs to be unique
      # bugzilla #309317
      "alias"     => alias_name,
      "type"      => repo_type
    )
  end

  if src_id.nil?
    error = ""
    details = ""

    if repo_type.nil?
      error = Pkg.LastError
      if Ops.greater_than(Builtins.size(error), 0)
        error = Ops.add("\n\n", error)
      end

      details = Pkg.LastErrorDetails
      if Ops.greater_than(Builtins.size(details), 0)
        details = Ops.add("\n\n", details)
      end
    end

    Report.Error(
      Ops.add(
        Ops.add(
          Builtins.sformat(
            # TRANSLATORS: pop-up error message
            # %1 is replaced with a repository name or URL
            _("Adding repository %1 failed."),
            repo_name != "" ? repo_name : url
          ),
          error
        ),
        details
      )
    )
    # FIXME: retry ?
    return false
  end

  if !AddOnProduct.AcceptedLicenseAndInfoFile(src_id)
    Pkg.SourceDelete(src_id)
    return false
  end

  if !Pkg.SourceRefreshNow(src_id)
    Report.Error(
      Ops.add(
        Ops.add(
          Builtins.sformat(
            # TRANSLATORS: pop-up error message
            # %1 is replaced with a repository name or URL
            _("Adding repository %1 failed."),
            repo_name != "" ? repo_name : url
          ),
          "\n"
        ),
        Pkg.LastError
      )
    )
    return false
  end

  if !Pkg.SourceSetEnabled(src_id, true)
    Report.Error(
      Ops.add(
        Ops.add(
          Builtins.sformat(
            # TRANSLATORS: pop-up error message
            # %1 is replaced with a repository name or URL
            _("Adding repository %1 failed."),
            repo_name != "" ? repo_name : url
          ),
          "\n"
        ),
        Pkg.LastError
      )
    )
    return false
  end

  if Stage.initial
    AddOnProduct.Integrate(src_id)

    prod = Pkg.SourceProductData(src_id)
    Builtins.y2milestone("Product Data: %1", prod)

    repo_id = CreateRepoId(url, pth)
    Builtins.y2milestone("Addind repository with ID: %1", repo_id)

    AddOnProduct.add_on_products = Builtins.add(
      AddOnProduct.add_on_products,
      "media"            => src_id,
      "product"          => repo_name,
      "autoyast_product" => Ops.get_string(prod, "productname", ""),
      "media_url"        => url,
      "product_dir"      => pth
    )
  end

  nil
end

#DownloadAndParseSourcesObject


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'src/clients/inst_productsources.rb', line 572

def DownloadAndParseSources
  @list_of_repos = {}
  @list_of_servers = []

  if !DownloadFile(@main_link, UseDownloadFile())
    Builtins.y2error("Unable to download list of online repositories")
    return false
  end

  if !ParseListOfServers(UseDownloadFile())
    Builtins.y2error("Unable to parse list of servers")
    return false
  end

  Builtins.foreach(@list_of_servers) do |one_server|
    if Ops.get_string(one_server, "link", "") != ""
      Builtins.y2milestone(
        "Downloading list of repos from %1",
        Ops.get_string(one_server, "link", "")
      )

      if !DownloadFile(
        Ops.get_string(one_server, "link", ""),
        UseDownloadFile()
      )
        Builtins.y2error("Unable to download list of online repositories")
        next
      end
      if !ParseListOfSources(
        UseDownloadFile(),
        Ops.get_string(one_server, "link", "")
      )
        Builtins.y2error("Unable to parse list of repositories")
        next
      end
    end
  end

  # just for debugging purposes
  Builtins.y2debug("list_of_repos: %1", @list_of_repos)

  true
end

#DownloadFile(from, to) ⇒ Object


461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'src/clients/inst_productsources.rb', line 461

def DownloadFile(from, to)
  RemoveFileIfExists(to)
  server_response = {}

  if Builtins.regexpmatch(from, "^[hH][tT][tT][pP]://")
    from = Builtins.regexpsub(
      from,
      "^[hH][tT][tT][pP]://(.*)",
      "http://\\1"
    )

    server_response = HTTP.Get(from, to)
  elsif Builtins.regexpmatch(from, "^[fF][tT][pP]://")
    from = Builtins.regexpsub(from, "^[fF][tT][pP]://(.*)", "ftp://\\1")

    server_response = FTP.Get(from, to)
  elsif Builtins.regexpmatch(from, "^[hH][tT][tT][pP][sS]://")
    from = Builtins.regexpsub(
      from,
      "^[hH][tT][tT][pP][sS]://(.*)",
      "https://\\1"
    )

    server_response = HTTP.Get(from, to)
  else
    Builtins.y2error("Not a supported type: %1", from)
    return false
  end

  Builtins.y2milestone("Server response: %1", server_response)

  return false if server_response.nil?

  true
end

#EscapeChars(input) ⇒ Object


1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'src/clients/inst_productsources.rb', line 1142

def EscapeChars(input)
  return input if input == "" || input.nil?

  # \ must be the first character!
  escape = "\\(){}[]+^$|"
  ret = input

  i = 0
  sz = Builtins.size(escape)

  while Ops.less_than(i, sz)
    ch = Builtins.substring(escape, i, 1)
    Builtins.y2debug("Escaping %1", ch)
    ret = Builtins.mergestring(
      Builtins.splitstring(ret, ch),
      Ops.add("\\", ch)
    )
    i = Ops.add(i, 1)
  end

  ret
end

#GetCurrentLangObject


616
617
618
619
620
621
622
623
624
625
626
# File 'src/clients/inst_productsources.rb', line 616

def GetCurrentLang
  cmd = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "echo -n $LANG")
  )
  ret = Builtins.tostring(Ops.get_string(cmd, "stdout", ""))

  ret = nil if ret == "C" || ret == "" || ret == "POSIX"

  Builtins.y2milestone("Using lang: %1", ret)
  ret
end

#GetLocalizedString(current_id, possible_keys) ⇒ Object

Returns a localized string using given parametters.

*Structure:*

$[
     // key
     "description" : "repository description",
     // "localized" + key
     "localized_description" : $[
         "en_GB" : "repository description (localized to en_GB)",
         ...
     ],
 ]

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
# File 'src/clients/inst_productsources.rb', line 838

def GetLocalizedString(current_id, possible_keys)
  possible_keys = deep_copy(possible_keys)
  ret = ""

  # try localized strings at first
  Builtins.foreach(possible_keys) do |possible_key|
    loc_key = Builtins.sformat("localized_%1", possible_key)
    if Ops.get_string(
      @list_of_repos,
      [current_id, loc_key, @language_long],
      ""
    ) != ""
      ret = Ops.get_string(
        @list_of_repos,
        [current_id, loc_key, @language_long],
        ""
      )
      raise Break
    elsif Ops.get_string(
      @list_of_repos,
      [current_id, loc_key, @language_short],
      ""
    ) != ""
      ret = Ops.get_string(
        @list_of_repos,
        [current_id, loc_key, @language_short],
        ""
      )
      raise Break
    end
  end

  return ret if ret != ""

  # try default strings
  Builtins.foreach(possible_keys) do |possible_key|
    if Ops.get_string(@list_of_repos, [current_id, possible_key], "") != ""
      ret = Ops.get_string(@list_of_repos, [current_id, possible_key], "")
      raise Break
    end
  end

  ret
end

#GetUniqueAlias(alias_orig) ⇒ Object

See bugzilla #309317


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
# File 'src/clients/inst_productsources.rb', line 185

def GetUniqueAlias(alias_orig)
  alias_orig = "" if alias_orig.nil?

  # all current aliases
  aliases = Builtins.maplist(Pkg.SourceGetCurrent(false)) do |i|
    info = Pkg.SourceGeneralData(i)
    Ops.get_string(info, "alias", "")
  end

  # default
  alias_name = alias_orig

  # repository alias must be unique
  # if it already exists add "_<number>" suffix to it
  idx = 1
  while Builtins.contains(aliases, alias_name)
    alias_name = Builtins.sformat("%1_%2", alias_orig, idx)
    idx = Ops.add(idx, 1)
  end

  if alias_orig != alias_name
    Builtins.y2milestone("Alias '%1' changed to '%2'", alias_orig, alias_name)
  end

  alias_name
end

#HandleFilterButtonObject


1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
# File 'src/clients/inst_productsources.rb', line 1195

def HandleFilterButton
  StoreSelectedInDialog()

  filter_string = Convert.to_string(
    UI.QueryWidget(Id("filter_text"), :Value)
  )
  current_item = Convert.to_string(
    UI.QueryWidget(Id("addon_repos"), :CurrentItem)
  )

  filter_string = EscapeChars(filter_string)
  filter_string = MakeCaseInsensitiveRegexp(filter_string)

  InitRepositoriesWidget(filter_string, false, current_item)

  UI.SetFocus(Id("filter_text"))

  nil
end

#HandleSelectedSourcesObject


1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'src/clients/inst_productsources.rb', line 1131

def HandleSelectedSources
  StoreSelectedInDialog()
  @repos_to_be_used = deep_copy(@already_selected_in_dialog)

  # FIXME: handle no repositories selected (warning)

  # FIXME: a lot of repositories selected (warning)

  true
end

#InitializeSourcesObject


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
# File 'src/clients/inst_productsources.rb', line 381

def InitializeSources
  #	if (Mode::installation()) {
  #	    y2milestone ("Sources already initialized");
  #	    return true;
  #	}

  Builtins.y2milestone("Initializing...")
  return false if !PackageLock.Check

  Pkg.TargetInitialize(Installation.destdir)
  # the fastest way
  Pkg.SourceRestore

  if !Mode.installation
    # repos_already_used
    Builtins.foreach(Pkg.SourceGetCurrent(true)) do |one_id|
      source_data = Pkg.SourceGeneralData(one_id)
      if Ops.greater_or_equal(
        IsAddOnAlreadySelected(
          Ops.get_string(source_data, "url", ""),
          Ops.get_string(source_data, "product_dir", "")
        ),
        -1
      )
        AddOnProduct.add_on_products = Builtins.add(
          AddOnProduct.add_on_products,
          "media"            => one_id,
          "media_url"        => Ops.get_string(source_data, "url", ""),
          "product_dir"      => Ops.get_string(
            source_data,
            "product_dir",
            ""
          ),
          "product"          => "",
          "autoyast_product" => ""
        )
      end
    end
  end

  true
end

#InitProxySettingsObject

See bugzilla #307680 Proxy needs to be read from sysconfig and set by setenv() builtin


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
# File 'src/clients/inst_productsources.rb', line 215

def InitProxySettings
  Builtins.y2milestone("Adjusting proxy settings")

  proxy_items = {
    "http_proxy"  => "HTTP_PROXY",
    "FTP_PROXY"   => "FTP_PROXY",
    "HTTPS_PROXY" => "HTTPS_PROXY",
    "NO_PROXY"    => "NO_PROXY"
  }
  use_proxy = false

  SCR.RegisterAgent(
    path(".current_proxy_settings"),
    term(:ag_ini, term(:SysConfigFile, "/etc/sysconfig/proxy"))
  )

  use_proxy = SCR.Read(path(".sysconfig.proxy.PROXY_ENABLED")) != "no"

  item_value = ""
  Builtins.foreach(proxy_items) do |proxy_item, sysconfig_item|
    item_value = Convert.to_string(
      SCR.Read(Builtins.add(path(".sysconfig.proxy"), sysconfig_item))
    )
    item_value = "" if item_value.nil?
    if use_proxy == true && item_value != ""
      Builtins.y2milestone("Adjusting '%1'='%2'", proxy_item, item_value)
      Builtins.setenv(proxy_item, item_value)
    end
  end

  SCR.UnregisterAgent(path(".current_proxy_settings"))

  nil
end

#InitRepositoriesWidget(filter_string, first_init, _current_item) ⇒ Object

This function fills up the table repositories found on a web servers linked from control file.

Order of appearance:

Running system: sorted by repository name
Inst-Sys:       sorted by "recommended tag", then by name

Preselections:

Running sustem: no repositories are preselected
Inst-Sys:       "recommended" repositories are prelected
                but only for the first time when running this client

See Also:

  • #297628

958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'src/clients/inst_productsources.rb', line 958

def InitRepositoriesWidget(filter_string, first_init, _current_item)
  items = []
  recommended_items = []
  @repos_visible_now = []
  counter = -1

  # used for recommended repos
  some_repo_already_selected = false

  #	boolean current_item_is_listed = false;

  Builtins.foreach(@list_of_repos) do |url, one_repo|
    repo_id = CreateRepoId(
      Ops.get_string(one_repo, "url", ""),
      Ops.get_string(one_repo, "path", "/")
    )
    src_id = IsAddOnAlreadySelected(
      Ops.get_string(one_repo, "url", ""),
      Ops.get_string(one_repo, "path", "/")
    )
    already_used = false
    # repository has been already initialized
    if Ops.greater_than(src_id, -1)
      Ops.set(@repos_already_used, repo_id, src_id)
      already_used = true

      # in some modes, it's required to hide alerady used repos
      if @skip_already_used_repos
        if Builtins.contains(SourceManager.just_removed_sources, src_id)
          Builtins.y2milestone(
            "Not skipping repo %1, known as removed ID %2",
            repo_id,
            src_id
          )
        end

        next
      end
      # repository has been already selected
    elsif IsSelectedInDialog(repo_id)
      already_used = true
    end
    # If this variable is true, no recoomended repos are preselected
    if already_used
      some_repo_already_selected = true
      # List of not-selected repos
    elsif !first_init
      @currently_NOT_selected = Builtins.add(
        @currently_NOT_selected,
        repo_id
      )
    end
    # bugzilla #358001
    # filter works with localized names
    localized_name = GetLocalizedString(repo_id, ["name", "url"])
    # do filter (filter after some_repo_already_selected is set)
    if filter_string != ""
      # neither "url" nor "name" matching
      if !Builtins.regexpmatch(
        Ops.get_string(one_repo, "url", ""),
        filter_string
      ) &&
          !Builtins.regexpmatch(localized_name, filter_string)
        next
      end
    end
    counter = Ops.add(counter, 1)
    if url == ""
      Builtins.y2error("Repository %1 has no 'url'", one_repo)
      next
    end
    # always fill-up this list -- later used for sorting using 'recommended' tag
    # Bugzilla #297628
    recommended = Ops.get_boolean(one_repo, "recommended", false)
    if recommended
      recommended_items = Builtins.add(recommended_items, repo_id)
    end

    Ops.set(items, counter, Item(Id(repo_id), localized_name, already_used))
    Ops.set(@repos_visible_now, counter, repo_id)
  end

  items = Builtins.sort(items) do |one_item_a, one_item_b|
    Ops.less_than(
      Ops.get_string(one_item_a, 1, ""),
      Ops.get_string(one_item_b, 1, "")
    )
  end

  # Preselect the recommended repositories when ne repository has been selected yet
  if @preselect_recommended
    tmp_items = deep_copy(items)
    counter2 = -1
    current_repoid = ""

    Builtins.foreach(tmp_items) do |one_item|
      counter2 = Ops.add(counter2, 1)
      current_repoid = Ops.get_string(one_item, [0, 0], "---")
      # recommended_items contain list of all recommended items (visible on the screen)
      if Builtins.contains(recommended_items, current_repoid)
        Builtins.y2milestone("Preselecting: %1", current_repoid)
        Ops.set(one_item, 2, true)
        Ops.set(items, counter2, one_item)
      end
    end
  end

  # In the initial stage, repos are additionally sorted whether they are recommended or not
  #	if (Stage::initial()) {
  items = Builtins.sort(items) do |one_item_a, one_item_b|
    Ops.greater_than(
      Builtins.contains(
        recommended_items,
        Ops.get_string(one_item_a, [0, 0], "")
      ),
      Builtins.contains(
        recommended_items,
        Ops.get_string(one_item_b, [0, 0], "")
      )
    )
  end
  #	}

  UI.ChangeWidget(Id("addon_repos"), :Items, items)

  # disabled
  #	if (current_item_is_listed) {
  #	    UI::ChangeWidget (`id ("addon_repos"), `CurrentItem, current_item);
  #	} else if (size (items) > 0) {
  #	    UI::ChangeWidget (`id ("addon_repos"), `CurrentItem, items[0,0,0]:"");
  #	}

  PrintRepositoryDescription()

  # Preselect recommended repos only once
  @preselect_recommended = false

  nil
end

#IsAddOnAlreadySelected(s_url, s_path) ⇒ Object

Returns whether this URL/Path is already added as a source -1 == not added 0 or 1 or 2 … or 'n' means 'added as source $id'


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
# File 'src/clients/inst_productsources.rb', line 355

def IsAddOnAlreadySelected(s_url, s_path)
  ret = -1

  s_url = NormalizeURL(s_url)

  Builtins.foreach(AddOnProduct.add_on_products) do |one_add_on|
    Ops.set(
      one_add_on,
      "media_url",
      NormalizeURL(Ops.get_string(one_add_on, "media_url", ""))
    )
    if Ops.get(one_add_on, "media_url") == s_url &&
        Ops.get(one_add_on, "product_dir") == s_path
      ret = Ops.get_integer(one_add_on, "media", -1)
      raise Break
    end
  end

  if Builtins.contains(SourceManager.just_removed_sources, ret)
    Builtins.y2milestone("Just deleted: %1", ret)
    ret = -1
  end

  ret
end

#IsSelectedInDialog(repo_id) ⇒ Object


941
942
943
# File 'src/clients/inst_productsources.rb', line 941

def IsSelectedInDialog(repo_id)
  Builtins.contains(@already_selected_in_dialog, repo_id)
end

#mainObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'src/clients/inst_productsources.rb', line 61

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

  Yast.import "Wizard"
  Yast.import "Sequencer"

  Yast.import "NetworkService"
  Yast.import "Mode"
  Yast.import "Popup"
  Yast.import "Label"
  Yast.import "Installation"
  Yast.import "PackageLock"
  Yast.import "ProductFeatures"
  Yast.import "Directory"
  Yast.import "Progress"
  Yast.import "Stage"
  Yast.import "Report"
  Yast.import "CommandLine"
  Yast.import "PackageCallbacks"
  Yast.import "SourceManager"

  Yast.import "FileUtils"
  Yast.import "HTTP"
  Yast.import "FTP"
  Yast.import "XML"
  Yast.import "ProductControl"
  Yast.import "AddOnProduct"
  Yast.import "GetInstArgs"
  Yast.import "OneClickInstallStandard"
  Yast.import "Language"
  Yast.import "String"
  Yast.import "URL"

  Yast.include self, "installation/misc.rb"

  if AddOnProduct.skip_add_ons
    Builtins.y2milestone("Skipping module (as requested before)")
    return :auto
  end

  if GetInstArgs.going_back
    Builtins.y2milestone("Going back...")
    return :back
  end

  @args = WFM.Args
  Builtins.y2milestone("Script args: %1", @args)

  # similar to commandline mode but actually it's called from another YaST script
  @script_noncmdline_args = {}

  if Ops.is_map?(Ops.get_map(@args, 0, {}))
    @script_noncmdline_args = Ops.get_map(@args, 0, {})
  end

  if Mode.normal && Ops.greater_than(Builtins.size(@args), 0) &&
      Builtins.size(@script_noncmdline_args).zero?
    CommandLine.Run("id" => "inst_productsources")
    return :auto
  end

  # (Applicable only in inst-sys)
  @preselect_recommended = true

  @skip_already_used_repos = false

  @script_called_from_another = false

  if Ops.get(@script_noncmdline_args, "skip_already_used_repos") == true
    Builtins.y2milestone("Already used repos will be hidden")
    @skip_already_used_repos = true
    @script_called_from_another = true
  end

  # useful when do not want to skip already used repos, but need to call it from another client
  if @script_noncmdline_args["script_called_from_another"]
    @script_called_from_another = true
  end

  @main_link = ""

  @list_of_repos = {}

  @list_of_servers = []

  # List of IDs of URLs to be added
  @repos_to_be_used = []

  @language_long = ""
  @language_short = ""

  # Map of already used suggested repositories
  # $[ "($url|$path)" : src_id ]
  @repos_already_used = {}

  @repos_visible_now = []

  @already_selected_in_dialog = []

  # visible but not selected items
  # used for filter together with recommended repos
  # not to select them 'again' when filter matches
  @currently_NOT_selected = []

  @casesenschars = "^[abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ]$"

  # *********************
  Wizard.CreateDialog if Mode.normal

  @client_ret = RunMain()

  Wizard.CloseDialog if Mode.normal
  # *********************

  @client_ret
end

#MakeCaseInsensitiveRegexp(input) ⇒ Object

Example: <- “aBc/iop” -> “[Aa][Cc]/[Oo]


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
# File 'src/clients/inst_productsources.rb', line 1168

def MakeCaseInsensitiveRegexp(input)
  return input if input.nil? || input == ""

  characters = []
  counter = 0
  input_size = Builtins.size(input)

  while Ops.less_than(counter, input_size)
    Ops.set(characters, counter, Builtins.substring(input, counter, 1))
    counter = Ops.add(counter, 1)
  end
  input = ""

  Builtins.foreach(characters) do |onechar|
    if Builtins.regexpmatch(onechar, @casesenschars)
      onechar = Builtins.sformat(
        "[%1%2]",
        Builtins.toupper(onechar),
        Builtins.tolower(onechar)
      )
    end
    input = Ops.add(input, onechar)
  end

  input
end

#NetworkRunningObject


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
# File 'src/clients/inst_productsources.rb', line 282

def NetworkRunning
  ret = false

  # bnc #327519
  if Mode.normal
    if !NetworkService.isNetworkRunning
      Builtins.y2warning("No network is running...")
      return false
    end
  end

  loop do
    if NetworkService.isNetworkRunning
      ret = true
      break
    end

    # Network is not running
    if !Popup.AnyQuestion(
      # TRANSLATORS: popup header
      _("Network is not configured."),
      # TRANSLATORS: popup question
      _(
        "Online sources defined by product require an Internet connection.\n" \
          "\n" \
          "Would you like to configure it?"
      ),
      Label.YesButton,
      Label.NoButton,
      :yes
    )
      Builtins.y2milestone("User decided not to setup the network")
      ret = false
      break
    end

    Builtins.y2milestone("User wants to setup the network")
    # Call InstLan client
    netret = WFM.call(
      "inst_lan",
      [GetInstArgs.argmap.merge("skip_detection" => true)]
    )

    if netret == :abort
      Builtins.y2milestone("Aborting the network setup")
      break
    end
  end

  ret
end

#NormalizeURL(url_string) ⇒ Object

Removes slashes from the end of the URL (or just string). Needed to fix bug #329629.


336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'src/clients/inst_productsources.rb', line 336

def NormalizeURL(url_string)
  return url_string if url_string.nil? || url_string == ""

  if Builtins.regexpmatch(url_string, "/+$")
    url_string = Builtins.regexpsub(url_string, "(.*)/+$", "\\1")
  end

  # URL is escaped
  if Builtins.regexpmatch(url_string, "%")
    # unescape it
    url_string = URL.UnEscapeString(url_string, URL.transform_map_filename)
  end

  url_string
end

#ParseListOfServers(download_file) ⇒ Object


497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'src/clients/inst_productsources.rb', line 497

def ParseListOfServers(download_file)
  if !FileUtils.Exists(download_file)
    Builtins.y2error("File %1 does not exist", download_file)
    return false
  end

  xml_file_content = XML.XMLToYCPFile(download_file)

  if xml_file_content.nil?
    Builtins.y2error("Reading file %1 failed", download_file)
    return false
  end

  if xml_file_content == {}
    Builtins.y2milestone("XML file is empty")
    return false
  end

  if Ops.get_list(xml_file_content, "servers", []) == []
    Builtins.y2milestone("List of servers is empty")
    return false
  end

  @list_of_servers = Ops.get_list(xml_file_content, "servers", [])

  # bugzilla #293811
  # only installation_repo (trusted) links are used during installation
  @list_of_servers = Builtins.filter(@list_of_servers) do |one_server|
    next true if Ops.get_boolean(one_server, "installation_repo", false)

    Builtins.y2milestone(
      "Sever %1 is not used during installation...",
      one_server
    )
    false
  end if Stage.initial

  true
end

#ParseListOfSources(download_file, url_from) ⇒ Object


537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'src/clients/inst_productsources.rb', line 537

def ParseListOfSources(download_file, url_from)
  if !FileUtils.Exists(download_file)
    Builtins.y2error("File %1 does not exist", download_file)
    return false
  end

  xml_file_content = OneClickInstallStandard.GetRepositoriesFromXML(
    download_file
  )

  if xml_file_content.nil?
    Builtins.y2error("Parsing file %1 failed", download_file)
    return false
  end

  if xml_file_content == []
    Builtins.y2milestone("XML file is empty")
    return false
  end

  Builtins.foreach(xml_file_content) do |one_repo|
    Ops.set(one_repo, "url_from", url_from)
    repo_id = CreateRepoId(
      Ops.get_string(one_repo, "url", ""),
      Ops.get_string(one_repo, "path", "/")
    )
    # do not redefine already added one
    if !Builtins.haskey(@list_of_repos, repo_id)
      Ops.set(@list_of_repos, repo_id, one_repo)
    end
  end

  true
end

#PrintRepositoryDescriptionObject


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
# File 'src/clients/inst_productsources.rb', line 883

def PrintRepositoryDescription
  current_id = Convert.to_string(
    UI.QueryWidget(Id("addon_repos"), :CurrentItem)
  )

  # Nothing selected, no description
  if current_id.nil? || current_id == ""
    UI.ChangeWidget(Id("addon_description"), :Value, "")
    return
  end

  recommended = if Ops.get_boolean(
    @list_of_repos,
    [current_id, "recommended"],
    false
  )
    Builtins.sformat(
      # TRANSLATORS: HTML-formatted summary text
      # %1 is replaced with "Yes" (currently only "Yes")
      # see *4
      _("<b>Recommended:</b> %1<br>"),
      # TRANSLATORS: used for "Recommended: Yes" (see *4)
      _("Yes")
    )
  else
    ""
  end

  description = Builtins.sformat(
    # TRANSLATORS: This is a complex HTML-formatted information about
    # selected external repository
    # It contains "key: value" pair, one per line, separated by <br> tags
    # %1 is replaced with an URL of the selected repository
    # %2 is replaced with an URL from which we've got this repository information
    # %3 is replaced with a summary text for the selected repository
    # %4 is replaced with a description text for the selected repository
    # %5 is replaced with an emty string or "Recommended: Yes" (*4)
    _(
      "<p>\n" \
        "<b>URL:</b> %1<br>\n" \
        "<b>Linked from:</b> %2<br>\n" \
        "<b>Summary:</b> %3<br>\n" \
        "<b>Description:</b> %4<br>\n" \
        "%5\n" \
        "</p>"
    ),
    Ops.get_string(@list_of_repos, [current_id, "url"], ""),
    Ops.get_string(@list_of_repos, [current_id, "url_from"], ""),
    GetLocalizedString(current_id, ["summary", "name"]),
    GetLocalizedString(current_id, ["description"]),
    recommended
  )

  UI.ChangeWidget(Id("addon_description"), :Value, description)

  nil
end

#ReadControlFileObject


424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'src/clients/inst_productsources.rb', line 424

def ReadControlFile
  software_features = ProductFeatures.GetSection("software")
  if !software_features.nil?
    @main_link = Ops.get_string(
      software_features,
      "external_sources_link",
      ""
    )
  else
    @main_link = ""
  end
  Builtins.y2milestone("Got link: %1", @main_link)

  if @main_link.nil? || @main_link == ""
    @main_link = ""
    Builtins.y2warning("No link")
    return false
  end

  Builtins.y2milestone("Using link: %1", @main_link)

  !@main_link.nil? && @main_link != ""
end

#ReadDialogObject


628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'src/clients/inst_productsources.rb', line 628

def ReadDialog
  actions_todo =
    # TRANSLATORS: progress step
    [
      # TRANSLATORS: progress step
      _("Check network configuration"),
      # TRANSLATORS: progress step
      _("Download list of online repositories")
    ]

  actions_doing = [
    # TRANSLATORS: progress step
    _("Checking network configuration..."),
    # TRANSLATORS: progress step
    _("Downloading list of online repositories...")
  ]

  icons_for_progress = ["yast-network.png", "yast-restore.png"]

  if !Stage.initial
    # TRANSLATORS: progress step
    actions_todo = Builtins.add(
      actions_todo,
      _("Initialize the repository manager")
    )
    # TRANSLATORS: progress step
    actions_doing = Builtins.add(
      actions_doing,
      _("Initializing the repository manager...")
    )
    icons_for_progress = Builtins.add(
      icons_for_progress,
      "yast-sw_source.png"
    )
  end

  Progress.NewProgressIcons(
    # TRANSLATORS: dialog caption
    _("Reading List of Online Repositories"),
    " ",
    Builtins.size(actions_todo),
    actions_todo,
    actions_doing,
    # TRANSLATORS: dialog help
    _(
      "<p>The packager is being initialized and \n" \
        "the list of servers downloaded from the Web.</p>\n"
    ),
    [icons_for_progress]
  )
  Wizard.SetTitleIcon("yast-network")

  Progress.NextStage

  return :abort if UserWantsToAbort()

  # Bugzilla #305554
  # Check if there is enough memory (only in inst-sys)
  # Called via WFM::call because of breaking RPM dependencies
  # on yast2-add-on package.
  if Stage.initial
    client_ret = WFM.call("inst_check_memsize")

    if client_ret == :skip
      # do not use them next time
      Installation.add_on_selected = false
      Installation.productsources_selected = false
      Builtins.y2milestone("Skipping inst_productsources")

      return :skip
    end
  end

  if !NetworkRunning()
    Builtins.y2warning("Cannot proceed, no network configured...")
    # TRANSLATORS: error report
    Report.Error(
      _("Cannot download list of repositories,\nno network configured.")
    )

    return :nosources
  end

  return :abort if UserWantsToAbort()

  # In the installation, recommended repositories will be preselected
  if Stage.initial
    # Set preselect_recommended to the correct state
    filename = Builtins.sformat(
      "%1/productsources_already_called",
      Directory.tmpdir
    )

    # Client must have been already called
    if FileUtils.Exists(filename)
      @preselect_recommended = false
      # Really for the very first time
    else
      @preselect_recommended = true
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat("touch '%1'", String.Quote(filename))
      )
      Builtins.y2milestone("Running for the first time...")
    end
    # ...but never on the running system
  else
    @preselect_recommended = false
  end

  Progress.NextStage

  return :abort if UserWantsToAbort()

  # hotfix for bug #307680
  # yast2-transfer ignores proxy settings
  # will be fixed globally after 10.3
  InitProxySettings() if Mode.normal

  return :abort if UserWantsToAbort()

  # language used for possible translations
  @language_long = GetCurrentLang() if !Stage.initial

  # fallback if no LANG variable set
  if @language_long.nil? || @language_long == ""
    @language_long = Language.language
  end

  # de_DE.UTF-8 --> de_DE
  dot_pos = Builtins.search(@language_long, ".")
  if !dot_pos.nil?
    @language_long = Builtins.substring(@language_long, 0, dot_pos)
  end

  if !@language_long.nil?
    @language_short = if Ops.greater_or_equal(Builtins.size(@language_long), 2)
      Builtins.substring(@language_long, 0, 2)
    else
      @language_long
    end
  end

  Builtins.y2milestone(
    "Preferred language: %1 %2",
    @language_long,
    @language_short
  )

  return :abort if UserWantsToAbort()

  if !ReadControlFile()
    Builtins.y2milestone("Feature not supported by the product")
    # TRANSLATORS: light-warning message
    Report.Message(
      _(
        "No product URL defined from which to download\nlist of repositories.\n"
      )
    )

    return :nosources
  end

  return :abort if UserWantsToAbort()

  if !DownloadAndParseSources()
    Builtins.y2error("Cannot download or parse repositories")
    # TRANSLATORS: warning message
    Report.Warning(
      _(
        "Unable to download list of repositories\nor no repositories defined."
      )
    )

    return :nosources
  end

  return :abort if UserWantsToAbort()

  if !Stage.initial
    Progress.NextStage
    InitializeSources()
  end

  return :abort if UserWantsToAbort()

  Progress.Finish
  Builtins.sleep(600)

  :next
end

#RemoveFileIfExists(file) ⇒ Object


452
453
454
455
456
457
458
459
# File 'src/clients/inst_productsources.rb', line 452

def RemoveFileIfExists(file)
  if FileUtils.Exists(file)
    Builtins.y2milestone("Removing file: %1", file)
    return Convert.to_boolean(SCR.Execute(path(".target.remove"), file))
  end

  true
end

#RunMainObject


1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
# File 'src/clients/inst_productsources.rb', line 1674

def RunMain
  aliases = {
    "read"    => -> { ReadDialog() },
    "sources" => -> { SourcesDialog() },
    "write"   => -> { WriteDialog() }
  }

  sequence = {
    "ws_start" => "read",
    "read"     => {
      next:      "sources",
      # not enough memory
      skip:      :next,
      nosources: :next,
      abort:     :abort
    },
    "sources"  => {
      special_go_back: :back,
      next:            "write",
      abort:           :abort
    },
    "write"    => { next: :next, abort: :abort }
  }

  ret = Sequencer.Run(aliases, sequence)
  Builtins.y2milestone("Sequencer::Run %1", ret)

  Convert.to_symbol(ret)
end

#SourcesDialogObject


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
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
# File 'src/clients/inst_productsources.rb', line 1215

def SourcesDialog
  Wizard.SetContents(
    # TRANSLATORS: dialog caption
    _("List of Online Repositories"),
    VBox(
      HBox(
        HVSquash(
          MinWidth(20, InputField(Id("filter_text"), Opt(:hstretch), ""))
        ),
        # TRANSLATORS: push button
        Bottom(PushButton(Id("do_filter"), Opt(:default), _("&Filter"))),
        HStretch()
      ),
      VSpacing(0.5),
      VWeight(
        2,
        MultiSelectionBox(
          Id("addon_repos"),
          Opt(:notify, :hstretch),
          # TRANSLATORS: multi-selection box
          _("&List of Repositories"),
          []
        )
      ),
      VSpacing(0.5),
      # TRANSLATORS: Rich-text widget (HTML)
      Left(Label(_("Repository Description"))),
      VWeight(1, RichText(Id("addon_description"), ""))
    ),
    # TRANSLATORS: dialog help 1/3
    _(
      "<p>List of default online repositories.\nClick on a repository for details.</p>\n"
    ) +
      (
        if Stage.initial
          # TRANSLATORS: dialog help 2/3 (version for installation)
          _(
            "<p>Select the online repositories you want to use then click <b>Next</b>.</p>\n"
          )
        else
          # TRANSLATORS: dialog help 2/3 (version for running system)
          _(
            "<p>Select the online repositories you want to use then click <b>Finish</b>.</p>\n"
          )
        end
      ) +
      # TRANSLATORS: dialog help 3/3
      (
        if @skip_already_used_repos
          ""
        else
          _("<p>To remove a used repository, simply deselect it.</p>")
        end
      ),
    Mode.installation ? GetInstArgs.enable_back : false,
    Mode.installation ? GetInstArgs.enable_next : true
  )
  Wizard.SetTitleIcon("yast-sw_source")

  if !Stage.initial
    Wizard.DisableBackButton

    if @script_called_from_another
      Wizard.SetAbortButton(:cancel, Label.CancelButton)
      Wizard.SetNextButton(:next, Label.OKButton)
    else
      Wizard.SetNextButton(:next, Label.FinishButton)
    end
  else
    # Next button must be always enabled
    # bnc #392111
    Wizard.RestoreNextButton
    Wizard.EnableNextButton
    Wizard.DisableBackButton

    # from add-ons
    if @script_called_from_another
      Wizard.SetAbortButton(:cancel, Label.CancelButton)
    else
      Wizard.RestoreAbortButton
    end
  end

  @repos_already_used = {}
  InitRepositoriesWidget("", true, nil)

  dialog_ret = nil

  # warn if there is low memory
  check_memory_size

  loop do
    dialog_ret = UI.UserInput

    case dialog_ret
    when :back
      Builtins.y2milestone("Going back")
      dialog_ret = :special_go_back
      break
    when :next
      HandleSelectedSources() ? break : next
    when :abort, :cancel
      dialog_ret = :abort
      if Stage.initial
        # from add-ons
        if @script_called_from_another
          Builtins.y2milestone("Back to add-ons")
          break
          # from workflow
        elsif Popup.ConfirmAbort(:painless)
          break
        end
      elsif @script_called_from_another
        break
      elsif Popup.ContinueCancelHeadline(
        # TRANSLATORS: popup header
        _("Aborting Configuration of Online Repository"),
        # TRANSLATORS: popup question
        _("Are you sure you want to abort the configuration?")
      )
        break
      end
    when "addon_repos"
      PrintRepositoryDescription()
    when "do_filter"
      HandleFilterButton()
    else
      Builtins.y2error("Unknown ret: %1", dialog_ret)
    end
  end

  Wizard.EnableBackButton
  Wizard.RestoreAbortButton

  Convert.to_symbol(dialog_ret)
end

#StoreSelectedInDialogObject


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
# File 'src/clients/inst_productsources.rb', line 1098

def StoreSelectedInDialog
  # remember already selected items before filtering
  currently_selected = Convert.convert(
    UI.QueryWidget(Id("addon_repos"), :SelectedItems),
    from: "any",
    to:   "list <string>"
  )

  # all visible repos - just now
  Builtins.foreach(@repos_visible_now) do |one_repo|
    # visible repository is not selected
    if !Builtins.contains(currently_selected, one_repo)
      # was already selected
      if Builtins.contains(@already_selected_in_dialog, one_repo)
        @already_selected_in_dialog = Builtins.filter(
          @already_selected_in_dialog
        ) { |o_r| o_r != one_repo }
      end

    # visible repository is selected now
    # wasn't selected
    elsif !Builtins.contains(@already_selected_in_dialog, one_repo)
      # add it
      @already_selected_in_dialog = Builtins.add(
        @already_selected_in_dialog,
        one_repo
      )
    end
  end

  nil
end

#UseDownloadFileObject


448
449
450
# File 'src/clients/inst_productsources.rb', line 448

def UseDownloadFile
  Builtins.sformat("%1/inst_productsources_downloadfile", Directory.tmpdir)
end

#UserWantsToAbortObject

Function returns whether user wants to abort the installation / configuration true - abort false - do not abort

Bugzilla #298049


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
# File 'src/clients/inst_productsources.rb', line 255

def UserWantsToAbort
  ret = UI.PollInput

  return false if ret != :abort

  function_ret = false

  # `abort pressed
  if Stage.initial
    function_ret = Popup.ConfirmAbort(:painless)
  else
    function_ret = Popup.ContinueCancelHeadline(
      # TRANSLATORS: popup header
      _("Aborting Configuration of Online Repository"),
      # TRANSLATORS: popup question
      _("Are you sure you want to abort the configuration?")
    )
  end

  Builtins.y2milestone("User decided to abort: %1", function_ret)

  # Clean-up the progress
  Progress.Finish if function_ret == true

  function_ret
end

#WriteDialogObject


1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
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
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
# File 'src/clients/inst_productsources.rb', line 1525

def WriteDialog
  actions_todo = []
  actions_doing = []
  at_once = false

  repos_to_be_deleted = []

  # repos_to_be_used
  # repos_already_used

  # y2milestone ("ToBeDeleted: %1", repos_to_be_deleted);
  # y2milestone ("ReposAlreadyUsed: %1", repos_already_used);
  # y2milestone ("ReposToBeUsed: %1", repos_to_be_used);

  # go through all already initialized repositories
  # add unselected repository to 'repos_to_be_deleted'
  # remove already selected repository from 'repos_to_be_used'

  # Currently, Mode::normal doesn't show already used repos
  # (when 'skip_already_used_repos' is 'true')
  # and thus doesn't support removing them
  Builtins.foreach(@repos_already_used) do |id_used, src_id|
    # was used, but isn't anymore
    if !Builtins.contains(@repos_to_be_used, id_used)
      repos_to_be_deleted = Builtins.add(repos_to_be_deleted, src_id)

      # was used and remains used
    else
      Builtins.y2milestone("NotUsingAgain: %1", id_used)
      @repos_to_be_used = Builtins.filter(@repos_to_be_used) do |id_already_used|
        id_used != id_already_used
      end
    end
  end if @skip_already_used_repos != true

  # y2milestone ("WillBeDeleted: %1", repos_to_be_deleted);
  # y2milestone ("WillBeUsed: %1", repos_to_be_used);

  if repos_to_be_deleted != []
    Builtins.y2milestone("Repos to be deleted: %1", repos_to_be_deleted)

    # TRANSLATORS: progress step
    actions_todo = [_("Delete deselected online repositories")]
    # TRANSLATORS: progress step
    actions_doing = [_("Deleting deselected online repositories...")]
  end

  if Ops.greater_than(Builtins.size(@repos_to_be_used), 12)
    at_once = true
    # TRANSLATORS: progress step
    actions_todo = Builtins.add(
      actions_todo,
      _("Add all selected online repositories")
    )
    # TRANSLATORS: progress step
    actions_doing = Builtins.add(
      actions_doing,
      _("Adding all selected online repositories...")
    )
  else
    Builtins.foreach(@repos_to_be_used) do |repo_id|
      actions_todo = Builtins.add(
        actions_todo,
        Builtins.sformat(
          # TRANSLATORS: progress step
          # %1 is replaced with repository name or URL
          _("Add repository: %1"),
          GetLocalizedString(repo_id, ["name", "url"])
        )
      )
      actions_doing = Builtins.add(
        actions_doing,
        Builtins.sformat(
          # TRANSLATORS: progress step,
          # %1 is replaced with repository name or URL
          _("Adding repository: %1 ..."),
          GetLocalizedString(repo_id, ["name", "url"])
        )
      )
    end
  end

  if Builtins.size(actions_todo).zero?
    Builtins.y2milestone("Nothing to do...")
    return :next
  end

  # Create writing dialog - initial state
  actions_todo_ref = arg_ref(actions_todo)
  CreateAndAdjustWriteProgress(actions_todo_ref, actions_doing)
  actions_todo = actions_todo_ref.value

  return :abort if UserWantsToAbort()

  if repos_to_be_deleted != []
    Progress.NextStage
    Builtins.foreach(repos_to_be_deleted) do |src_id|
      success = Pkg.SourceDelete(src_id)
      Builtins.y2error("Couldn't delete repository %1", src_id) if !success
      AddOnProduct.Disintegrate(src_id)
      # filter it also from the list of Add-Ons
      AddOnProduct.add_on_products = Builtins.filter(
        AddOnProduct.add_on_products
      ) do |one_addon|
        Ops.get_integer(one_addon, "media", -1) != src_id
      end
    end
  end

  return :abort if UserWantsToAbort()

  # One progress stage for all repositories
  Progress.NextStage if at_once

  Builtins.foreach(@repos_to_be_used) do |repo_id|
    # If not at once, call one stage per repository
    Progress.NextStage if !at_once
    next :abort if UserWantsToAbort()
    actions_todo_ref = arg_ref(actions_todo)
    actions_doing_ref = arg_ref(actions_doing)
    CreateSource(
      Ops.get_string(@list_of_repos, [repo_id, "url"], ""),
      Ops.get_string(@list_of_repos, [repo_id, "path"], "/"),
      GetLocalizedString(repo_id, ["name"]),
      actions_todo_ref,
      actions_doing_ref,
      at_once
    )
    actions_todo = actions_todo_ref.value
    actions_doing = actions_doing_ref.value
  end

  return :abort if UserWantsToAbort()

  # Redraw installation wizard
  if Stage.initial
    UpdateWizardSteps()
    # Store repositories
  else
    Pkg.SourceSaveAll
  end

  Progress.Finish

  Builtins.sleep(1000) if !Stage.initial

  :next
end