Module: Yast::PackagerRepositoriesIncludeInclude

Includes:
Logger
Defined in:
src/include/packager/repositories_include.rb

Overview

Include file to be shared by yast2-packager and yast2-add-on

Constant Summary collapse

PLAINDIR_TYPE =

constant Plaindir

"Plaindir".freeze
SHELL_UNFRIENDLY =

shell unfriendly characters we want to remove from alias, so it is easier to use with zypper

"()/!'\"*?;&|<>{}$#`".freeze

Instance Method Summary collapse

Instance Method Details

#autorefresh_for?(url) ⇒ Boolean

Evaluate the default autorefresh flag for the given repository URL.


327
328
329
330
331
332
333
334
335
# File 'src/include/packager/repositories_include.rb', line 327

def autorefresh_for?(url)
  protocol = URL.Parse(url)["scheme"].downcase

  # disable autorefresh for local repositories ,
  autorefresh = !Pkg.UrlSchemeIsLocal(protocol)

  log.info "Autorefresh flag for '#{protocol}' URL protocol: #{autorefresh}"
  autorefresh
end

#createSource(url, plaindir, download, preffered_name) ⇒ Object

start createSource() function in extra wizard dialog


214
215
216
# File 'src/include/packager/repositories_include.rb', line 214

def createSource(url, plaindir, download, preffered_name)
  createSourceWithAlias(url, plaindir, download, preffered_name, "")
end

#createSourceImpl(url, plaindir, download, preffered_name, force_alias) ⇒ Symbol

Create a new repository or service.


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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'src/include/packager/repositories_include.rb', line 59

def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
  log.info("createSource: #{URL.HidePassword(url)}, plaindir: #{plaindir}," \
    "download: #{download}, name: #{preffered_name}, force_alias: #{force_alias}")

  if url.nil? || url.empty?
    Builtins.y2error(-1, "Empty URL! Backtrace:")
    return :again
  end

  expanded_url = Pkg.ExpandedUrl(url)

  if expanded_url.nil?
    # TRANSLATORS: Error message, %{url} is replaced by the real URL
    Report.Error(_("Invalid URL:\n%{url}") % { url: url })
    return :again
  end

  # for Plaindir repository we have to use SourceCreateType() binding
  parsed = URL.Parse(url)
  scheme = parsed["scheme"].downcase

  # check if the URL can be accessed/mounted, install the missing packages
  install_mount_package(scheme)

  initialize_progress

  Progress.NextStage
  service_type = Pkg.ServiceProbe(expanded_url)
  Builtins.y2milestone("Probed service type: %1", service_type)

  # create a new service if a service is detected at the URL
  if ![nil, "NONE"].include?(service_type)
    add_service(url, preffered_name)
    return :ok
  end

  found_products = scan_products(expanded_url, url)
  newSources = []

  enter_again = false

  # more products on the medium, let the user choose the products to install
  # this code is not used in AutoYaST, but rather be on the safe side...
  if !Mode.auto && found_products.size > 1
    require "y2packager/dialogs/addon_selector"
    dialog = Y2Packager::Dialogs::AddonSelector.new(found_products)

    ui = dialog.run
    found_products = dialog.selected_products

    # pressed abort/cancel/close/back/...
    return ui if ui != :next

    # nothing selected, just skip adding the repos and continue in the workflow
    return :next if found_products.empty?
  end

  found_products.each do |product|
    next if enter_again
    name = !preffered_name.nil? && preffered_name != "" ? preffered_name : product.name
    # probe repository type (do not probe plaindir repo)
    repo_type = plaindir ? PLAINDIR_TYPE : Pkg.RepositoryProbe(expanded_url, product.dir)
    log.info("Repository type (#{URL.HidePassword(url)},#{product.dir}): #{repo_type}")

    # the probing has failed
    if repo_type.nil? || repo_type == "NONE"
      if scheme == "dir"
        if !confirm_plain_repo
          enter_again = true
          next
        end

        repo_type = PLAINDIR_TYPE
        log.info("Probing has failed, using Plaindir repository type.")
      end

      next
    end

    alias_name = (force_alias == "") ? propose_alias(product.name) : force_alias

    # map with repository parameters: $[ "enabled" : boolean,
    # "autorefresh" : boolean, "name" : string, "alias" : string,
    # "base_urls" : list<string>, "prod_dir" : string, "type" : string ]
    repo_prop = {
      "enabled"     => true,
      "autorefresh" => autorefresh_for?(url),
      "name"        => name,
      "prod_dir"    => product.dir,
      "alias"       => alias_name,
      "base_urls"   => [url],
      "type"        => repo_type
    }
    if force_alias != ""
      # don't check uniqueness of the alias, force the alias
      repo_prop["check_alias"] = false
    end
    Progress.NextStage
    new_repo_id = Pkg.RepositoryAdd(repo_prop)

    # hide the URL password in the log
    repo_prop_log = deep_copy(repo_prop)
    repo_prop_log["base_urls"] = [URL.HidePassword(url)]
    log.info("Added repository: #{new_repo_id}: #{repo_prop_log}")

    newSources << new_repo_id

    # for local repositories (e.g. CD/DVD) which have autorefresh disabled
    # download the metadata immediately, the medium is in the drive right
    # now, it can be changed later and accidentally added a different repository
    if !autorefresh_for?(url)
      log.info "Adding a local repository, refreshing it now..."
      Pkg.SourceRefreshNow(new_repo_id)
    end
  end

  # broken repository or wrong URL - enter the URL again
  return :again if enter_again

  log.info("New sources: #{newSources}")

  if newSources.empty?
    log.error("Cannot add the repository")
    try_again(url, scheme) ? :again : :cancel
  else
    Progress.NextStage
    license_accepted = true
    Builtins.foreach(newSources) do |id|
      if !LicenseAccepted(id)
        log.info("License NOT accepted, removing the source")
        Pkg.SourceDelete(id)
        license_accepted = false
      else
        src_data = Pkg.SourceGeneralData(id)
        log.info("Addded repository: #{src_data}")

        sourceState = {
          "SrcId"       => id,
          "enabled"     => src_data["enabled"],
          "autorefresh" => src_data["autorefresh"],
          "name"        => src_data["name"],
          "do_refresh"  => download
        }
        @sourceStatesOut << sourceState
      end
    end

    license_accepted ? :ok : :abort
  end
