Class: Yast::RepositoriesClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/lib/packager/clients/repositories.rb

Overview

Interface for repository management

Constant Summary collapse

NO_SERVICE =
:no_service
NO_SERVICE_ITEM =
:no_service_item

Instance Method Summary collapse

Constructor Details

#initializeRepositoriesClient

Returns a new instance of RepositoriesClient


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'src/lib/packager/clients/repositories.rb', line 55

def initialize
  textdomain "packager"

  @full_mode = false

  # cache for textmode value
  @text_mode = nil

  @sourcesToDelete = []
  @reposFromDeletedServices = []

  # default (minimal) priority of a repository
  @default_priority = 99

  @priority_label = _("&Priority")

  @keeppackages_label = _("Keep Downloaded Packages")

  # current view:
  # selected service (or empty) if all services are selected
  @displayed_service = ""
  # service/repository view flag
  @repository_view = true

  # remember the original selected URL scheme
  @selected_url_scheme = ""

  @cmdline_description = {
    "id"         => "inst_source",
    # Command line help text for the repository module, %1 is "zypper"
    "help"       => Builtins.sformat(
      _(
        "Installation Repositories - This module does not support the command line " \
          "interface, use '%1' instead."
      ),
      "zypper"
    ),
    "guihandler" => fun_ref(method(:StartInstSource), "symbol ()")
  }

  # list of repositories that was already informed to the user that they are
  # managed by service
  @services_repos = []
end

Instance Method Details

#buildListObject


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
# File 'src/lib/packager/clients/repositories.rb', line 657

def buildList
  ret = [
    Item(Id(:all_repositories), _("All repositories"), @repository_view),
    Item(
      Id(:all_services),
      _("All services"),
      !@repository_view && @displayed_service == ""
    )
  ]

  Builtins.foreach(@serviceStatesOut) do |srv_state|
    t = Item(
      Id(Ops.get_string(srv_state, "alias", "")),
      Builtins.sformat(
        _("Service '%1'"),
        Ops.get_string(srv_state, "name", "")
      ),
      @repository_view &&
        @displayed_service == Ops.get_string(srv_state, "alias", "")
    )
    ret = Builtins.add(ret, t)
  end

  # there is some service, so allow to filter repos without service (bnc#944504)
  if ret.size > 2
    t = Item(
      Id(NO_SERVICE_ITEM),
      # TRANSLATORS: Item in selection box that allow user to see only
      # repositories not associated with service. Sometimes called also
      # third party as they are usually repositories not provided by SUSE
      # within product subscription.
      _("Only repositories not provided by a service"),
      @repository_view &&
        @displayed_service == NO_SERVICE
    )
    ret = Builtins.add(ret, t)
  end

  ret
end

#clearRepoInfoObject


449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'src/lib/packager/clients/repositories.rb', line 449

def clearRepoInfo
  if textmode
    UI.ChangeWidget(Id(:name), :Label, "")
    UI.ChangeWidget(Id(:url), :Label, "")
    UI.ChangeWidget(Id(:category), :Label, "")
  else
    UI.ChangeWidget(Id(:repo_info), :Value, "")
  end

  UI.ChangeWidget(Id(:enable), :Value, false)
  UI.ChangeWidget(Id(:autorefresh), :Value, false)

  if UI.WidgetExists(Id(:priority))
    # priority is displayed only for repositories
    UI.ChangeWidget(Id(:priority), :Value, @default_priority)
  end

  nil
end

#createItem(index, source, repository_mode) ⇒ Object

Create a table item from a map as returned by the InstSrcManager agent.

@param [Hash] source The map describing the source as returned form the agent.
@return An item suitable for addition to a Table.

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'src/lib/packager/clients/repositories.rb', line 195

def createItem(index, source, repository_mode)
  source = deep_copy(source)
  id = Ops.get_integer(source, "SrcId", 0)
  generalData = Pkg.SourceGeneralData(id)
  Builtins.y2milestone("generalData(%1): %2", id, generalData)

  name = if repository_mode
    if Builtins.haskey(source, "name")
      Ops.get_string(source, "name", "")
    else
      Ops.get_locale(
        # unkown name (alias) of the source
        generalData,
        "alias",
        Ops.get_locale(generalData, "type", _("Unknown Name"))
      )
    end
  else
    Ops.get_string(source, "name", "")
  end

  priority = Ops.get_integer(source, "priority", @default_priority)
  url = if repository_mode
    Ops.get_string(generalData, "url", "")
  else
    Ops.get_string(source, "url", "")
  end
  if ![nil, "", "/"].include?(generalData["product_dir"])
    url += " (#{generalData["product_dir"]})"
  end
  service_alias = Ops.get_string(source, "service", "")
  service_name = if service_alias != ""
    Ops.get_string(Pkg.ServiceGet(service_alias), "name", "")
  else
    ""
  end

  item = if repository_mode
    Item(
      Id(index),
      PriorityToString(priority),
      if Ops.get_boolean(
        # corresponds to the "Enable/Disable" button
        source,
        "enabled",
        true
      )
        UI.Glyph(:CheckMark)
      else
        ""
      end,
      Ops.get_boolean(source, "autorefresh", true) ? UI.Glyph(:CheckMark) : "",
      # translators: unknown name for a given source
      name,
      service_name,
      url
    )
  else
    Item(
      Id(index),
      if Ops.get_boolean(
        # corresponds to the "Enable/Disable" button
        source,
        "enabled",
        true
      )
        UI.Glyph(:CheckMark)
      else
        ""
      end,
      Ops.get_boolean(source, "autorefresh", true) ? UI.Glyph(:CheckMark) : "",
      # translators: unknown name for a given source
      name,
      url
    )
  end

  deep_copy(item)
end

#deleteService(index) ⇒ Object


562
563
564
565
566
567
# File 'src/lib/packager/clients/repositories.rb', line 562

def deleteService(index)
  Builtins.y2milestone("Removing service: %1", index)
  @serviceStatesOut = Builtins.remove(@serviceStatesOut, index)

  nil
end

#deleteSource(index) ⇒ Object


546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'src/lib/packager/clients/repositories.rb', line 546

def deleteSource(index)
  srcid = Ops.get_integer(@sourceStatesOut, [index, "SrcId"], -1)

  if srcid != -1
    @sourcesToDelete = Builtins.add(@sourcesToDelete, srcid)
    SourceManager.just_removed_sources = Builtins.add(
      SourceManager.just_removed_sources,
      srcid
    )
  end

  @sourceStatesOut = Builtins.remove(@sourceStatesOut, index)

  nil
end

#fillCurrentRepoInfoObject


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
# File 'src/lib/packager/clients/repositories.rb', line 469

def fillCurrentRepoInfo
  selected = Convert.to_integer(UI.QueryWidget(Id(:table), :CurrentItem))
  if selected.nil?
    clearRepoInfo
    return
  end

  data = if @repository_view
    if @displayed_service == ""
      Ops.get(@sourceStatesOut, selected, {})
    else
      Ops.get(
        ReposFromService(@displayed_service, @sourceStatesOut),
        selected,
        {}
      )
    end
  else
    Ops.get(@serviceStatesOut, selected, {})
  end

  fillRepoInfo(selected, data, @repository_view, @displayed_service)

  nil
end

#fillRepoInfo(index, source, repo_mode, _service_name) ⇒ Object


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
# File 'src/lib/packager/clients/repositories.rb', line 384

def fillRepoInfo(index, source, repo_mode, _service_name)
  source = deep_copy(source)
  info = repo_mode ? getSourceInfo(index, source) : deep_copy(source)
  if repo_mode
    Builtins.y2milestone("getSourceInfo(%1, %2): %3", index, source, info)
  end

  # heading - in case repo name not found
  name = Ops.get_locale(info, "name", _("Unknown Repository Name"))

  # label to be used instead of URL if not found
  url = Builtins.sformat(
    _("URL: %1"),
    Ops.get_locale(info, "url", _("Unknown"))
  )

  # label, %1 is repo category (eg. YUM)
  category = Builtins.sformat(
    _("Category: %1"),
    Ops.get_locale(info, "type", _("Unknown"))
  )

  # don't display category for services
  category = "" if !repo_mode

  if textmode
    UI.ChangeWidget(Id(:name), :Label, name)
    UI.ChangeWidget(Id(:url), :Label, url)
    UI.ChangeWidget(Id(:category), :Label, category)
  else
    UI.ChangeWidget(
      Id(:repo_info),
      :Value,
      repoInfoRichText(name, category, info)
    )
  end

  UI.ChangeWidget(
    Id(:enable),
    :Value,
    Ops.get_boolean(info, "enabled", true)
  )
  UI.ChangeWidget(
    Id(:autorefresh),
    :Value,
    Ops.get_boolean(info, "autorefresh", true)
  )

  if repo_mode
    # priority and keeppackages are displayed only for repositories
    UI.ChangeWidget(
      Id(:priority),
      :Value,
      Ops.get_integer(info, "priority", @default_priority)
    )
    UI.ChangeWidget(
      Id(:keeppackages),
      :Value,
      Ops.get_boolean(info, "keeppackages", false)
    )
  end

  nil
