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)

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

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #RemoveResolvables()


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

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



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

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)

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

Returns:

  • (Array<String>)

    list of resolvables

See Also:

  • #supported_resolvables


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

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 do |_unique_ID, 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)

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

Returns:

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

    map of resolvables



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

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



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

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



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

def GetSupportedResolvables
  @supported_resolvables
end

#IsSupportedResolvableType(type) ⇒ Object



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

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



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

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



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 36

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)

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

Returns:

  • (Boolean)

    whether successful

See Also:

  • #supported_resolvables
  • #AddResolvables()


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

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.



57
58
59
60
61
62
63
64
# 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

  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)

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

Returns:

  • (Boolean)

    whether successful



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

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