Class: Yast::PackagesProposalClass

Inherits:
Module
  • Object
show all
Defined in:
../../library/general/src/modules/PackagesProposal.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) AddResolvables(unique_ID, type, resolvables)

Adds list of resolvables to pool that is then used by software proposal to propose a selection of resolvables to install.

Examples:

AddResolvables ("y2_kdump", `package, ["yast2-kdump", "kdump"]) -> true
// `not_supported is definitely not a supported resolvable
AddResolvables ("test", `not_supported, ["bash"]) -> false

Parameters:

  • unique_ID (String)
  • symbol

    resolvable type

  • list (string)

    of resolvables to add for installation

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #RemoveResolvables()


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
# File '../../library/general/src/modules/PackagesProposal.rb', line 147

def AddResolvables(unique_ID, type, resolvables)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_ID, type)

  CreateEmptyStructureIfMissing(unique_ID, type)

  if resolvables.nil?
    Builtins.y2warning("Changing resolvables %1 to empty list", resolvables)
    resolvables = []
  end

  Builtins.y2milestone(
    "Adding resolvables %1 type %2 for %3",
    resolvables,
    type,
    unique_ID
  )
  Ops.set(
    @resolvables_to_install,
    [unique_ID, type],
    Convert.convert(
      Builtins.union(
        Ops.get(@resolvables_to_install, [unique_ID, type], []),
        resolvables
      ),
      from: "list",
      to:   "list <string>"
    )
  )

  true
end

- (Boolean) CheckParams(unique_ID, type)

Checks parameters for global functions

Parameters:

  • unique_ID (String)
  • type (Symbol)

Returns:

  • (Boolean)

    if parameters are correct



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File '../../library/general/src/modules/PackagesProposal.rb', line 114

def CheckParams(unique_ID, type)
  if unique_ID.nil? || unique_ID == ""
    Builtins.y2error("Unique ID cannot be: %1", unique_ID)
    return false
  end

  if !IsSupportedResolvableType(type)
    Builtins.y2error(
      "Not a supported type: %1, supported are only: %2",
      type,
      @supported_resolvables
    )
    return false
  end

  true
end

- (Object) CreateEmptyStructureIfMissing(unique_ID, type)

Checks the currently created data structure and creates missing keys if needed.

Parameters:

  • unique_ID (String)
  • type (Symbol)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File '../../library/general/src/modules/PackagesProposal.rb', line 88

def CreateEmptyStructureIfMissing(unique_ID, type)
  if !Builtins.haskey(@resolvables_to_install, unique_ID)
    Builtins.y2debug(
      "Creating '%1' key in resolvables_to_install",
      unique_ID
    )
    Ops.set(@resolvables_to_install, unique_ID, {})
  end

  if !Builtins.haskey(Ops.get(@resolvables_to_install, unique_ID, {}), type)
    Builtins.y2debug(
      "Creating '%1' key in resolvables_to_install[%2]",
      type,
      unique_ID
    )
    Ops.set(@resolvables_to_install, [unique_ID, type], [])
  end

  nil
end

- (Array<String>) GetAllResolvables(type)

Returns list of selected resolvables of a given type

Examples:

GetAllResolvables (`package) -> ["list", "of", "packages"]
GetAllResolvables (`pattern) -> ["list", "of", "patterns"]
// not a supported resolvable type
GetAllResolvables (`unknown) -> nil

Parameters:

  • symbol

    resolvable type

Returns:

  • (Array<String>)

    list of resolvables

See Also:

  • #supported_resolvables


281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File '../../library/general/src/modules/PackagesProposal.rb', line 281

def GetAllResolvables(type)
  if !IsSupportedResolvableType(type)
    Builtins.y2error(
      "Not a supported type: %1, supported are only: %2",
      type,
      @supported_resolvables
    )
    return nil
  end

  ret = []

  Builtins.foreach(@resolvables_to_install) do |_unique_ID, resolvables|
    if Builtins.haskey(resolvables, type)
      ret = Builtins.sort(
        Convert.convert(
          Builtins.union(ret, Ops.get(resolvables, type, [])),
          from: "list",
          to:   "list <string>"
        )
      )
    end
  end

  deep_copy(ret)
end

- (Hash{Symbol => Array<String>}) GetAllResolvablesForAllTypes

Returns all selected resolvables for all supported types

Structure:

$[
   `resolvable_type : [ "list", "of", "resolvables" ],
   `another_type    : [ "list", "of", "resolvables" ],
 ]

// No resolvables selected GetAllResolvablesForAllTypes() -> $[] // Only patterns selected GetAllResolvablesForAllTypes() -> $[pattern : ["some", "patterns"]] // Also packages selected GetAllResolvablesForAllTypes() -> $[ pattern : [“some”, “patterns”], `package : [“some”, “packages”], ]

Returns:

  • (Hash{Symbol => Array<String>})

    map of resolvables



329
330
331
332
333
334
335
336
337
338
339
340
341
# File '../../library/general/src/modules/PackagesProposal.rb', line 329

def GetAllResolvablesForAllTypes
  ret = {}
  resolvables = []

  Builtins.foreach(GetSupportedResolvables()) do |one_type|
    resolvables = GetAllResolvables(one_type)
    if !resolvables.nil? && resolvables != []
      Ops.set(ret, one_type, resolvables)
    end
  end

  deep_copy(ret)
end

- (Array<String>) GetResolvables(unique_ID, type)

Returns all resolvables selected for installation.

Examples:

GetResolvables ("y2_kdump", `package) -> ["yast2-kdump", "kdump"]

Parameters:

  • unique_ID (String)
  • symbol

    resolvable type

Returns:

  • (Array<String>)

    of resolvables



263
264
265
266
267
# File '../../library/general/src/modules/PackagesProposal.rb', line 263

def GetResolvables(unique_ID, type)
  return nil if !CheckParams(unique_ID, type)

  Ops.get(@resolvables_to_install, [unique_ID, type], [])
end

- (Array<Symbol>) GetSupportedResolvables

Returns list of resolvables currently supported by this module.

Examples:

GetSupportedResolvables() -> [package,pattern, … ]

Returns:

  • (Array<Symbol>)

    of resolvables



70
71
72
# File '../../library/general/src/modules/PackagesProposal.rb', line 70

def GetSupportedResolvables
  deep_copy(@supported_resolvables)
end

- (Object) IsSupportedResolvableType(type)



74
75
76
77
78
79
80
81
# File '../../library/general/src/modules/PackagesProposal.rb', line 74

def IsSupportedResolvableType(type)
  if type.nil?
    Builtins.y2error("Wrong type: %1", type)
    return false
  end

  Builtins.contains(@supported_resolvables, type)
end

- (Boolean) IsUniqueID(unique_ID)

Return whether a unique ID is already in use.

Parameters:

  • unique_ID (String)

    to check

Returns:

  • (Boolean)

    whether the ID is not in use yet



347
348
349
350
351
352
353
354
# File '../../library/general/src/modules/PackagesProposal.rb', line 347

def IsUniqueID(unique_ID)
  if unique_ID.nil? || unique_ID == ""
    Builtins.y2error("Unique ID cannot be: %1", unique_ID)
    return nil
  end

  !Builtins.haskey(@resolvables_to_install, unique_ID)
end

- (Object) main



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File '../../library/general/src/modules/PackagesProposal.rb', line 34

def main
  textdomain "base"

  #
  # **Structure:**
  #
  #     $[
  #          "unique_ID" : $[
  #              `package : [ "list", "of", "packages", "to", "install" ],
  #              `pattern : [ "list", "of", "patterns", "to", "install" ],
  #          ]
  #      ]
  @resolvables_to_install = {}

  # List of currently supported types of resolvables
  @supported_resolvables = [:package, :pattern]
end

- (Boolean) RemoveResolvables(unique_ID, type, resolvables)

Removes list of packages from pool that is then used by software proposal to propose a selection of resolvables to install.

Examples:

RemoveResolvables ("y2_kdump", `package, ["kdump"]) -> true

Parameters:

  • unique_ID (String)
  • symbol

    resolvable type

  • list (string)

    of resolvables to remove from list selected for installation

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #AddResolvables()


223
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
# File '../../library/general/src/modules/PackagesProposal.rb', line 223

def RemoveResolvables(unique_ID, type, resolvables)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_ID, type)

  CreateEmptyStructureIfMissing(unique_ID, type)

  if resolvables.nil?
    Builtins.y2warning("Changing resolvables %1 to empty list", resolvables)
    resolvables = []
  end

  Builtins.y2milestone(
    "Removing resolvables %1 type %2 for %3",
    resolvables,
    type,
    unique_ID
  )
  Ops.set(
    @resolvables_to_install,
    [unique_ID, type],
    Builtins.filter(Ops.get(@resolvables_to_install, [unique_ID, type], [])) do |one_resolvable|
      !Builtins.contains(resolvables, one_resolvable)
    end
  )
  Builtins.y2milestone(
    "Resolvables left: %1",
    Ops.get(@resolvables_to_install, [unique_ID, type], [])
  )

  true
end

- (Object) ResetAll

Resets all resolvables to install. Use carefully.



53
54
55
56
57
58
59
60
61
62
63
# File '../../library/general/src/modules/PackagesProposal.rb', line 53

def ResetAll
  if @resolvables_to_install != {}
    Builtins.y2warning("Reseting all PackagesProposal items")
  else
    Builtins.y2milestone("Reseting all PackagesProposal items")
  end

  @resolvables_to_install = {}

  nil
end

- (Boolean) SetResolvables(unique_ID, type, resolvables)

Replaces the current resolvables with new ones. Similar to AddResolvables() but it replaces the list of resolvables instead of adding them to the pool. It always replaces only the part that is identified by the unique_ID.

Parameters:

  • unique_ID (String)
  • symbol

    resolvable type

  • list (string)

    of resolvables to add for installation

Returns:

  • (Boolean)

    whether successful



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File '../../library/general/src/modules/PackagesProposal.rb', line 188

def SetResolvables(unique_ID, type, resolvables)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_ID, type)

  CreateEmptyStructureIfMissing(unique_ID, type)

  if resolvables.nil?
    Builtins.y2warning("Changing resolvables %1 to empty list", resolvables)
    resolvables = []
  end

  Builtins.y2milestone(
    "Adjusting resolvables %1 type %2 for %3",
    resolvables,
    type,
    unique_ID
  )
  Ops.set(@resolvables_to_install, [unique_ID, type], resolvables)

  true
end