end

#fillTable(repo_mode, service_name) ⇒ Object

Fill sources table with entries from the InstSrcManager agent.


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
# File 'src/lib/packager/clients/repositories.rb', line 298

def fillTable(repo_mode, service_name)
  Builtins.y2milestone(
    "Filling repository table: repository mode: %1, service: %2",
    repo_mode,
    service_name
  )
  items = []

  if repo_mode
    # because Online Repositories / Community Repositories don't use
    # these internal data maps
    RemoveDeletedAddNewRepos()
  end

  itemList = repo_mode ? deep_copy(@sourceStatesOut) : deep_copy(@serviceStatesOut)

  # displaye only repositories from the selected service
  if repo_mode && service_name != ""
    itemList = ReposFromService(service_name, itemList)
  end

  numItems = Builtins.size(itemList)

  i = 0
  while Ops.less_than(i, numItems)
    items = Builtins.add(
      items,
      createItem(i, Ops.get(itemList, i, {}), repo_mode)
    )
    i = Ops.add(i, 1)
  end

  Builtins.y2milestone("New table content: %1", items)

  UI.ChangeWidget(Id(:table), :Items, items)

  nil
end

#getSourceInfo(_index, source) ⇒ Object


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'src/lib/packager/clients/repositories.rb', line 275

def getSourceInfo(_index, source)
  source = deep_copy(source)
  id = Ops.get_integer(source, "SrcId", 0)
  generalData = Pkg.SourceGeneralData(id)
  Builtins.y2milestone("generalData(%1): %2", id, generalData)

  # get the editable propertis from 'source' parameter,
  # get the fixed propertis from the package manager
  out = {
    "enabled"      => Ops.get_boolean(source, "enabled", true),
    "autorefresh"  => Ops.get_boolean(source, "autorefresh", true),
    "name"         => Ops.get_locale(source, "name", _("Unknown Name")),
    "url"          => Ops.get_string(generalData, "url", ""),
    "raw_url"      => Ops.get_string(generalData, "raw_url", ""),
    "type"         => Ops.get_string(generalData, "type", ""),
    "priority"     => Ops.get_integer(source, "priority", @default_priority),
    "service"      => Ops.get_string(source, "service", ""),
    "keeppackages" => Ops.get_boolean(source, "keeppackages", false)
  }
  deep_copy(out)
end

#import_modulesObject


46
47
48
49
50
51
52
53
# File 'src/lib/packager/clients/repositories.rb', line 46

def import_modules
  Yast.import "Pkg"
  Yast.import "UI"

  Yast.include self, "packager/inst_source_dialogs.rb"
  Yast.include self, "packager/key_manager_dialogs.rb"
  Yast.include self, "packager/repositories_include.rb"
end

#mainObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'src/lib/packager/clients/repositories.rb', line 46

def main
  textdomain "packager"

  Yast.include self, "packager/inst_source_dialogs.rb"
  Yast.include self, "packager/key_manager_dialogs.rb"
  Yast.include self, "packager/repositories_include.rb"

  @full_mode = false

  # cache for textmode value
  @text_mode = nil

  @sourcesToDelete = []
  @reposFromDeletedServices = []

  # default (minimal) priority of a repository
  @default_priority = 99

  @priority_label = _("&Priority")

  @keeppackages_label = _("Keep Downloaded Packages")

  # current view:
  # selected service (or empty) if all services are selected
  @displayed_service = ""
  # service/repository view flag
  @repository_view = true

  # remember the original selected URL scheme
  @selected_url_scheme = ""

  @cmdline_description = {
    "id"         => "inst_source",
    # Command line help text for the repository module, %1 is "zypper"
    "help"       => Builtins.sformat(
      _(
        "Installation Repositories - This module does not support the command line " \
          "interface, use '%1' instead."
      ),
      "zypper"
    ),
    "guihandler" => fun_ref(method(:StartInstSource), "symbol ()")
  }

  if WFM.Args == [:sw_single_mode]
    Builtins.y2milestone("Started from sw_single, switching the mode")

    @full_mode = true
    @ret = StartInstSource()

    # load objects from the new repositories
    Pkg.SourceLoad if @ret != :abort

    return deep_copy(@ret)
  end

  if WFM.Args == ["refresh-enabled"]
    Builtins.y2milestone("Refresh enabled option set")
    return StartInstSource()
  end

  CommandLine.Run(@cmdline_description)
end

#newServices(statesOld, statesNew) ⇒ Object


527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'src/lib/packager/clients/repositories.rb', line 527

def newServices(statesOld, statesNew)
  statesOld = deep_copy(statesOld)
  statesNew = deep_copy(statesNew)
  Builtins.y2milestone("Services from %1 To %2", statesOld, statesNew)
  ret = []

  seen = Builtins.maplist(statesOld) do |srv|
    Ops.get_string(srv, "alias", "")
  end

  Builtins.foreach(statesNew) do |srv|
    alias_name = Ops.get_string(srv, "alias", "")
    Builtins.y2milestone("Checking %1", alias_name)
    ret = Builtins.add(ret, alias_name) if !Builtins.contains(seen, alias_name)
  end
  Builtins.y2milestone("Difference %1", ret)
  deep_copy(ret)
end

#newSources(statesOld, statesNew) ⇒ Object

Find which repositories have to be added or deleted to ZENworks. #182992: formerly we did not consider the enabled attribute. But ZENworks cannot completely disable a repository (unsubscribing a repository merely decreases its priority) so we consider a disabled repository like a deleted one.

Parameters:

  • statesOld (Array<Hash{String => Object>})

    sourceStates - In or Out

  • statesNew (Array<Hash{String => Object>})

    sourceStates - In or Out

Returns:

  • the list of SrcId's that are enabled in statesNew but are not enabled in statesOld


504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'src/lib/packager/clients/repositories.rb', line 504

def newSources(statesOld, statesNew)
  statesOld = deep_copy(statesOld)
  statesNew = deep_copy(statesNew)
  Builtins.y2milestone("From %1 To %2", statesOld, statesNew)
  ret = []
  seen = Builtins.listmap(statesOld) do |src|
    {
      Ops.get_integer(src, "SrcId", -1) => Ops.get_boolean(
        src,
        "enabled",
        true
      )
    }
  end
  Builtins.foreach(statesNew) do |src|
    newid = Ops.get_integer(src, "SrcId", -1)
    newena = Ops.get_boolean(src, "enabled", true)
    ret = Builtins.add(ret, newid) if newena && !Ops.get(seen, newid, false)
  end
  Builtins.y2milestone("Difference %1", ret)
  deep_copy(ret)
end

#plugin_change_msgObject

The message displayed when trying to change a plugin service


2031
2032
2033
2034
# File 'src/lib/packager/clients/repositories.rb', line 2031

def plugin_change_msg
  # TRANSLATORS: An error message
  _("The services of type 'plugin' cannot be changed.")
end

#plugin_service_check(service_alias, msg) ⇒ Boolean

Check whether the service is of type “plugin”, if yes display the message

Parameters:

  • service_alias (String)

    Alias of the service

  • msg (String)

    Error message displayed

Returns:

  • (Boolean)

    true if type of service is not “plugin” or service does not exist, false otherwise

See Also:


2050
2051
2052
2053
2054
2055
2056
2057
2058
# File 'src/lib/packager/clients/repositories.rb', line 2050

def plugin_service_check(service_alias, msg)
  # check whether this is a repo from a plugin based service
  serv_info = Pkg.ServiceGet(service_alias) || {}

  return true if serv_info["type"] != "plugin"

  Popup.Message(msg)
  false
end

#PriorityToString(priority) ⇒ Object


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'src/lib/packager/clients/repositories.rb', line 167

