Class: Yast::PackageInstallationClass

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

Overview

Perfoms package installation

Instance Method Summary collapse

Instance Method Details

#Commit(config) ⇒ Array

commitPackages marked for deletion or installation

Returns:

  • (Array)

    containing [ int successful, list failed, list remaining, list srcremaining, list update_messages ]


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

def Commit(config)
  config = deep_copy(config)
  if Mode.test
    FakePackager([], "suse", false) # not deleting packages
    return []
  end
  # install packages from this media

  PackageSlideShow.InitPkgData(false)

  # structure: [ ["source_name", id] ]
  src_list = Pkg.PkgMediaNames

  # get ID of the first repository
  first_source = Ops.get_integer(src_list, [0, 1], 1)

  Builtins.y2milestone("ID of the first repository: %1", first_source)

  if Ops.get_integer(config, "medium_nr", 0).zero?
    PackageSlideShow.SetCurrentCdNo(first_source, 1)
  else
    PackageSlideShow.SetCurrentCdNo(
      first_source,
      Ops.get_integer(config, "medium_nr", 0)
    )
  end
  PackageSlideShow.UpdateAllCdProgress(false)
  SlideShow.StartTimer

  start_time = Yast2::SystemTime.uptime

  # returns [ int successful, list failed, list remaining, list srcremaining ]
  Builtins.y2milestone("Calling Pkg::Commit (%1)", config)
  commit_result = Pkg.Commit(config)

  SlideShow.StopTimer

  if commit_result.nil?
    Builtins.y2error("Commit failed: %1", Pkg.LastError)
    return []
  end

  installation_time = Yast2::SystemTime.uptime - start_time
  Builtins.y2milestone(
    "Installation took %1 seconds, commit result: %2",
    installation_time,
    commit_result
  )

  # see if installation of some packages failed
  errpacks = Ops.get_list(commit_result, 1, [])
  if Ops.greater_than(Builtins.size(errpacks), 0)
    full_log = Ops.get_string(
      PackagesUI.GetPackageSummary,
      "install_log",
      ""
    )
    ShowFailedPackages(Builtins.mergestring(errpacks, "\n"), full_log)

    old_failed_packs = []
    if Ops.greater_than(
      Convert.to_integer(
        SCR.Read(path(".target.size"), "/var/lib/YaST2/failed_packages")
      ),
      0
    )
      old_failed_packs = Convert.convert(
        SCR.Read(path(".target.ycp"), "/var/lib/YaST2/failed_packages"),
        from: "any",
        to:   "list <string>"
      )
    end
    SCR.Write(
      path(".target.ycp"),
      "/var/lib/YaST2/failed_packages",
      Builtins.merge(old_failed_packs, errpacks)
    )
  end

  PackagesUI.show_update_messages(commit_result) unless Mode.installation || Mode.autoinst

  if Mode.normal
    # collect and set installation summary data
    summary = PackageSlideShow.GetPackageSummary

    Ops.set(summary, "time_seconds", installation_time)
    Ops.set(summary, "success", Builtins.size(errpacks).zero?)
    Ops.set(summary, "remaining", package_names(commit_result[2] || []))
    Ops.set(summary, "install_log", SlideShow.inst_log)

    if Ops.greater_than(Builtins.size(errpacks), 0)
      Ops.set(summary, "error", Pkg.LastError)
      Ops.set(summary, "failed", errpacks)
    end

    if commit_result == [-1]
      Ops.set(summary, "error", _("Installation aborted by user."))
      Ops.set(summary, "success", false)
    end

    PackagesUI.SetPackageSummary(summary)
  end

  deep_copy(commit_result)
end

#CommitPackages(media_number, packages_installed) ⇒ Array

commitPackages marked for deletion or installation

Returns:

  • (Array)

    with content [ int successful, list failed, list remaining, list srcremaining, list update_messages ]


207
208
209
210
211
212
213
214
215
216
# File 'src/modules/PackageInstallation.rb', line 207

def CommitPackages(media_number, packages_installed)
  # this is a backward compatible wrapper for Commit()
  Builtins.y2milestone(
    "CommitPackages (%1,%2): Pkg::TargetGetDU() %3",
    media_number,
    packages_installed,
    Pkg.TargetGetDU
  )
  Commit("medium_nr" => media_number)
end

#DownloadInAdvanceObject


27
28
29
# File 'src/modules/PackageInstallation.rb', line 27

def DownloadInAdvance
  @download_in_advance
end

#FakePackager(packages, _inst_source, _deleting) ⇒ Object

Fake progress bars for Mode::test ()

NOTE: This is currently completely broken. – sh 2003-12-15


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

def FakePackager(packages, _inst_source, _deleting)
  packages = deep_copy(packages)
  disk_usage = 20
  ret = nil
  number = 0

  Builtins.y2debug(
    "FakePackager - handling %1 packages",
    Builtins.size(packages)
  )

  Builtins.foreach(packages) do |_pac|
    pkg_size = 42 * 1024
    bytes_installed = 0
    if Ops.less_than(pkg_size, 0)
      # pkginfo doesn't know anything about the kernel RPM, so its
      # size can't be obtained, e.g. pkg_size is -1. To make up for
      # this, let's assume a negative starting size to keep things
      # going for a while (this is test_mode only, anyway).
      bytes_installed = -857 * 1024
    end
    while Ops.less_than(bytes_installed, pkg_size) && ret != :cancel &&
        ret != :diskfull
      Builtins.sleep(300) # millisec
      bytes_installed = Ops.add(bytes_installed, 300 * 1024)
    end
    disk_usage = Ops.add(disk_usage, 1)
    number = Ops.add(number, 1)
  end

  ret = if ret == :cancel || ret == :abort
    :cancel
  elsif ret == :diskfull
    :diskfull
  else
    :ok
  end

  Builtins.y2debug("FakePackager returning with %1", ret)
  deep_copy(ret)
end

#mainObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'src/modules/PackageInstallation.rb', line 9

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

  Yast.import "Mode"
  Yast.import "Installation"
  Yast.import "Directory"
  Yast.import "Packages"
  Yast.import "SlideShow"
  Yast.import "PackageSlideShow"
  Yast.import "PackagesUI"

  Yast.import "Label"

  @download_in_advance = nil
end

#SetDownloadInAdvance(enable) ⇒ Object


31
32
33
34
35
# File 'src/modules/PackageInstallation.rb', line 31

def SetDownloadInAdvance(enable)
  @download_in_advance = enable

  nil
end

#ShowFailedPackages(a, b) ⇒ Object

Show a dialog with either the list of failed packages (string a) or

the complete log (string b).

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

def ShowFailedPackages(a, b)
  rbuttons = RadioButtonGroup(
    VBox(
      Left(
        RadioButton(
          Id(:a),
          Opt(:notify),
          # button label
          _("&Show Failed Packages List"),
          true
        )
      ),
      Left(
        RadioButton(
          Id(:b),
          Opt(:notify),
          # button label
          _("&Show Full Log"),
          false
        )
      )
    )
  )

  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HSpacing(40),
      # dialog headline
      Left(Heading(_("Installation of some Packages Failed"))),
      rbuttons,
      RichText(Id(:text), Opt(:plainText), a),
      PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton)
    )
  )

  loop do
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :a || ret == :b
      UI.ChangeWidget(
        Id(:text),
        :Value,
        Convert.to_boolean(UI.QueryWidget(Id(:a), :Value)) ? a : b
      )
      next
    end

    break if ret == :ok
  end

  UI.CloseDialog

  nil
end