Class: Yast::PackagesProposalClass

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

Overview

API for selecting or de-selecting packages or patterns for installation. It stores two separate lists, one for required resolvables and the other one for optional resolvables. The optional resolvables can be deselected by user manually and the installation proposal will not complain that they are missing.

Instance Method Summary collapse

Instance Method Details

#AddResolvables(unique_id, type, resolvables, optional: false) ⇒ Boolean

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

  • optional (Boolean) (defaults to: false)

    True for optional list, false (the default) for the required list

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #RemoveResolvables()


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'library/general/src/modules/PackagesProposal.rb', line 118

def AddResolvables(unique_id, type, resolvables, optional: false)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_id, type)

  if resolvables.nil?
    log.info("Using empty list instead of nil")
    resolvables = []
  end

  log.info("Adding #{log_label(optional)} #{resolvables.inspect} of type #{type} for #{unique_id}")

  current_resolvables = data_for(unique_id, type, data(optional))
  current_resolvables.concat(resolvables)

  true
end

#AddTaboos(unique_id, type, resolvables) ⇒ Boolean

Adds a list of resolvables to not be installed

Parameters:

  • unique_id (String)

    the unique identificator

  • type (Symbol)

    resolvable type

  • resolvables (Array<String>)

    list of resolvables to taboo

Returns:

  • (Boolean)

    whether successful



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'library/general/src/modules/PackagesProposal.rb', line 203

def AddTaboos(unique_id, type, resolvables)
  return false if !CheckParams(unique_id, type)

  log.info("Taboo #{resolvables.inspect} for #{unique_id}}")

  # Remove the resolvable from the list of resolvables to install....
  RemoveResolvables(unique_id, type, resolvables)
  # ... and from the optional list too
  RemoveResolvables(unique_id, type, resolvables, optional: true)

  data_for(unique_id, type, @taboos).concat(resolvables)
  log.info("Adding taboos #{resolvables.inspect} of type #{type} for #{unique_id}")

  true
end

#CheckParams(unique_id, type) ⇒ Boolean

Checks parameters for global functions

Parameters:

  • unique_id (String)
  • type (Symbol)

Returns:

  • (Boolean)

    if parameters are correct



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/general/src/modules/PackagesProposal.rb', line 87

def CheckParams(unique_id, type)
  if unique_id.nil? || unique_id == ""
    log.error("Unique ID cannot be: #{unique_id.inspect}")
    return false
  end

  if !IsSupportedResolvableType(type)
    log.error("Not a supported type: #{type}")
    return false
  end

  true
end

#GetAllResolvables(type, optional: false) ⇒ Array<String>

Returns list of selected resolvables of a given type

Examples:

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

Parameters:

  • type (Symbol)

    resolvables type

  • optional (Boolean) (defaults to: false)

    True for optional list, false (the default) for the required list

Returns:

  • (Array<String>)

    list of resolvables

See Also:

  • #supported_resolvables


305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'library/general/src/modules/PackagesProposal.rb', line 305

def GetAllResolvables(type, optional: false)
  if !IsSupportedResolvableType(type)
    log.error("Not a supported type: #{type}, supported are only: #{@supported_resolvables}")
    return nil
  end

  ret = []

  data(optional).each_value do |resolvables|
    ret.concat(resolvables[type]) if resolvables.key?(type)
  end

  # sort the result and remove the duplicates
  ret.sort!
  ret.uniq!

  ret
end

#GetAllResolvablesForAllTypes(optional: false) ⇒ Hash{Symbol => Array<String>}

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"], ]

Parameters:

  • optional (Boolean) (defaults to: false)

    True for optional list, false (the default) for the required list

Returns:

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

    map of resolvables



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

def GetAllResolvablesForAllTypes(optional: false)
  ret = {}

  GetSupportedResolvables().each do |one_type|
    resolvables = GetAllResolvables(one_type, optional: optional)
    ret[one_type] = resolvables if !resolvables.nil? && !resolvables.empty?
  end

  ret
end

#GetAllTaboos(type) ⇒ Array<String>

Returns the full list of taboos

Parameters:

  • type (Symbol)

    resolvable type

Returns:

  • (Array<String>)

    List of taboos



266
267
268
269
270
271
272
# File 'library/general/src/modules/PackagesProposal.rb', line 266

def GetAllTaboos(type)
  all_taboos = @taboos.values.each_with_object([]) do |tab, all|
    all.concat(tab[type]) if tab.key?(type)
  end

  all_taboos.sort.uniq
end

#GetResolvables(unique_id, type, optional: false) ⇒ Array<String>

Returns of resolvables.

Examples:

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

Returns:

  • (Array<String>)

    of resolvables



285
286
287
288
289
# File 'library/general/src/modules/PackagesProposal.rb', line 285

def GetResolvables(unique_id, type, optional: false)
  return nil if !CheckParams(unique_id, type)

  data(optional).fetch(unique_id, {}).fetch(type, [])
end

#GetSupportedResolvablesArray<Symbol>

Returns list of resolvables currently supported by this module.

Examples:

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

Returns:

  • (Array<Symbol>)

    of resolvables



72
73
74
# File 'library/general/src/modules/PackagesProposal.rb', line 72

def GetSupportedResolvables
  @supported_resolvables
end