def PriorityToString(priority)
  ret = Builtins.tostring(priority)

  # pad to 3 characters
  rest = Ops.subtract(3, Builtins.size(ret))
  while Ops.greater_than(rest, 0)
    ret = Ops.add(" ", ret)
    rest = Ops.subtract(rest, 1)
  end

  if priority == @default_priority
    ret = Ops.add(Ops.add(Ops.add(ret, " ("), _("Default")), ")")
  end

  ret
end

#RemoveDeletedAddNewReposObject


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
# File 'src/lib/packager/clients/repositories.rb', line 122

def RemoveDeletedAddNewRepos
  ret = []

  current_sources = Pkg.SourceGetCurrent(false)
  known_repos = []
  deleted_repos = []

  # sources deleted during this script run
  Builtins.foreach(@sourceStatesIn) do |one_source|
    src_id = Builtins.tointeger(Ops.get(one_source, "SrcId"))
    deleted_repos = Builtins.add(deleted_repos, src_id) if !src_id.nil?
  end

  # sources is a copy of sourceStatesOut
  Builtins.foreach(@sourceStatesOut) do |one_source|
    src_id = Builtins.tointeger(Ops.get(one_source, "SrcId"))
    if Builtins.contains(current_sources, src_id)
      known_repos = Builtins.add(known_repos, src_id) if !src_id.nil?
      ret = Builtins.add(ret, one_source)
    else
      Builtins.y2milestone("Source %1 has been removed already", one_source)
    end
  end

  Builtins.foreach(current_sources) do |one_srcid|
    # already known repository
    next if Builtins.contains(known_repos, one_srcid)
    # already deleted repository
    next if Builtins.contains(deleted_repos, one_srcid)
    # already deleted repository
    next if Builtins.contains(SourceManager.just_removed_sources, one_srcid)
    # repository has been added recently (by some external functionality
    # that doesn't use these internal variables)
    generalData = Pkg.SourceGeneralData(one_srcid)
    Ops.set(generalData, "enabled", true)
    Ops.set(generalData, "SrcId", one_srcid)
    Builtins.y2milestone("New repository found: %1", generalData)
    ret = Builtins.add(ret, generalData)
  end

  @sourceStatesOut = deep_copy(ret)

  nil
end

#RemoveReposFromService(service_alias) ⇒ Object


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
# File 'src/lib/packager/clients/repositories.rb', line 776

def RemoveReposFromService(service_alias)
  # delete the repositories belonging to the service
  repos = ReposFromService(service_alias, @sourceStatesOut)
  Builtins.y2milestone(
    "Removing repos from service alias=%1: %2",
    service_alias,
    repos
  )

  Builtins.foreach(repos) do |repo|
    srcid = Ops.get_integer(repo, "SrcId", -1)
    if srcid != -1
      @sourcesToDelete = Builtins.add(@sourcesToDelete, srcid)
      SourceManager.just_removed_sources = Builtins.add(
        SourceManager.just_removed_sources,
        srcid
      )
    end
    @sourceStatesOut = Builtins.filter(@sourceStatesOut) do |srcstate|
      if Ops.get_integer(srcstate, "SrcId", -1) == srcid
        Builtins.y2milestone("Removing repository %1", srcstate)
        @reposFromDeletedServices = Builtins.add(
          @reposFromDeletedServices,
          srcid
        )
        next false
      end
      true
    end
  end

  nil
end

#ReplaceWidgets(repo_mode) ⇒ Object


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
# File 'src/lib/packager/clients/repositories.rb', line 745

def ReplaceWidgets(repo_mode)
  Builtins.y2milestone("Replacing the table widget")
  UI.ReplaceWidget(Id(:tabrp), TableWidget(repo_mode))

  UI.ReplaceWidget(
    Id(:priorp),
    if repo_mode
      IntField(
        Id(:priority),
        Opt(:notify),
        @priority_label,
        0,
        200,
        @default_priority
      )
    else
      Empty()
    end
  )
  UI.ReplaceWidget(
    Id(:keeppkg_rp),
    if repo_mode
      CheckBox(Id(:keeppackages), Opt(:notify), @keeppackages_label)
    else
      Empty()
    end
  )

  nil
end

#repo_autorefresh_handler(sourceState, global_current, current) ⇒ Object

Handle the “Autorefresh” checkbox in the repository view

Parameters:

  • sourceState (Hash)

    the current state of the repository or service

  • global_current (Integer)

    index of the repository in the @sourceStatesOut

  • current (Integer)

    index of the selected item in the table


1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
# File 'src/lib/packager/clients/repositories.rb', line 1699

def repo_autorefresh_handler(sourceState, global_current, current)
  source_id = sourceState["SrcId"]
  src_data = Pkg.SourceGeneralData(source_id)
  return if !plugin_service_check(sourceState["service"], repo_change_msg)

  type = src_data["type"]
  state = !sourceState["autorefresh"]

  if type == "PlainDir" && state
    # popup message
    Popup.Message(_("For the selected repository, refresh\ncannot be set."))
    return
  end

  new_symbol = state ? UI.Glyph(:CheckMark) : ""
  UI.ChangeWidget(Id(:table), term(:Item, current, 2), new_symbol)

  sourceState["autorefresh"] = state
  @sourceStatesOut[global_current] = sourceState
end

#repo_change_msgObject

The message displayed when trying to change a repository belonging to a plugin service


2038
2039
2040
2041
# File 'src/lib/packager/clients/repositories.rb', line 2038

def repo_change_msg
  # TRANSLATORS: An error message
  _("The repositories belonging to a service of type 'plugin' cannot be changed.")
end

#repo_delete_handler(global_current) ⇒ Object

Handle the “Delete” button in the repository view

Parameters:

  • global_current (Integer)

    index of the repository in the @sourceStatesOut


1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
# File 'src/lib/packager/clients/repositories.rb', line 1639

def repo_delete_handler(global_current)
  repo = @sourceStatesOut[global_current] || {}

  msg = _("The repositories belonging to a service of type 'plugin' cannot be removed.")
  return if !repo["service"].to_s.empty? && !plugin_service_check(repo["service"], msg)

  # yes-no popup
  return if !Popup.YesNo(_("Delete the selected repository from the list?"))

  deleteSource(global_current)
  fillTable(@repository_view, @displayed_service)
  fillCurrentRepoInfo
end

#repo_enable_handler(sourceState, global_current, current) ⇒ Object

Handle the “Enable” checkbox in the repository view

Parameters:

  • sourceState (Hash)

    the current state of the repository or service

  • global_current (Integer)

    index of the repository in the @sourceStatesOut

  • current (Integer)

    index of the selected item in the table


1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'src/lib/packager/clients/repositories.rb', line 1657

def repo_enable_handler(sourceState, global_current, current)
  repo = @sourceStatesOut[global_current] || {}
  if !repo["service"].to_s.empty? && !plugin_service_check(repo["service"], repo_change_msg)
    return
  end

  state = !sourceState["enabled"]
  # corresponds to the "Enable/Disable" button
  state_symbol = state ? UI.Glyph(:CheckMark) : ""
  UI.ChangeWidget(Id(:table), term(:Item, current, 1), state_symbol)
  sourceState["enabled"] = state
  @sourceStatesOut[global_current] = sourceState
end

#repo_keeppackages_handler(sourceState, global_current) ⇒ Object

Handle the “Keep packages” check box in the repository view

Parameters:

  • sourceState (Hash)

    the current state of the repository or service

  • global_current (Integer)

    index of the repository in the @sourceStatesOut


1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
# File 'src/lib/packager/clients/repositories.rb', line 1762

def repo_keeppackages_handler(sourceState, global_current)
  return if !plugin_service_check(sourceState["service"], repo_change_msg)

  # refresh the value in the table
  new_keep = UI.QueryWidget(Id(:keeppackages), :Value)
  log.info("New keep packages option: #{new_keep}")

  sourceState["keeppackages"] = new_keep
  @sourceStatesOut[global_current] = sourceState
end

#repo_priority_handler(sourceState, global_current, current) ⇒ Object

Handle the “Priority” field in the repository view

Parameters:

  • sourceState (Hash)

    the current state of the repository or service

  • global_current (Integer)

    index of the repository in the @sourceStatesOut

  • current (Integer)

    index of the selected item in the table


1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
# File 'src/lib/packager/clients/repositories.rb', line 1743

