Class: Yast::ProductFeaturesClass

Inherits:
Module
  • Object
show all
Defined in:
library/control/src/modules/ProductFeatures.rb

Instance Method Summary collapse

Instance Method Details

#ClearOverlayObject

Remove a @features overlay; does nothing if SetOverlay was never called.

Returns:

  • void

See Also:



376
377
378
379
380
381
382
383
# File 'library/control/src/modules/ProductFeatures.rb', line 376

def ClearOverlay
  return if @backup_features.nil?

  @features = deep_copy(@backup_features)
  # when overlay is cleared, remove backup as it can become invalid over-time
  # when new extensions is applied
  @backup_features = nil
end

#ExportHash <String, Hash{String => Object>}

Exports the current set of ProductFeatures

Returns:



339
340
341
# File 'library/control/src/modules/ProductFeatures.rb', line 339

def Export
  deep_copy(@features)
end

#GetBooleanFeature(section, feature) ⇒ Boolean

Note:

This is a stable API function

Get value of a feature If the feature is missing false is returned. So it is not possible to distingush between a missing value and a false value.

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

Returns:

  • (Boolean)

    the feature value



247
248
249
250
251
252
# File 'library/control/src/modules/ProductFeatures.rb', line 247

def GetBooleanFeature(section, feature)
  value = GetFeature(section, feature)
  return value if Ops.is_boolean?(value)

  Ops.is_string?(value) && Builtins.tolower(Convert.to_string(value)) == "yes"
end

#GetBooleanFeatureWithFallback(section, feature, fallback) ⇒ Boolean

Note:

This is a stable API function

Get value of a boolean feature with a fallback value.

Parameters:

  • section (String)

    string section of the feature

  • feature (String)

    feature name

  • fallback (Boolean)

Returns:

  • (Boolean)

    the feature value or fallback if not specified



262
263
264
265
266
267
268
269
270
271
272
273
# File 'library/control/src/modules/ProductFeatures.rb', line 262

def GetBooleanFeatureWithFallback(section, feature, fallback)
  value = GetFeature(section, feature)
  return fallback if value.nil?
  return value if Ops.is_boolean?(value)

  if value.respond_to?(:downcase)
    return true  if ["yes", "true"].include?(value.downcase)
    return false if ["no", "false"].include?(value.downcase)
  end

  fallback
end

#GetFeature(section, feature) ⇒ Object

Note:

This is a stable API function

Get value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

Returns:

  • (Object)

    the feature value, "" if not found



215
216
217
218
219
220
# File 'library/control/src/modules/ProductFeatures.rb', line 215

def GetFeature(section, feature)
  InitIfNeeded()
  ret = Ops.get(@features, [section, feature])
  ret = "" if ret.nil?
  deep_copy(ret)
end

#GetIntegerFeature(section, feature) ⇒ Fixnum

Note:

This is a stable API function

Get value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

Returns:

  • (Fixnum)

    the feature value, nil if not found



280
281
282
283
284
285
286
287
# File 'library/control/src/modules/ProductFeatures.rb', line 280

def GetIntegerFeature(section, feature)
  value = GetFeature(section, feature)
  if Ops.is_integer?(value)
    value
  elsif Ops.is_string?(value)
    Builtins.tointeger(Convert.to_string(value))
  end
end

#GetSection(section_name) ⇒ Object

Note:

This is a stable API function

Get a complete section for evaluation

Parameters:

  • section_name (String)

    string name of the section

Returns:

  • a map key->value, options in the section



137
138
139
140
# File 'library/control/src/modules/ProductFeatures.rb', line 137

def GetSection(section_name)
  InitFeatures(false)
  Ops.get(@features, section_name, {})
end

#GetStringFeature(section, feature) ⇒ String

Note:

This is a stable API function

Get value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

Returns:

  • (String)

    the feature value, "" if not found



227
228
229
230
231
232
233
234
235
236
237
238
# File 'library/control/src/modules/ProductFeatures.rb', line 227

def GetStringFeature(section, feature)
  value = GetFeature(section, feature)

  case value
  when ::String
    value
  when true, false
    value ? "yes" : "no"
  else
    Builtins.sformat("%1", value)
  end
