Class: Yast::ProductFeaturesClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Hash <String, Hash{String => Object>}) Export

Exports the current set of ProductFeatures

Returns:

  • (Hash <String, Hash{String => Object>})

    features



305
306
307
# File '../../src/modules/ProductFeatures.rb', line 305

def Export
  deep_copy(@features)
end

- (Boolean) GetBooleanFeature(section, feature)

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



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

def GetBooleanFeature(section, feature)
  value = GetFeature(section, feature)
  if Ops.is_boolean?(value)
    return value
  elsif Ops.is_string?(value) &&
      Builtins.tolower(Convert.to_string(value)) == "yes"
    return true
  else
    return false
  end
end

- (Object) GetFeature(section, feature)

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



197
198
199
200
201
202
# File '../../src/modules/ProductFeatures.rb', line 197

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

- (Fixnum) GetIntegerFeature(section, feature)

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



244
245
246
247
248
249
250
251
252
253
# File '../../src/modules/ProductFeatures.rb', line 244

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

- (Object) GetSection(section_name)

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



125
126
127
128
# File '../../src/modules/ProductFeatures.rb', line 125

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

- (String) GetStringFeature(section, feature)

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



209
210
211
212
213
214
215
216
217
218
# File '../../src/modules/ProductFeatures.rb', line 209

def GetStringFeature(section, feature)
  value = GetFeature(section, feature)
  if Ops.is_string?(value)
    return value
  elsif Ops.is_boolean?(value)
    return Convert.to_boolean(value) ? "yes" : "no"
  else
    return Builtins.sformat("%1", value)
  end
end

- (Object) Import(import_settings)

Imports product features

Parameters:

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

    features



312
313
314
315
316
317
# File '../../src/modules/ProductFeatures.rb', line 312

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

  nil
end

- (Object) InitFeatures(force)

Initialize default values of features

Parameters:

  • force (Boolean)

    boolean drop all settings which were set before



95
96
97
98
99
100
# File '../../src/modules/ProductFeatures.rb', line 95

def InitFeatures(force)
  return if !(force || @features == nil)
  @features = deep_copy(@defaults)

  nil
end

- (Object) InitIfNeeded

Note:

This is a stable API function

Initialize the features structure if needed Either read from /etc/YaST2/ProductFeatures or set default values



181
182
183
184
185
186
187
188
189
190
# File '../../src/modules/ProductFeatures.rb', line 181

def InitIfNeeded
  return if @features != nil
  if Stage.normal || Stage.firstboot
    Restore()
  else
    InitFeatures(false)
  end

  nil
end

- (Object) main



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

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

  # Default values for features
  # two-level map, section_name -> [ feature -> value ]
  @defaults = {
    "globals"      => {
      "incomplete_translation_treshold" => "95",
      "ui_mode"                         => "expert",
      "enable_autologin"                => true,
      "language"                        => "",
      "skip_language_dialog"            => false,
      "keyboard"                        => "",
      "default_target"                  => "",
      "timezone"                        => "",
      "fam_local_only"                  => "never",
      "enable_firewall"                 => true,
      "firewall_enable_ssh"             => false,
      "enable_sshd"                     => false,
      "additional_kernel_parameters"    => "",
      "flags"                           => [],
      "run_you"                         => true,
      "relnotesurl"                     => "",
      "vendor_url"                      => "",
      "enable_clone"                    => false,
      "disable_os_prober"               => false,
      # FATE #304865
      "base_product_license_directory"  => "/etc/YaST2/licenses/base/"
    },
    "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 }
  }
end

- (Object) Restore

Note:

This is a stable API function

Restore product features in running system



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File '../../src/modules/ProductFeatures.rb', line 158

def Restore
  InitFeatures(true)
  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

- (Object) Save

Note:

This is a stable API function

Save product features



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File '../../src/modules/ProductFeatures.rb', line 132

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) { |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 }
  SCR.Write(path(".product.features"), nil) # flush

  nil
end

- (Object) SetBooleanFeature(section, feature, value)

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



285
286
287
288
289
# File '../../src/modules/ProductFeatures.rb', line 285

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

  nil
end

- (Object) SetFeature(section, feature, value)

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



260
261
262
263
264
265
266
267
# File '../../src/modules/ProductFeatures.rb', line 260

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

- (Object) SetIntegerFeature(section, feature, value)

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



296
297
298
299
300
# File '../../src/modules/ProductFeatures.rb', line 296

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

  nil
end

- (Object) SetSection(section_name, section_map)

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



107
108
109
110
111
112
113
114
115
116
117
118
119
# File '../../src/modules/ProductFeatures.rb', line 107

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

- (Object) SetStringFeature(section, feature, value)

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



274
275
276
277
278
# File '../../src/modules/ProductFeatures.rb', line 274

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

  nil
end