def repo_priority_handler(sourceState, global_current, current)
  return if !plugin_service_check(sourceState["service"], repo_change_msg)

  # refresh the value in the table
  new_priority = UI.QueryWidget(Id(:priority), :Value)
  log.debug("New priority: #{new_priority}")

  UI.ChangeWidget(
    Id(:table),
    term(:Item, current, 0),
    PriorityToString(new_priority)
  )
  sourceState["priority"] = new_priority
  @sourceStatesOut[global_current] = sourceState
end

#repo_replace_handler(sourceState, global_current) ⇒ Object

Handle the “Edit” button in the repository view

Parameters:

  • sourceState (Hash)

    the current state of the repository or service

  • global_current (Integer)

    index of the repository in the @sourceStatesOut


1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
# File 'src/lib/packager/clients/repositories.rb', line 1776

def repo_replace_handler(sourceState, global_current)
  id = sourceState["SrcId"]
  generalData = Pkg.SourceGeneralData(id)

  return if !plugin_service_check(generalData["service"], repo_change_msg)

  # use the full URL (incl. the password) when editing it
  url2 = Pkg.SourceRawURL(id)
  old_url = url2
  plaindir = Ops.get_string(generalData, "type", "YaST") == @plaindir_type

  SourceDialogs.SetRepoName(Ops.get_string(sourceState, "name", ""))
  begin
    url2 = SourceDialogs.EditPopupType(url2, plaindir)

    break if Builtins.size(url2).zero?

    same_url = url2 == old_url

    Builtins.y2debug(
      "same_url: %1 (old: %2, new: %3)",
      same_url,
      old_url,
      url2
    )

    # special check for cd:// and dvd:// repositories
    if !same_url
      new_url_parsed = URL.Parse(url2)
      old_url_parsed = URL.Parse(old_url)

      new_url_scheme = Builtins.tolower(
        Ops.get_string(new_url_parsed, "scheme", "")
      )
      old_url_scheme = Builtins.tolower(
        Ops.get_string(old_url_parsed, "scheme", "")
      )

      # ignore cd:// <-> dvd:// changes if the path is not changed
      if (new_url_scheme == "cd" || new_url_scheme == "dvd") &&
          (old_url_scheme == "cd" || old_url_scheme == "dvd")
        # compare only directories, ignore e.g. ?device=/dev/sr0 options
        if Ops.get_string(new_url_parsed, "path", "") ==
            Ops.get_string(old_url_parsed, "path", "")
          Pkg.SourceChangeUrl(
            Ops.get_integer(sourceState, "SrcId", -1),
            url2
          )
          same_url = true
        end
      end
    end

    if !same_url || plaindir != SourceDialogs.IsPlainDir
      Builtins.y2milestone(
        "URL or plaindir flag changed, recreating the source"
      )
      # copy the refresh flag

      # get current alias
      alias_name = Ops.get_string(generalData, "alias", "alias")
      Builtins.y2milestone("Reusing alias: %1", alias_name)

      createResult = createSourceWithAlias(
        url2,
        SourceDialogs.IsPlainDir,
        Ops.get_boolean(sourceState, "do_refresh", false),
        SourceDialogs.GetRepoName,
        alias_name
      )
      if createResult == :ok
        # restore the origonal properties (enabled, autorefresh, keeppackages)
        # the added repository is at the end of the list
        idx = Ops.subtract(Builtins.size(@sourceStatesOut), 1)
        addedSource = Ops.get(@sourceStatesOut, idx, {})

        Builtins.y2milestone("Orig repo: %1", sourceState)
        Builtins.y2milestone("Added repo: %1", addedSource)

        if addedSource != {}
          auto_refresh = Ops.get_boolean(
            sourceState,
            "autorefresh",
            true
          )
          keeppackages = Ops.get_boolean(
            sourceState,
            "keeppackages",
            false
          )
          enabled = Ops.get_boolean(sourceState, "enabled", true)
          priority = Ops.get_integer(
            sourceState,
            "priority",
            @default_priority
          )
          Builtins.y2milestone(
            "Restoring the original properties: enabled: %1, autorefresh: %2, " \
              "keeppackages: %3, priority: %4",
            enabled,
            auto_refresh,
            keeppackages,
            priority
          )

          # set the original properties
          Ops.set(addedSource, "autorefresh", auto_refresh)
          Ops.set(addedSource, "keeppackages", keeppackages)
          Ops.set(addedSource, "enabled", enabled)
          Ops.set(addedSource, "priority", priority)

          # get the ID of the old repo and mark it for removal
          srcid = Ops.get_integer(
            @sourceStatesOut,
            [global_current, "SrcId"],
            -1
          )
          if srcid != -1
            @sourcesToDelete = Builtins.add(@sourcesToDelete, srcid)
            SourceManager.just_removed_sources = Builtins.add(
              SourceManager.just_removed_sources,
              srcid
            )
          end

          # replace the data
          Ops.set(@sourceStatesOut, global_current, addedSource)
          # remove the duplicate at the end
          @sourceStatesOut = Builtins.remove(@sourceStatesOut, idx)

          # refresh only the name and URL in the table
          UI.ChangeWidget(
            Id(:table),
            Cell(global_current, 3),
            Ops.get_string(addedSource, "name", "")
          )
          UI.ChangeWidget(Id(:table), Cell(global_current, 5), url2)

          fillCurrentRepoInfo
        end
      end
    else
      Builtins.y2milestone(
        "URL is the same, not recreating the source"
      )

      new_name = SourceDialogs.GetRepoName
      if new_name != Ops.get_string(sourceState, "name", "")
        Ops.set(sourceState, "name", new_name)
        Ops.set(@sourceStatesOut, global_current, sourceState)

        # update only the name cell in the table
        UI.ChangeWidget(
          Id(:table),
          Cell(global_current, 3),
          new_name
        )

        fillCurrentRepoInfo
      else
        Builtins.y2milestone(
          "The repository name has not been changed"
        )
      end

      createResult = :ok
    end
  end while createResult == :again # service view
end

#RepoFilterWidgetObject


698
699
700
701
# File 'src/lib/packager/clients/repositories.rb', line 698

def RepoFilterWidget
  # combobox label
  ComboBox(Id(:service_filter), Opt(:notify), _("View"), buildList)
end

#repoInfoRichText(name, category, info) ⇒ Object


337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'src/lib/packager/clients/repositories.rb', line 337

def repoInfoRichText(name, category, info)
  url = info["url"]
  raw_url = info["raw_url"]

  schema = Builtins.tolower(
    Ops.get_string(URL.Parse(url), "scheme", "")
  )
  icon_tag = Ops.add(
    Ops.add(
      Ops.add(Ops.add("<IMG SRC=\"", Directory.icondir), "/22x22/apps/"),
      ["cd", "dvd", "iso"].include?(schema) ? "yast-cd_update.png" : "yast-http-server.png"
    ),
    "\">&nbsp;&nbsp;&nbsp;"
  )

  url = _("Unknown") if url == ""
  raw_url = _("Unknown") if raw_url == ""

  url_string = Builtins.sformat(_("URL: %1"), url)
  if url != raw_url
    url_string += "<BR>"
    # TRANSLATORS: Raw URL is the address without expanding repo variables
    # e.g. Raw URL = http://something/$arch -> URL = http://something/x86_64
    url_string += _("Raw URL: %s") % raw_url
  end

  Builtins.sformat(
    "<P>%1<B><BIG>%2</BIG></B></P><P>%3<BR>%4</P>",
    icon_tag,
    name,
    url_string,
    category
  )
end

#repoInfoTermObject


372
373
374
375
376
377
378
379
380
381
382
# File 'src/lib/packager/clients/repositories.rb', line 372

def repoInfoTerm
  if textmode
    VBox(
      Left(Heading(Id(:name), Opt(:hstretch), "")),
      Left(Label(Id(:url), Opt(:hstretch), "")),
      Left(Label(Id(:category), Opt(:hstretch), ""))
    )
  else
    VSquash(MinHeight(4, RichText(Id(:repo_info), "")))
  end
end

#ReposFromService(service, input) ⇒ Object


184
185
186
187
188
189
190
# File 'src/lib/packager/clients/repositories.rb', line 184

def ReposFromService(service, input)
  input = deep_copy(input)
  service = "" if service == NO_SERVICE
  Builtins.filter(input) do |repo|
    Ops.get_string(repo, "service", "") == service
  end
end