end

#Import(import_settings) ⇒ Object

Imports product features

Parameters:

  • map (string, map <string, any>)

    features



346
347
348
349
350
# File 'library/control/src/modules/ProductFeatures.rb', line 346

def Import(import_settings)
  @features = deep_copy(import_settings)

  nil
end

#InitFeatures(force) ⇒ Object

Initialize default values of features

Parameters:

  • force (Boolean)

    boolean drop all settings which were set before



106
107
108
109
110
111
112
# File 'library/control/src/modules/ProductFeatures.rb', line 106

def InitFeatures(force)
  return if @features && !force

  @features = deep_copy(@defaults)

  nil
end

#InitIfNeededObject

Note:

The values are normally read from a control file or set to default values. But, in normal

Note:

This is a stable API function

Initialize the features structure if needed

mode, the values are taken from /etc/YaST2/ProductFeatures. Also note that for firstboot mode, the values are taken from the firstboot.xml control file.



200
201
202
203
204
205
206
207
208
# File 'library/control/src/modules/ProductFeatures.rb', line 200

def InitIfNeeded
  if Stage.normal
    Restore()
  else
    InitFeatures(false)
  end

  nil
end

#mainObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'library/control/src/modules/ProductFeatures.rb', line 33

def main
  textdomain "base"

  Yast.import "Misc"
  Yast.import "Mode"
  Yast.import "Stage"

  # Map of all features
  # See defaults map below for sample contents
  @features = nil

  # See SetOverlay and ClearOverlay
  @backup_features = nil

  # Default values for features
  # two-level map, section_name -> [ feature -> value ]
  @defaults = {
    "globals"                  => {
      "additional_kernel_parameters"    => "",
      # FATE #304865
      "base_product_license_directory"  => "/usr/share/licenses/product/base/",
      # jsc#SLE-22667
      "boot_timeout"                    => 8,
      "default_target"                  => "",
      "disable_os_prober"               => false,
      "enable_autologin"                => true,
      "enable_clone"                    => false,
      "enable_firewall"                 => true,
      "enable_local_users"              => true,
      "enable_sshd"                     => false,
      "fam_local_only"                  => "never",
      "firewall_enable_ssh"             => false,
      "flags"                           => [],
      "full_system_download_url"        => "",
      "full_system_media_name"          => "",
      "incomplete_translation_treshold" => "95",
      "keyboard"                        => "",
      "language"                        => "",
      "propose_hibernation"             => true,
      "relnotesurl"                     => "",
      "run_you"                         => true,
      "save_y2logs"                     => true,
      "skip_language_dialog"            => false,
      "timezone"                        => "",
      "ui_mode"                         => "expert",
      "vendor_url"                      => ""
    },
    "partitioning"             => {
      "use_flexible_partitioning"    => false,
      "flexible_partitioning"        => {},
      "vm_keep_unpartitioned_region" => false
    },
    "software"                 => {
      "software_proposal"                    => "selection",
      "selection_type"                       => :auto,
      "delete_old_packages"                  => true,
      "only_update_installed"                => false,
      "packages_transmogrify"                => "",
      "base_selection"                       => "",
      "packages"                             => [],
      "kernel_packages"                      => [],
      "addon_selections"                     => [],
      "inform_about_suboptimal_distribution" => false
    },
    "network"                  => { "force_static_ip" => false },
    # Defaults are defined in the ConfigurationManagement::Configurations classes:
    # https://github.com/yast/yast-configuration-management/blob/27c93ba9d592271a299706aca323d9d371d44058/src/lib/configuration_management/configurations/base.rb#L13
    "configuration_management" => {}
  }
end

#RestoreObject

Note:

This is a stable API function

Restore product features in running system



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

def Restore
  InitFeatures(false)

  groups = SCR.Dir(path(".product.features.section"))
  Builtins.foreach(groups) do |group|
    Ops.set(@features, group, Ops.get(@features, group, {}))
    values = SCR.Dir(Ops.add(path(".product.features.value"), group))
    Builtins.foreach(values) do |v|
      Ops.set(
        @features,
        [group, v],
        SCR.Read(
          Ops.add(Ops.add(path(".product.features.value"), group), v)
        )
      )
    end
  end

  nil