ensure
  # relese (unmount) the medium
  Pkg.SourceReleaseAll
end

#createSourceWithAlias(url, plaindir, download, preffered_name, alias_name) ⇒ Object

create source with alias IMPORTANT: make sure the alias is unique!! Otherwise the repo will be overwritten!!


220
221
222
223
224
225
# File 'src/include/packager/repositories_include.rb', line 220

def createSourceWithAlias(url, plaindir, download, preffered_name, alias_name)
  Wizard.CreateDialog
  ret = createSourceImpl(url, plaindir, download, preffered_name, alias_name)
  Wizard.CloseDialog
  ret
end

#EditDialogObject


320
321
322
# File 'src/include/packager/repositories_include.rb', line 320

def EditDialog
  SourceDialogs.EditDialog
end

#initialize_packager_repositories_include(_include_target) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'src/include/packager/repositories_include.rb', line 16

def initialize_packager_repositories_include(_include_target)
  Yast.import "Pkg"
  Yast.import "Stage"
  Yast.import "Wizard"
  Yast.import "AddOnProduct"
  Yast.import "URL"
  Yast.import "PackageSystem"
  Yast.import "Popup"
  Yast.import "Label"
  Yast.import "SourceDialogs"
  Yast.import "Report"
  Yast.import "Progress"

  textdomain "packager"

  @sourceStatesIn = []
  @sourceStatesOut = []

  @serviceStatesIn = []
  @serviceStatesOut = []

  @download_meta = true
end

#LicenseAccepted(id) ⇒ Object


40
41
42
# File 'src/include/packager/repositories_include.rb', line 40

def LicenseAccepted(id)
  AddOnProduct.AcceptedLicenseAndInfoFile(id)
end

#StoreSourceObject


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'src/include/packager/repositories_include.rb', line 227

def StoreSource
  url = SourceDialogs.GetURL
  name = SourceDialogs.GetRepoName
  plaindir = SourceDialogs.IsPlainDir

  # special case, bugzilla #238680
  if url == "slp://"
    required_package = "yast2-slp"
    installed_before = PackageSystem.Installed(required_package)

    if !Stage.initial && !installed_before
      # Tries to Check and Install packages
      if !PackageSystem.CheckAndInstallPackagesInteractive(
        [required_package]
      ) ||
          !PackageSystem.Installed(required_package)
        Report.Error(
          Builtins.sformat(
            # popup error message, %1 is the package name
            _(
              "Cannot search for SLP repositories\nwithout having %1 package installed.\n"
            ),
            required_package
          )
        )
        Builtins.y2warning("Not searching for SLP repositories")
        return :back
        # New .slp agent has been added
        # FIXME: lazy loading of agents will make this obsolete
      else
        SCR.RegisterAgent(path(".slp"), term(:ag_slp, term(:SlpAgent)))
      end
    end

    service = Convert.to_string(WFM.call("select_slp_source"))

    if service.nil?
      Builtins.y2milestone("No SLP service selected, returning back...")
      return :back
    else
      url = service
    end
  elsif url == "commrepos://"
    commrepos = WFM.call(
      "inst_productsources",
      [{ "skip_already_used_repos" => true }]
    )
    Builtins.y2milestone("Community Repositories returned: %1", commrepos)

    if commrepos == :abort || commrepos == :cancel
      Builtins.y2milestone("Using CR have been canceled")
      return :back
    end

    return :next
  elsif url == "sccrepos://"
    sccrepos = WFM.call("inst_scc", ["select_extensions"])
    Builtins.y2milestone("Registration Repositories returned: %1", sccrepos)

    return sccrepos == :abort || sccrepos == :cancel ? :back : :next
  end

  ret = createSource(url, plaindir, @download_meta, name)

  case ret
  when :again
    :back
  when :abort, :cancel
    :abort
  when :next
    :next
  else
    log.warn "Received unknown result: #{ret}, using :next instead"
    :next
  end
end

#TypeDialogObject


315
316
317
318
# File 'src/include/packager/repositories_include.rb', line 315

def TypeDialog
  # download metadata, reset the stored URL
  TypeDialogOpts(true, "")
end

#TypeDialogOpts(download, url) ⇒ Object


304
305
306
307
308
309
310
311
312
313
# File 'src/include/packager/repositories_include.rb', line 304

def TypeDialogOpts(download, url)
  SourceDialogs.SetDownloadOption(download)
  SourceDialogs.SetURL(url)

  td = SourceDialogs.TypeDialogDownloadOpt

  ret = Ops.get_symbol(td, "ui", :next)
  @download_meta = Ops.get_boolean(td, "download", true)
  ret
end