#service_autorefresh_handler(current) ⇒ Object

Handle the “Autorefresh” checkbox in the service view

Parameters:

  • current (Integer)

    index of the selected item in the table


1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
# File 'src/lib/packager/clients/repositories.rb', line 1722

def service_autorefresh_handler(current)
  srv = @serviceStatesOut[current]
  log.info("Selected service: #{srv}")

  service_alias = srv["alias"]
  return if !plugin_service_check(service_alias, plugin_change_msg)

  state = !srv["autorefresh"]
  # update the table
  new_symbol = state ? UI.Glyph(:CheckMark) : ""
  UI.ChangeWidget(Id(:table), term(:Item, current, 1), new_symbol)

  # store the change
  srv["autorefresh"] = state
  @serviceStatesOut[current] = srv
end

#service_delete_handler(current) ⇒ Object

Handle the “Delete” button in the service view

Parameters:

  • current (Integer)

    index of the selected item in the table


1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
# File 'src/lib/packager/clients/repositories.rb', line 1612

def service_delete_handler(current)
  selected_service = @serviceStatesOut[current] || {}

  service_alias = selected_service["alias"]
  msg = _("The services of type 'plugin' cannot be removed.")
  return if !plugin_service_check(service_alias, msg)

  # yes-no popup
  return if !Popup.YesNo(
    Builtins.sformat(
      _("Delete service %1\nand its repositories?"),
      selected_service["name"]
    )
  )

  RemoveReposFromService(service_alias)

  deleteService(current)
  fillTable(@repository_view, @displayed_service)
  fillCurrentRepoInfo

  # refresh also the combobox widget
  UpdateCombobox()
end

#service_enable_handler(current) ⇒ Object

Handle the “Enable” checkbox in the service view

Parameters:

  • current (Integer)

    index of the selected item in the table


1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
# File 'src/lib/packager/clients/repositories.rb', line 1673

def service_enable_handler(current)
  srv = @serviceStatesOut[current]
  return if !srv

  log.info("Selected service: #{srv}")
  state = !srv["enabled"]

  # disable/enable the repositories belonging to the service
  service_alias = srv["alias"]
  return if !plugin_service_check(service_alias, plugin_change_msg)

  SetReposStatusFromService(service_alias, state)

  # update the table
  state_symbol = state ? UI.Glyph(:CheckMark) : ""
  UI.ChangeWidget(Id(:table), term(:Item, current, 0), state_symbol)

  # store the change
  srv["enabled"] = state
  @serviceStatesOut[current] = srv
end

#service_replace_handler(current) ⇒ Object

Handle the “Edit” button in the service view

Parameters:

  • current (Integer)

    index of the selected item in the table


1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
# File 'src/lib/packager/clients/repositories.rb', line 1948

def service_replace_handler(current)
  service_info = Ops.get(@serviceStatesOut, current, {})

  service_alias = service_info["alias"]
  return if !plugin_service_check(service_alias, plugin_change_msg)

  Builtins.y2milestone("Editing service %1...", current)
  url2 = Ops.get_string(service_info, "raw_url", "")
  old_url = url2

  SourceDialogs.SetRepoName(
    Ops.get_string(service_info, "name", "")
  )
  begin
    url2 = SourceDialogs.EditPopupService(url2)

    break if Builtins.size(url2).zero?
    if url2 != old_url
      Builtins.y2milestone(
        "URL of the service has been changed, recreating the service"
      )
      # createSource() can potentially create a repository instead of a service
      # Probe for a service first must be done before creating a new service
      service_type = Pkg.ServiceProbe(url2)
      Builtins.y2milestone("Probed service type: %1", service_type)

      if !service_type.nil? && service_type != "NONE"
        createResult = createSource(
          url2,
          false,
          false,
          SourceDialogs.GetRepoName
        )
        if createResult == :ok
          deleteService(current)
          fillTable(@repository_view, @displayed_service)
          fillCurrentRepoInfo

          # refresh also the combobox widget
          UpdateCombobox()
        end
      else
        Report.Error(
          Builtins.sformat(
            _("There is no service at URL:\n%1"),
            url2
          )
        )
      end
    else
      Builtins.y2milestone(
        "URL is the same, not recreating the service"
      )
      entered_service_name = SourceDialogs.GetRepoName
      old_service_name = Ops.get_string(service_info, "name", "")

      if old_service_name != entered_service_name
        Builtins.y2milestone(
          "Updating name of the service to '%1'",
          entered_service_name
        )
        Ops.set(service_info, "name", entered_service_name)
        Ops.set(@serviceStatesOut, current, service_info)
        fillTable(@repository_view, @displayed_service)
        fillCurrentRepoInfo
        createResult = :ok

        # update the reference
        @sourceStatesOut = Builtins.maplist(@sourceStatesOut) do |src_state|
          if Ops.get_string(src_state, "service", "") == old_service_name
            Ops.set(src_state, "service", entered_service_name)
          end
          deep_copy(src_state)
        end

        # refresh also the combobox widget
        UpdateCombobox()
      end
    end
  end while createResult == :again
end

#SetReposStatusFromService(service_alias, enable) ⇒ Object


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
# File 'src/lib/packager/clients/repositories.rb', line 810

def SetReposStatusFromService(service_alias, enable)
  # delete the repositories belonging to the service
  repos = ReposFromService(service_alias, @sourceStatesOut)
  Builtins.y2milestone(
    "%1 repos from service alias=%2: %3",
    enable ? "Enabling" : "Disabling",
    service_alias,
    repos
  )

  Builtins.foreach(repos) do |repo|
    srcid = Ops.get_integer(repo, "SrcId", -1)
    @sourceStatesOut = Builtins.maplist(@sourceStatesOut) do |srcstate|
      if Ops.get_integer(srcstate, "SrcId", -1) == srcid
        Builtins.y2milestone(
          "%1 repository %2",
          enable ? "Enabling" : "Disabling",
          srcstate
        )
        Ops.set(srcstate, "enabled", enable)
      end
      deep_copy(srcstate)
    end
  end

  nil
end

#SortReposByPriority(repos) ⇒ Object


1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# File 'src/lib/packager/clients/repositories.rb', line 1385

def SortReposByPriority(repos)
  repos = deep_copy(repos)
  # check the input
  return deep_copy(repos) if repos.nil?

  # sort the maps by "repos" key (in ascending order)
  ret = Builtins.sort(repos) do |repo1, repo2|
    Ops.less_than(
      Ops.get_integer(repo1, "priority", @default_priority),
      Ops.get_integer(repo2, "priority", @default_priority)
    )
  end

  Builtins.y2milestone("SortReposByPriority: %1 -> %2", repos, ret)

  deep_copy(ret)
end

#StartEditDialogObject


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
# File 'src/lib/packager/clients/repositories.rb', line 1456

def StartEditDialog
  Builtins.y2milestone("Edit URL with protocol %1", @selected_url_scheme)
  ret = nil
  begin
    ret = SourceDialogs.EditDialogProtocol(@selected_url_scheme)

    if ret == :next
      url = SourceDialogs.GetURL
      occupied = url_occupied?(url)

      if occupied
        # popup question, %1 is repository URL
        if !Popup.AnyQuestion(
          "",
          Builtins.sformat(
            _(
              "Repository %1\n" \
                "has been already added. Each repository should be added only once.\n" \
                "\n" \
                "Really add the repository again?"
            ),
            URL.HidePassword(url)
          ),
          Label.YesButton,
          Label.NoButton,
          :focus_no
        )
          # ask again
          ret = nil
        end
      end
    end
  end while ret.nil?

  Builtins.y2milestone("Result: %1", ret)

  ret
end

#StartInstSourceObject

main function - start the workflow


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
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
# File 'src/lib/packager/clients/repositories.rb', line 1507

