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()

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

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} of type #{type} for #{unique_id}")

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

  true
end

#CheckParams(unique_id, type) ⇒ Boolean

Checks parameters for global functions

Parameters:

  • unique_id (String)
  • type (Symbol)

Returns:

  • (Boolean)

    if parameters are correct


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'library/general/src/modules/PackagesProposal.rb', line 84

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 resolvable type
GetAllResolvables (`unknown) -> nil

Parameters:

  • type (Symbol)

    resolvable 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

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'library/general/src/modules/PackagesProposal.rb', line 224

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


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

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

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

Returns of resolvables.

Examples:

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

Returns:

  • (Array<String>)

    of resolvables


204
205
206
207
208
# File 'library/general/src/modules/PackagesProposal.rb', line 204

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


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

def GetSupportedResolvables
  @supported_resolvables
end

#IsSupportedResolvableType(type) ⇒ Object


73
74
75
76
77
# File 'library/general/src/modules/PackagesProposal.rb', line 73

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


281
282
283
284
285
286
287
288
# File 'library/general/src/modules/PackagesProposal.rb', line 281

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)
end

#mainObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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 = {}

  # 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()

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

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} type #{type} for #{unique_id}")

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

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

  true
end

#ResetAllObject

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


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

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

  @resolvables_to_install.clear
  @opt_resolvables_to_install.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


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

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, optional: optional)
  current_resolvables.replace(resolvables)

  true
end