Class: Yast::InstAddonUpdateSourcesClient

Inherits:
Client
  • Object
show all
Defined in:
src/lib/installation/clients/inst_addon_update_sources.rb

Instance Method Summary collapse

Instance Method Details

#KnownUrlsObject

Returns the urls of known installation sources.

Returns:

  • the urls of known installation sources



142
143
144
145
146
147
148
149
150
151
# File 'src/lib/installation/clients/inst_addon_update_sources.rb', line 142

def KnownUrls
  src_ids = Pkg.SourceGetCurrent(
    true # enabled only?
  )
  urls = Builtins.maplist(src_ids) do |src_id|
    gendata = Pkg.SourceGeneralData(src_id)
    Ops.get_string(gendata, "url", "")
  end
  deep_copy(urls)
end

#mainObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'src/lib/installation/clients/inst_addon_update_sources.rb', line 33

def main
  Yast.import "Pkg"
  textdomain "installation"

  Yast.import "GetInstArgs"
  Yast.import "PackageCallbacks"
  Yast.import "Popup"
  Yast.import "SourceManager"
  Yast.import "Report"
  Yast.import "Installation"
  Yast.import "String"

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

  return :auto if GetInstArgs.going_back # going backwards? # don't execute this once more

  @aliases = {}

  # feedback heading
  @heading = _("Add-on Product Installation")
  # feedback message
  @message = _("Reading packages available in the repositories...")

  # bugzilla #270899#c29
  Pkg.TargetInitialize(Installation.destdir)
  Pkg.TargetLoad
  Pkg.SourceStartManager(true)

  @knownUrls = KnownUrls()
  Builtins.y2milestone("sources known: %1", @knownUrls)
  @is_known = Builtins.listmap(@knownUrls) { |u| { u => true } }

  @updateUrls = UpdateUrls()
  Builtins.y2milestone("sources for updates: %1", @updateUrls)

  @addUrls = Builtins.filter(@updateUrls) do |url, _name|
    !Ops.get(@is_known, url, false)
  end
  Builtins.y2milestone("sources to add: %1", @addUrls)

  if @addUrls != {}
    Popup.ShowFeedback(@heading, @message)

    Builtins.foreach(@addUrls) do |url, name|
      again = true
      while again
        # BNC #557723: Repositories migh be created without access to network
        # Libzypp must not probe the repo

        alias_ = Ops.get(@aliases, url, "")
        if alias_ == ""
          # don't use spaces in alias (hard to use with zypper)
          alias_ = String.Replace(
            Ops.greater_than(Builtins.size(name), 0) ? name : url,
            " ",
            "-"
          )
        end

        repo_prop = {
          "enabled"     => true,
          "autorefresh" => true,
          "name"        => Ops.greater_than(Builtins.size(name), 0) ? name : url,
          "alias"       => alias_,
          "base_urls"   => [url],
          "prod_dir"    => "/"
        }

        srcid = Pkg.RepositoryAdd(repo_prop)
        Builtins.y2milestone("got %1 from creating %2/%3", srcid, url, name)

        # wrong srcid, must have failed
        if srcid == -1
          # popup error message
          # %1 represents the the error message details
          if Popup.YesNo(
            Builtins.sformat(
              _(
                "An error occurred while connecting to the server.\n" \
                "Details: %1\n" \
                "\n" \
                "Try again?"
              ),
              Pkg.LastError
            )
          )
            # try again
            url = editUrl(url)
          else
            # abort
            again = false
          end

          # everything is ok
        else
          again = false
        end
      end
    end

    Popup.ClearFeedback
  end

  :auto

  # EOF
end

#UpdateUrlsObject

Returns the installation sources to be added.

Returns:

  • the installation sources to be added



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'src/lib/installation/clients/inst_addon_update_sources.rb', line 154

def UpdateUrls
  urls = {}
  products = Y2Packager::Resolvable.find(kind: :product)

  Builtins.foreach(products) do |p|
    Builtins.foreach(p.update_urls) do |u|
      # bnc #542792
      # Repository name must be generated from product details
      p_name =
        [p.display_name, p.name, p.summary, _("Unknown Product")].reject(&:empty?).first
      Ops.set(
        urls,
        u,
        Builtins.sformat(
          _("Updates for %1 %2"),
          p_name,
          p.version
        )
      )
      # alias should be simple (bnc#768624)
      p_alias = [p.display_name, p.name, "repo"].reject(&:empty?).first
      Ops.set(
        @aliases,
        u,
        String.Replace(
          Ops.add(
            "update-",
            p_alias
          ),
          " ",
          "-"
        )
      )
    end
  end

  deep_copy(urls)
end