def StartInstSource
  Wizard.CreateDialog
  Wizard.SetDesktopIcon("sw_source")

  if !@full_mode
    # dialog caption
    Wizard.SetContents(_("Initializing..."), Empty(), "", false, true)
    Pkg.TargetInit("/", true)
  end

  Wizard.SetDesktopTitleAndIcon("sw_source")

  # check whether running as root
  if !Confirm.MustBeRoot ||
      !Ops.get_boolean(PackageLock.Connect(false), "connected", false)
    UI.CloseDialog
    return :abort
  end

  PackageCallbacks.InitPackageCallbacks if !@full_mode

  # read repositories & services
  restore = !@full_mode ? Pkg.SourceRestore : true

  Builtins.y2milestone("Known services: %1", Pkg.ServiceAliases)

  if !restore
    cont = Popup.AnyQuestionRichText(
      Label.ErrorMsg,
      Ops.add(
        Ops.add(
          # Error popup
          _(
            "<p>Errors occurred while restoring the repository configuration.</p>\n"
          ) + "<p>",
          Pkg.LastError
        ),
        "</p>"
      ),
      50,
      15,
      Label.ContinueButton,
      Label.CancelButton,
      :focus_no
    )

    # really continue?
    if !cont
      Wizard.CloseDialog
      return :abort
    end
  end

  # read known GPG keys
  KeyManager.Read

  @sourceStatesIn = SortReposByPriority(Pkg.SourceEditGet)
  Builtins.y2milestone("Found repositories: %1", @sourceStatesIn)
  @sourceStatesOut = deep_copy(@sourceStatesIn)

  srv_aliases = Pkg.ServiceAliases
  # get the current services
  Builtins.foreach(srv_aliases) do |srv_alias|
    @serviceStatesIn = Builtins.add(
      @serviceStatesIn,
      Pkg.ServiceGet(srv_alias)
    )
  end

  Builtins.y2milestone("Loaded services: %1", @serviceStatesIn)

  @serviceStatesOut = deep_copy(@serviceStatesIn)

  aliases = {
    "summary" => -> { SummaryDialog() },
    "type"    => -> { StartTypeDialog() },
    "edit"    => -> { StartEditDialog() },
    "store"   => -> { StartStoreSource() },
    "keymgr"  => [-> { RunGPGKeyMgmt(false) }, true]
  }

  sequence = {
    "ws_start" => "summary",
    "summary"  => {
      add:     "type",
      edit:    "edit",
      key_mgr: "keymgr",
      abort:   :abort,
      next:    :next
    },
    "keymgr"   => { next: "summary", abort: "summary" },
    "type"     => { next: "edit", finish: "store", abort: :abort },
    "edit"     => { next: "store", abort: :abort },
    "store"    => { next: "summary", abort: "summary" }
  }

  Builtins.y2milestone("Starting repository sequence")
  ret = Sequencer.Run(aliases, sequence)

  UI.CloseDialog
  ret
end

#StartStoreSourceObject


1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
# File 'src/lib/packager/clients/repositories.rb', line 1495

def StartStoreSource
  ret = StoreSource()

  if ret == :next || ret == :abort || ret == :close
    Builtins.y2milestone("Resetting selected URL scheme")
    @selected_url_scheme = ""
  end

  ret
end

#StartTypeDialogObject


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
# File 'src/lib/packager/clients/repositories.rb', line 1403

def StartTypeDialog
  seturl = @selected_url_scheme

  if !seturl.nil? && seturl != ""
    seturl = Ops.add(@selected_url_scheme, "://")
  end

  ret = TypeDialogOpts(true, seturl)

  if ret == :back
    @selected_url_scheme = ""
  else
    @selected_url_scheme = Ops.get_string(
      URL.Parse(SourceDialogs.GetRawURL),
      "scheme",
      ""
    )
    Builtins.y2milestone("Selected URL scheme: %1", @selected_url_scheme)

    if @selected_url_scheme.nil? || @selected_url_scheme == ""
      @selected_url_scheme = "url"
    end
  end

  ret
end

#SummaryDialogObject


838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
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
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
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
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
# File 'src/lib/packager/clients/repositories.rb', line 838

