Module: Yast::PackagesCommonInclude

Defined in:
library/packages/src/include/packages/common.rb

Instance Method Summary collapse

Instance Method Details

#AskPackages(packs, install) ⇒ Object


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'library/packages/src/include/packages/common.rb', line 99

def AskPackages(packs, install)
  packs = deep_copy(packs)
  pkgs = Builtins.mergestring(packs, ", ")
  text = if install
    # the message is followed by list of required packages
    _("These packages need to be installed:")
  else
    # the message is followed by list of required packages
    _("These packages need to be removed:")
  end

  text += " " + pkgs

  CommandLine.Print(text)

  CommandLine.YesNo
end

#AvailableAll(packages) ⇒ Boolean

Are all of these packages available?

Parameters:

  • packages (Array<String>)

    list of packages

Returns:

  • (Boolean)

    true if yes (nil = an error occurred)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'library/packages/src/include/packages/common.rb', line 48

def AvailableAll(packages)
  packages = deep_copy(packages)
  error = false

  which = Builtins.find(packages) do |p|
    avail = Available(p)
    error = true if avail.nil?
    !avail
  end

  return nil if error

  which.nil?
end

#AvailableAny(packages) ⇒ Boolean

Is any of these packages available?

Parameters:

  • packages (Array<String>)

    list of packages

Returns:

  • (Boolean)

    true if yes (nil = an error occurred)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'library/packages/src/include/packages/common.rb', line 66

def AvailableAny(packages)
  packages = deep_copy(packages)
  error = false

  which = Builtins.find(packages) do |p|
    avail = Available(p)
    error = true if avail.nil?
    avail
  end

  return nil if error

  !which.nil?
end

#initialize_packages_common(_include_target) ⇒ Object


35
36
37
38
39
40
41
42
43
# File 'library/packages/src/include/packages/common.rb', line 35

def initialize_packages_common(_include_target)
  textdomain "base"

  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Wizard"
  Yast.import "Mode"
  Yast.import "CommandLine"
end

#Install(package) ⇒ Object


206
207
208
# File 'library/packages/src/include/packages/common.rb', line 206

def Install(package)
  InstallMsg(package, nil)
end

#InstallAll(packages) ⇒ Object


210
211
212
213
# File 'library/packages/src/include/packages/common.rb', line 210

def InstallAll(packages)
  packages = deep_copy(packages)
  InstallAllMsg(packages, nil)
end

#InstallAllMsg(packages, message) ⇒ Object

Install list of packages with a custom text message

Parameters:

  • packages (Array<String>)

    The list packages to be installed

  • message (String)

    custom text message

Returns:

  • True on success


183
184
185
186
# File 'library/packages/src/include/packages/common.rb', line 183

def InstallAllMsg(packages, message)
  packages = deep_copy(packages)
  PackageDialog(packages, true, message)
end

#InstalledAll(packages) ⇒ Boolean

Are all of these packages installed?

Parameters:

  • packages (Array<String>)

    list of packages

Returns:

  • (Boolean)

    true if yes


84
85
86
87
88
# File 'library/packages/src/include/packages/common.rb', line 84

def InstalledAll(packages)
  packages = deep_copy(packages)
  which = Builtins.find(packages) { |p| !Installed(p) }
  which.nil?
end

#InstalledAny(packages) ⇒ Boolean

Is any of these packages installed?

Parameters:

  • packages (Array<String>)

    list of packages

Returns:

  • (Boolean)

    true if yes


93
94
95
96
97
# File 'library/packages/src/include/packages/common.rb', line 93

def InstalledAny(packages)
  packages = deep_copy(packages)
  which = Builtins.find(packages) { |p| Installed(p) }
  !which.nil?
end

#InstallMsg(package, message) ⇒ Object

Install a package with a custom text message

Parameters:

  • package (String)

    to be installed

  • message (String)

    custom text message

Returns:

  • True on success


175
176
177
# File 'library/packages/src/include/packages/common.rb', line 175

def InstallMsg(package, message)
  PackageDialog([package], true, message)
end

#LastOperationCanceledObject

Return result of the last operation Use immediately after calling any Package*:: function

Returns:

  • true if it last operation was canceled


228
229
230
# File 'library/packages/src/include/packages/common.rb', line 228

def LastOperationCanceled
  @last_op_canceled
end

#PackageDialog(packages, install, message) ⇒ Object

Main package installatio|removal dialog

Parameters:

  • packages (Array<String>)

    list of packages

  • install (Boolean)

    true if install, false if remove

  • message (String)

    optional installation|removal text (nil -> standard will be used)

Returns:

  • true on success


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
# File 'library/packages/src/include/packages/common.rb', line 122

def PackageDialog(packages, install, message)
  packages = deep_copy(packages)
  Builtins.y2debug("Asking for packages: %1", packages)
  packs = Builtins.filter(packages) do |package|
    install ? !Installed(package) : Installed(package)
  end
  Builtins.y2debug("Remaining packages: %1", packs)

  return true if Ops.less_than(Builtins.size(packs), 1)

  # Popup Text
  text = _("These packages need to be installed:") + "<p>"
  # Popup Text
  text = _("These packages need to be removed:") + "<p>" if install == false

  Builtins.foreach(packs) do |p|
    text = Ops.add(text, Builtins.sformat("%1<br>", p))
  end

  text = Builtins.sformat(message, Builtins.mergestring(packs, ", ")) if !message.nil?

  doit = if Mode.commandline
    CommandLine.Interactive ? AskPackages(packs, install) : true
  else
    Popup.AnyQuestionRichText(
      "",
      text,
      40,
      10,
      # labels changed for bug #215195
      #  Label::ContinueButton (), Label::CancelButton (),
      # push button label
      install ? Label.InstallButton : _("&Uninstall"),
      Label.CancelButton,
      :focus_yes
    )
  end

  if doit
    @last_op_canceled = false
    return DoRemove(packs) if install == false

    return DoInstall(packs)
  end

  @last_op_canceled = true
  false
end

#Remove(package) ⇒ Object

FIXME


216
217
218
# File 'library/packages/src/include/packages/common.rb', line 216

def Remove(package)
  RemoveMsg(package, nil)
end

#RemoveAll(packages) ⇒ Object


220
221
222
223
# File 'library/packages/src/include/packages/common.rb', line 220

def RemoveAll(packages)
  packages = deep_copy(packages)
  RemoveAllMsg(packages, nil)
end

#RemoveAllMsg(packages, message) ⇒ Object

Remove a list of packages with a custom text message

Parameters:

  • packages (Array<String>)

    The list of packages to be removed

  • message (String)

    custom text message

Returns:

  • True on success


201
202
203
204
# File 'library/packages/src/include/packages/common.rb', line 201

def RemoveAllMsg(packages, message)
  packages = deep_copy(packages)
  PackageDialog(packages, false, message)
end

#RemoveMsg(package, message) ⇒ Object

Remove a package with a custom text message

Parameters:

  • package (String)

    package to be removed

  • message (String)

    custom text message

Returns:

  • True on success


193
194
195
# File 'library/packages/src/include/packages/common.rb', line 193

def RemoveMsg(package, message)
  PackageDialog([package], false, message)
end