#GetTaboos(unique_id, type) ⇒ Array<String>

Returns the list of taboos for a ID

Parameters:

  • unique_id (String)

    the unique identificator

  • type (Symbol)

    resolvable type

Returns:

  • (Array<String>)

    List of taboos for the given ID



256
257
258
259
260
# File 'library/general/src/modules/PackagesProposal.rb', line 256

def GetTaboos(unique_id, type)
  return [] unless @taboos.dig(unique_id, type)

  data_for(unique_id, type, @taboos)
end

#IsSupportedResolvableType(type) ⇒ Object



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

def IsSupportedResolvableType(type)
  log.warn("Type cannot be nil") if type.nil?

  @supported_resolvables.include?(type)
end

#IsUniqueID(unique_id) ⇒ Boolean

Returns true/false indicating whether the ID is already in use.

Parameters:

  • unique_id (String)

    the unique identificator to check

Returns:

  • (Boolean)

    true if the ID is not used, false otherwise



362
363
364
365
366
367
368
369
370
371
# File 'library/general/src/modules/PackagesProposal.rb', line 362

def IsUniqueID(unique_id)
  if unique_id.nil? || unique_id == ""
    log.error("Unique ID cannot be #{unique_id.inspect}")
    return nil
  end

  !@resolvables_to_install.key?(unique_id) &&
    !@opt_resolvables_to_install.key?(unique_id) &&
    !@taboos.key?(unique_id)
end

#mainObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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 = {}
  # the same as above but the resolvables are considered optional
  @opt_resolvables_to_install = {}
  # resolvables to remove
  @taboos = {}

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

#RemoveResolvables(unique_id, type, resolvables, optional: false) ⇒ Boolean

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)

    the unique identificator

  • type (Symbol)

    resolvable type

  • resolvables (Array<String>)

    list of resolvables to add for installation

  • optional (Boolean) (defaults to: false)

    True for optional list, false (the default) for the required list

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #AddResolvables()


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'library/general/src/modules/PackagesProposal.rb', line 177

def RemoveResolvables(unique_id, type, resolvables, optional: false)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_id, type)

  if resolvables.nil?
    log.warn("Using empty list instead of nil")
    resolvables = []
  end

  log.info("Removing #{log_label(optional)} #{resolvables.inspect} " \
           "type #{type} for #{unique_id}")

  current_resolvables = data_for(unique_id, type, data(optional))
  current_resolvables.reject! { |r| resolvables.include?(r) }

  log.info("#{log_label(optional)} left: #{current_resolvables.inspect}")

  true
end

#RemoveTaboos(unique_id, type, resolvables) ⇒ Boolean

Removes a resolvables from the list of taboos

Parameters:

  • unique_id (String)

    the unique identificator

  • type (Symbol)

    resolvables type

  • resolvables (Array<String>)

    list of resolvables to taboo

Returns:

  • (Boolean)

    whether successful



240
241
242
243
244
245
246
247
248
249
# File 'library/general/src/modules/PackagesProposal.rb', line 240

def RemoveTaboos(unique_id, type, resolvables)
  return false if !CheckParams(unique_id, type)

  current_taboos = data_for(unique_id, type, @taboos)
  current_taboos.reject! { |r| resolvables.include?(r) }

  log.info("Removing taboos  #{resolvables.inspect} type #{type} for #{unique_id}")

  true
end

#ResetAllObject

Resets all resolvables to install (both required and optional). Use carefully.



57
58
59
60
61
62
63
64
65
# File 'library/general/src/modules/PackagesProposal.rb', line 57

def ResetAll
  log.info("Resetting all PackagesProposal items")

  @resolvables_to_install.clear
  @opt_resolvables_to_install.clear
  @taboos.clear

  nil
end

#SetResolvables(unique_id, type, resolvables, optional: false) ⇒ Boolean

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)

    the unique identificator

  • type (Symbol)

    resolvable type

  • resolvables (Array<String>)

    list of resolvables to add for installation

  • optional (Boolean) (defaults to: false)

    True for optional list, false (the default) for the required list

Returns:

  • (Boolean)

    whether successful



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'library/general/src/modules/PackagesProposal.rb', line 145

def SetResolvables(unique_id, type, resolvables, optional: false)
  resolvables = deep_copy(resolvables)
  return false if !CheckParams(unique_id, type)

  if resolvables.nil?
    log.warn("Using empty list instead of nil")
    resolvables = []
  end

  log.info("Setting #{log_label(optional)} #{resolvables} of type #{type} for #{unique_id}")

  current_resolvables = data_for(unique_id, type, data(optional))
  current_resolvables.replace(resolvables)

  true
end

#SetTaboos(unique_id, type, resolvables) ⇒ Boolean

Sets the taboos list for a given unique_id

Parameters:

  • unique_id (String)

    the unique identificator

  • type (Symbol)

    resolvable type

  • resolvables (Array<String>)

    list of resolvables to taboo

Returns:

  • (Boolean)

    whether successful



225
226
227
228
229
230
231
232
# File 'library/general/src/modules/PackagesProposal.rb', line 225

def SetTaboos(unique_id, type, resolvables)
  return false if !CheckParams(unique_id, type)

  current_taboos = data_for(unique_id, type, @taboos)
  current_taboos.replace(resolvables)

  true
end