def SummaryDialog
  Builtins.y2milestone("Running Summary dialog")

  # push button - refresh the selected repository now
  refreshButtonLabel = _("Re&fresh Selected")

  contents = VBox(
    Right(ReplacePoint(Id(:filter_rp), RepoFilterWidget())),
    VWeight(1, ReplacePoint(Id(:tabrp), TableWidget(@repository_view))),
    repoInfoTerm,
    # label
    Left(Label(_("Properties"))),
    HBox(
      HSquash(
        VBox(
          # check box
          Left(CheckBox(Id(:enable), Opt(:notify), _("&Enabled"))),
          # check box
          Left(
            CheckBox(
              Id(:autorefresh),
              Opt(:notify),
              _("Automatically &Refresh")
            )
          )
        )
      ),
      HSpacing(1),
      HSquash(
        Bottom(
          # check box
          ReplacePoint(
            Id(:keeppkg_rp),
            CheckBox(Id(:keeppackages), Opt(:notify), @keeppackages_label)
          )
        )
      ),
      HSpacing(1),
      HSquash(
        ReplacePoint(
          Id(:priorp),
          IntField(
            Id(:priority),
            Opt(:notify),
            @priority_label,
            0,
            200,
            @default_priority
          )
        )
      ),
      HStretch()
    ),
    VSpacing(0.4),
    HBox(
      PushButton(Id(:add), Opt(:key_F3), Label.AddButton),
      PushButton(Id(:replace), Opt(:key_F4), Label.EditButton),
      PushButton(Id(:delete), Opt(:key_F5), Label.DeleteButton),
      HStretch(),
      # push button label
      PushButton(Id(:key_mgr), _("&GPG Keys...")),
      # menu button label
      MenuButton(
        Id(:menu_button),
        Opt(:key_F6),
        _("Refresh"),
        [
          Item(Id(:refresh), refreshButtonLabel),
          # menu button label
          Item(Id(:autorefresh_all), _("Refresh all Autor&efreshed")),
          # menu button label
          Item(Id(:refresh_enabled), _("Refresh all &Enabled"))
        ]
      )
    )
  )

  # dialog caption
  title = _("Configured Software Repositories")

  # help
  help_text = _(
    "<p>\nManage configured software repositories and services.</p>\n"
  )

  help_text = Ops.add(
    help_text,
    _(
      "<P>A <B>service</B> or <B>Repository Index Service (RIS) </B> is a protocol for " \
        "package repository management. A service can offer one or more software " \
        "repositories which can be dynamically changed by the service administrator.</P>"
    )
  )

  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "<b>Adding a new Repository or a Service</b><br>\n" \
        "To add a new repository, use <b>Add</b> and specify the software repository or " \
        "service.\n YaST will automatically detect whether a service or a repository is " \
        "available at the entered location.\n</p>\n"
    )
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "To install packages from <b>CD</b>,\n" \
        "have the CD set or the DVD available.\n" \
        "</p>\n"
    )
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "The CDs can be copied to <b>hard disk</b>\n" \
        "and then used as a repository.\n" \
        "Insert the path name where the first\n" \
        "CD is located, for example, /data1/<b>CD1</b>.\n" \
        "Only the base path is required if all CDs are copied\n" \
        "into one directory.\n" \
        "</p>\n"
    )
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "<b>Modifying Status of a Repository or a Service</b><br>\n" \
        "To change a repository location, use <b>Edit</b>. To remove a repository, use\n" \
        "<b>Delete</b>. To enable or disable the repository or to change the refresh status " \
        "at initialization time, select the repository in the table and use the check boxes " \
        "below.\n</p>\n"
    )
  )

  # help text, continued
  help_text = Ops.add(
    help_text,
    _(
      "<P><B>Priority of a Repository</B><BR>\nPriority of a repository is " \
        "an integer value between 0 (the highest priority) and 200 (the lowest priority). " \
        "Default is 99. If a package is available in more repositories, " \
        "the repository with the highest priority is used.</P>\n"
    )
  )

  # help text, continued
  help_text = Ops.add(
    help_text,
    _(
      "<P>Select the appropriate option on top of the window for navigation in " \
        "repositories and services.</P>"
    )
  )
  # help text, continued
  help_text = Ops.add(
    Ops.add(
      help_text,
      _(
        "<P><B>Keep Downloaded Packages</B><BR>Check this option to keep downloaded\n" \
          "packages in a local cache so they can be reused later when the packages are\n" \
          "reinstalled. If not checked, the downloaded packages are deleted after " \
          "installation.</P>"
      )
    ),
    _(
      "<P>The default local cache is located in directory <B>/var/cache/zypp/packages</B>. " \
        "Change the location in <B>/etc/zypp/zypp.conf</B> file.</P>"
    )
  )

  Wizard.SetNextButton(:next, Label.OKButton)
  Wizard.SetAbortButton(:abort, Label.CancelButton)

  Wizard.SetContents(title, contents, help_text, false, true)
  Wizard.HideBackButton

  fillTable(@repository_view, @displayed_service)
  fillCurrentRepoInfo

  input = nil

  current = -1

  exit = false
  begin
    if !current.nil? && Ops.greater_or_equal(current, 0)
      UI.ChangeWidget(Id(:table), :CurrentItem, current)
      fillCurrentRepoInfo
    end

    current = -1

    event = UI.WaitForEvent
    input = Ops.get_symbol(event, "ID", :nothing)
    Builtins.y2debug("Input: %1", input)
    if input == :table &&
        Ops.get_string(event, "EventReason", "") == "Activated"
      input = :enable
    end

    return :add if input == :add
    if input == :next
      # store the new state
      success = Write()
      if !success
        # popup message part 1
        message1 = _(
          "Unable to save changes to the repository\nconfiguration."
        )
        details = Pkg.LastError
        Builtins.y2milestone("LastError: %1", details)
        # popup message part 2 followed by other info
        message2 = details != "" ? Ops.add(_("Details:") + "\n", details) : ""
        # popup message part 3
        message2 = Ops.add(Ops.add(message2, "\n"), _("Try again?"))

        tryagain = Popup.YesNo(Ops.add(Ops.add(message1, "\n"), message2))
        exit = true if !tryagain
      else
        exit = true
      end
    # Wizard::UserInput returns `back instead of `cancel when window is closed by WM
    elsif input == :abort || input == :cancel
      # handle cancel as abort
      input = :abort

      # no change, do not confirm exit
      if @sourceStatesOut == @sourceStatesIn
        exit = true
      else
        # popup headline
        headline = _("Abort Repository Configuration")
        # popup message
        msg = _(
          "Abort the repository configuration?\nAll changes will be lost."
        )
        exit = true if Popup.YesNoHeadline(headline, msg)
      end
    elsif input == :key_mgr
      exit = true
      # return `key_mgr;
      # start the GPG key manager
      # RunGPGKeyMgmt();
    elsif input == :service_filter
      # handle the combobox events here...
      current_item = UI.QueryWidget(Id(:service_filter), :Value)

      # rebuild the dialog if needed
      Builtins.y2milestone("Current combobox item: %1", current_item)
      update_table_widget = false

      if current_item == :all_repositories
        update_table_widget = !@repository_view || @displayed_service != ""
        Builtins.y2milestone("Switching to repository view")
        @repository_view = true
        @displayed_service = ""
      elsif current_item == :all_services
        update_table_widget = @repository_view
        Builtins.y2milestone("Switching to service view")
        @repository_view = false
        # display all services
        @displayed_service = ""
      elsif current_item == NO_SERVICE_ITEM
        update_table_widget = @repository_view
        Builtins.y2milestone("Switching to without service view")
        @repository_view = true
        # display repositories without service
        @displayed_service = NO_SERVICE
      elsif Ops.is_string?(current_item)
        # switch to the selected repository
        Builtins.y2milestone("Switching to service %1", current_item)
        @repository_view = true
        # display the selected service
        @displayed_service = Convert.to_string(current_item)

        # FIXME: always update the table?
        update_table_widget = true
      end

      # update table widget
      ReplaceWidgets(@repository_view) if update_table_widget

      # update table content
      fillTable(@repository_view, @displayed_service)
      fillCurrentRepoInfo

      # update the current item
      current = Convert.to_integer(UI.QueryWidget(Id(:table), :CurrentItem))
    else
      current = Convert.to_integer(UI.QueryWidget(Id(:table), :CurrentItem))

      Builtins.y2debug("Current item: %1", current)

      sourceState = {}

      # global_current - 'current' that points to global sourceStatesOut
      global_current = -1

      if @repository_view
        if @displayed_service == ""
          sourceState = Ops.get(@sourceStatesOut, current, {})
          global_current = current
        elsif !current.nil?
          sources_from_service = ReposFromService(
            @displayed_service,
            @sourceStatesOut
          )
          sourceState = Ops.get(sources_from_service, current, {})

          Builtins.find(@sourceStatesOut) do |s|
            global_current = Ops.add(global_current, 1)
            Ops.get(s, "SrcId") ==
              Ops.get_integer(sourceState, "SrcId", -1)
          end

          Builtins.y2milestone("global_current: %1", global_current)
        end
      end

      id = Ops.get_integer(sourceState, "SrcId", -1)

      if Ops.less_than(id, 0) && @repository_view &&
          @displayed_service == ""
        Builtins.y2error(
          "Unable to determine repository id, broken repository?"
        )
        next
      end

      if input == :replace
        if @repository_view
          repo_replace_handler(sourceState, global_current)
        else
          service_replace_handler(current)
        end
      elsif input == :refresh
        if @repository_view
          Pkg.SourceRefreshNow(id)

          if @full_mode && Ops.get_boolean(sourceState, "enabled", false)
            # force loading of the resolvables
            Pkg.SourceSetEnabled(id, false)
            Pkg.SourceSetEnabled(id, true)
          end
        else
          # refresh a service
          service_alias = Ops.get_string(
            Ops.get(@serviceStatesOut, current, {}),
            "alias",
            ""
          )

          Builtins.y2milestone("Refreshing service %1...", service_alias)
          Pkg.ServiceRefresh(service_alias)
        end
      elsif input == :autorefresh_all || input == :refresh_enabled
        Builtins.y2milestone(
          "Refreshing all %1 %2%3...",
          input == :refresh_enabled ? "enabled" : "autorefreshed",
          @repository_view ? "repositories" : "services",
          if @repository_view && @displayed_service != ""
            Ops.add(" from service ", @displayed_service)
          else
            ""
          end
        )

        refresh_autorefresh_only = input == :autorefresh_all
        to_refresh = 0

        data = if @repository_view
          if @displayed_service == ""
            deep_copy(@sourceStatesOut)
          else
            ReposFromService(@displayed_service, @sourceStatesOut)
          end
        else
          deep_copy(@serviceStatesOut)
        end

        Builtins.y2milestone("data: %1", data)

        Builtins.foreach(data) do |src_state|
          if Ops.get_boolean(src_state, "enabled", false) &&
              (!refresh_autorefresh_only ||
                Ops.get_boolean(src_state, "autorefresh", false))
            url2 = if @repository_view
              Ops.get_string(
                Pkg.SourceGeneralData(
                  Ops.get_integer(src_state, "SrcId", -1)
                ),
                "url",
                ""
              )
            else
              Ops.get_string(src_state, "url", "")
            end
            schema = Builtins.tolower(Builtins.substring(url2, 0, 3))

            if schema != "cd:" && schema != "dvd"
              to_refresh = Ops.add(to_refresh, 1)
            end
          end
        end

        Builtins.y2milestone(
          "%1 %2 will be refreshed",
          to_refresh,
          @repository_view ? "repositories" : "services"
        )

        if Ops.greater_than(to_refresh, 0)
          Wizard.CreateDialog
          # TODO: add help text
          Progress.New(
            @repository_view ? _("Refreshing Repositories") : _("Refreshing Services"),
            "",
            Ops.add(to_refresh, 1),
            [
              @repository_view ? _("Refresh Repositories") : _("Refresh Services")
            ],
            [],
            ""
          )

          Builtins.foreach(data) do |src_state|
            if Ops.get_boolean(src_state, "enabled", false) &&
                (!refresh_autorefresh_only ||
                  Ops.get_boolean(src_state, "autorefresh", false))
              name = Ops.get_string(src_state, "name", "")
              if @repository_view
                srcid = Ops.get_integer(src_state, "SrcId", -1)

                url2 = Ops.get_string(
                  Pkg.SourceGeneralData(
                    Ops.get_integer(src_state, "SrcId", -1)
                  ),
                  "url",
                  ""
                )
                schema = Builtins.tolower(Builtins.substring(url2, 0, 3))

                if schema != "cd:" && schema != "dvd"
                  Builtins.y2milestone(
                    "Autorefreshing repository %1 (%2)",
                    srcid,
                    name
                  )

                  # progress bar label
                  Progress.Title(
                    Builtins.sformat(_("Refreshing Repository %1..."), name)
                  )

                  Pkg.SourceRefreshNow(srcid)

                  if @full_mode &&
                      Ops.get_boolean(src_state, "enabled", false)
                    # force loading of the resolvables
                    Pkg.SourceSetEnabled(srcid, false)
                    Pkg.SourceSetEnabled(srcid, true)
                  end

                  Progress.NextStep
                else
                  Builtins.y2milestone(
                    "Skipping a CD/DVD repository %1 (%2)",
                    srcid,
                    name
                  )
                end
              else
                service_alias = Ops.get_string(src_state, "alias", "")

                # refreshing services
                # progress bar label
                Progress.Title(
                  Builtins.sformat(_("Refreshing Service %1..."), name)
                )
                Builtins.y2milestone(
                  "Refreshing service %1 (alias: %2)...",
                  name,
                  service_alias
                )
                Pkg.ServiceRefresh(service_alias)
              end
            end
          end

          Progress.Finish
          Wizard.CloseDialog
        end
      elsif input == :delete
        if @repository_view
          repo_delete_handler(global_current)
        else
          service_delete_handler(current)
        end
      elsif input == :enable
        if @repository_view
          repo_enable_handler(sourceState, global_current, current)
        else
          service_enable_handler(current)
        end
      elsif input == :autorefresh
        if @repository_view
          repo_autorefresh_handler(sourceState, global_current, current)
        else
          service_autorefresh_handler(current)
        end
      elsif input == :priority
        if @repository_view
          repo_priority_handler(sourceState, global_current, current)
        else
          Builtins.y2error(
            "Ignoring event `priority: the widget should NOT be displayed in service mode!"
          )
        end
      elsif input == :keeppackages
        if @repository_view
          repo_keeppackages_handler(sourceState, global_current)
        else
          Builtins.y2error(
            "Ignoring event `keeppackages: the widget should NOT be displayed in service mode!"
          )
        end
      elsif input != :table
        Builtins.y2warning("Unknown user input: %1", input)
      end
    end
  end until exit

  Builtins.y2debug("Return: %1", input)

  input