end

#SaveObject

Note:

This is a stable API function

Save product features



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
# File 'library/control/src/modules/ProductFeatures.rb', line 144

def Save
  InitFeatures(false)
  if Mode.update # in case of update old file has different format
    SCR.Execute(
      path(".target.bash"),
      "test -f /etc/YaST2/ProductFeatures && /bin/rm /etc/YaST2/ProductFeatures"
    )
  end
  Builtins.foreach(@features) do |group, options|
    Builtins.foreach(options) do |key, value|
      if Ops.is_map?(value) || Ops.is_list?(value) || Ops.is_symbol?(value)
        Builtins.y2debug("Skipping option %1", key)
      else
        strval = GetStringFeature(group, key)
        SCR.Write(
          Ops.add(Ops.add(path(".product.features.value"), group), key),
          strval
        )
      end
    end
  end
  SCR.Write(path(".product.features"), nil) # flush

  nil
end

#SetBooleanFeature(section, feature, value) ⇒ Object

Note:

This is a stable API function

Set value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

  • value (Boolean)

    boolean the feature value



319
320
321
322
323
# File 'library/control/src/modules/ProductFeatures.rb', line 319

def SetBooleanFeature(section, feature, value)
  SetFeature(section, feature, value)

  nil
end

#SetFeature(section, feature, value) ⇒ Object

Note:

This is a stable API function

Set value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

  • value (Object)

    any the feature value



294
295
296
297
298
299
300
301
# File 'library/control/src/modules/ProductFeatures.rb', line 294

def SetFeature(section, feature, value)
  value = deep_copy(value)
  InitIfNeeded()
  Ops.set(@features, section, {}) if !Builtins.haskey(@features, section)
  Ops.set(@features, [section, feature], value)

  nil
end

#SetIntegerFeature(section, feature, value) ⇒ Object

Note:

This is a stable API function

Set value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

  • value (Fixnum)

    integer the feature value



330
331
332
333
334
# File 'library/control/src/modules/ProductFeatures.rb', line 330

def SetIntegerFeature(section, feature, value)
  SetFeature(section, feature, value)

  nil
end

#SetOverlay(features) ⇒ Object

Overlay, or override, some features. The intended use is to use SetOverlay to apply some features specified by a system role (FATE#317481). Clear would be called only when coming Back to the role selection dialog (and then SetOverlay with a different one)

Parameters:

  • features (Hash{String => Hash{String => Object}})

    in the same format as @features or @defaults

Returns:

  • void

Raises:



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

def SetOverlay(features)
  raise "SetOverlay called when old overlay was not cleared" if @backup_features

  @backup_features = deep_copy(@features)

  features.each do |section_name, section|
    section.each do |k, v|
      SetFeature(section_name, k, v)
    end
  end
end

#SetSection(section_name, section_map) ⇒ Object

Note:

This is a stable API function

Set a feature section Default values will be used where value not defined

Parameters:

  • section

    name string the name of the section

  • section_map (Hash{String => Object})

    a map containing data of the section



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'library/control/src/modules/ProductFeatures.rb', line 119

def SetSection(section_name, section_map)
  section_map = deep_copy(section_map)
  InitFeatures(false)
  Builtins.y2debug("Setting section: %1", section_name)
  section_map = Convert.convert(
    Builtins.union(Ops.get(@defaults, section_name, {}), section_map),
    from: "map",
    to:   "map <string, any>"
  )
  Ops.set(@features, section_name, section_map)

  nil
end

#SetStringFeature(section, feature, value) ⇒ Object

Note:

This is a stable API function

Set value of a feature

Parameters:

  • section (String)

    string section of the feature

  • features

    string feature name

  • value (String)

    string the feature value



308
309
310
311
312
# File 'library/control/src/modules/ProductFeatures.rb', line 308

def SetStringFeature(section, feature, value)
  SetFeature(section, feature, value)

  nil
end