Module: Yast::PackagesCommonInclude

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

Instance Method Summary collapse

Instance Method Details

#AskPackages(packs, install) ⇒ Object



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

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)



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

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)



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

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



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

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



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

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

#InstallAll(packages) ⇒ Object



213
214
215
216
# File 'library/packages/src/include/packages/common.rb', line 213

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



186
187
188
189
# File 'library/packages/src/include/packages/common.rb', line 186

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



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

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



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

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



178
179
180
# File 'library/packages/src/include/packages/common.rb', line 178

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



231
232
233
# File 'library/packages/src/include/packages/common.rb', line 231

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



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

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

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

  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



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

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

#RemoveAll(packages) ⇒ Object



223
224
225
226
# File 'library/packages/src/include/packages/common.rb', line 223

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



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

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



196
197
198
# File 'library/packages/src/include/packages/common.rb', line 196

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