end

#TableWidget(repository_mode) ⇒ Object

return table widget definition layout of the table depends on the current mode (services do not have priorities)


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
# File 'src/lib/packager/clients/repositories.rb', line 711

def TableWidget(repository_mode)
  tabheader = if repository_mode
    Header(
      # table header - priority of the repository - keep the translation as short as possible!
      _("Priority"),
      # table header - is the repo enabled? - keep the translation as short as possible!
      Center(_("Enabled")),
      # table header - is autorefresh enabled for the repo?
      # keep the translation as short as possible!
      Center(_("Autorefresh")),
      # table header - name of the repo
      _("Name"),
      # table header - service to which the repo belongs
      _("Service"),
      # table header - URL of the repo
      _("URL")
    )
  else
    Header(
      # table header - is the repo enabled? - keep the translation as short as possible!
      Center(_("Enabled")),
      # table header - is autorefresh enabled for the repo?
      # keep the translation as short as possible!
      Center(_("Autorefresh")),
      # table header - name of the repo
      _("Name"),
      # table header - URL of the repo
      _("URL")
    )
  end

  Table(Id(:table), Opt(:notify, :immediate), tabheader, [])
end

#textmodeObject


110
111
112
113
114
115
116
117
118
119
120
# File 'src/lib/packager/clients/repositories.rb', line 110

def textmode
  if @text_mode.nil?
    @text_mode = if Mode.commandline
      true
    else
      Ops.get_boolean(UI.GetDisplayInfo, "TextMode", false)
    end
  end

  @text_mode
end

#UpdateComboboxObject


703
704
705
706
707
# File 'src/lib/packager/clients/repositories.rb', line 703

def UpdateCombobox
  UI.ReplaceWidget(Id(:filter_rp), RepoFilterWidget())

  nil
end

#url_occupied?(url) ⇒ Boolean

Returns:

  • (Boolean)

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
# File 'src/lib/packager/clients/repositories.rb', line 1430

def url_occupied?(url)
  scheme = Builtins.tolower(Ops.get_string(URL.Parse(url), "scheme", ""))

  # alway create CD/DVD repository
  return false if scheme == "cd" || scheme == "dvd"

  ret = false

  Builtins.foreach(@sourceStatesOut) do |src|
    src_id = Builtins.tointeger(Ops.get(src, "SrcId"))
    generalData = Pkg.SourceGeneralData(src_id)
    src_url = Ops.get_string(generalData, "url", "")
    multi_modules = ![nil, "", "/"].include?(generalData["product_dir"])
    # for multi modules single url can be used for multi repositories, so
    # so it is not occupied
    if (src_url == url) && !multi_modules
      ret = true
      break
    end
  end

  Builtins.y2milestone("URL exists: %1", ret)

  ret
end

#warn_service_repository(source_state) ⇒ Object

Shows a warning message when repository managed by a service

Parameters:

  • source_state (Hash)

    the current state of the repository or service


2072
2073
2074
2075
2076
2077
2078
2079
2080
# File 'src/lib/packager/clients/repositories.rb', line 2072

def warn_service_repository(source_state)
  msg = _("Repository '%{name}' is managed by service '%{service}'.\n"\
    "Your manual changes might be reset by the next service refresh!") %
    { name: source_state["name"], service: source_state["service"] }
  if !source_state["service"].to_s.empty? && !@services_repos.include?(source_state["SrcId"])
    Popup.Warning(msg)
    @services_repos.push(source_state["SrcId"])
  end
end

#WriteObject


569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'src/lib/packager/clients/repositories.rb', line 569

def Write
  success = true

  # evaluate removed and new services
  deleted_services = newServices(@serviceStatesOut, @serviceStatesIn)
  Builtins.y2milestone("Deleted services: %1", deleted_services)
  added_services = newServices(@serviceStatesIn, @serviceStatesOut)
  Builtins.y2milestone("Added services: %1", added_services)

  Builtins.foreach(deleted_services) do |alias_name|
    Builtins.y2milestone("Removing service %1", alias_name)
    success &&= Pkg.ServiceDelete(alias_name)
  end

  Builtins.y2milestone("New service config: %1", @serviceStatesOut)
  Builtins.foreach(@serviceStatesOut) do |s|
    alias_name = Ops.get_string(s, "alias", "")
    if Builtins.contains(added_services, alias_name)
      Builtins.y2milestone("Adding service %1", alias_name)
      new_url = Ops.get_string(s, "url", "")

      if new_url != ""
        Builtins.y2milestone("aliases: %1", Pkg.ServiceAliases)
        success &&= Pkg.ServiceAdd(alias_name, new_url)
        # set enabled and autorefresh flags
        success &&= Pkg.ServiceSet(alias_name, s)
      else
        Builtins.y2error("Empty URL for service %1", alias_name)
      end
    else
      Builtins.y2milestone("Modifying service %1", alias_name)
      success &&= Pkg.ServiceSet(alias_name, s)
    end
  end

  # if started from the package manager we need to call these extra
  # pkg-bindings to sync the pool state
  if @full_mode
    @sourceStatesOut.each do |src|
      srcid = src["SrcId"]
      next unless Pkg.SourceGetCurrent(false).include?(srcid)

      Pkg.SourceSetEnabled(srcid, src["enabled"])
      Pkg.SourceSetPriority(srcid, src["priority"])
    end
  end

  Builtins.y2milestone("New repo config: %1", @sourceStatesOut)
  success &&= Pkg.SourceEditSet(@sourceStatesOut)

  # we must sync before the repositories are deleted from zypp
  # otherwise we will not get their details
  added = newSources(@sourceStatesIn, @sourceStatesOut)

  Builtins.foreach(@sourcesToDelete) do |id|
    if Builtins.contains(@reposFromDeletedServices, id)
      Builtins.y2milestone(
        "Repository %1 has been already removed (belongs to a deleted service)",
        id
      )
    else
      success &&= Pkg.SourceDelete(id)
    end
  end

  refresh_enabled = Builtins.contains(WFM.Args, "refresh-enabled")

  Builtins.foreach(@sourceStatesOut) do |src_state|
    srcid = Ops.get_integer(src_state, "SrcId", -1)
    if refresh_enabled && Builtins.contains(added, srcid)
      Builtins.y2milestone("Refreshing enabled repository: %1", srcid)
      Ops.set(src_state, "do_refresh", true)
    end
    if Ops.get_boolean(src_state, "do_refresh", false)
      Builtins.y2milestone("Downloading metadata for source %1", srcid)

      success &&= Pkg.SourceRefreshNow(srcid)
    end
  end

  success &&= KeyManager.Write

  # store repositories and services in the persistent libzypp storage
  success &&= Pkg.SourceSaveAll # #176013

  success
end