Module: Yast::SysconfigCmdlineInclude

Defined in:
../../src/include/sysconfig/cmdline.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) clearHandler(options)

Command line interface - handler for clear command

Parameters:

  • options (Hash{String => Object})

    command options

Returns:

  • (Boolean)

    True on success



133
134
135
136
137
138
139
140
141
142
143
# File '../../src/include/sysconfig/cmdline.rb', line 133

def clearHandler(options)
  options = deep_copy(options)
  # set empty value
  Ops.set(options, "value", "")

  # do not check if the value is valid
  Ops.set(options, "force", true)

  # call set handler
  setHandler(options)
end

- (Boolean) detailsHandler(options)

Command line interface - handler for details command

Parameters:

  • options (Hash{String => Object})

    details command options

Returns:

  • (Boolean)

    True on success



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File '../../src/include/sysconfig/cmdline.rb', line 149

def detailsHandler(options)
  options = deep_copy(options)
  variable = Ops.get_string(options, "variable")
  varid = variable2id(variable)

  return false if varid == nil

  # header (command line mode output)
  CommandLine.Print("\nDescription:\n")
  description = Sysconfig.get_description(varid)

  # display a new value for modified variables
  value = Ops.add(
    Ops.get(description, "new_value") != nil ?
      Ops.add(
        _("New Value: "),
        Ops.get_string(description, "new_value", "")
      ) :
      Ops.add(_("Value: "), Ops.get_string(description, "value", "")),
    "\n"
  )

  # convert description into plain text
  plaintext = Ops.add(value, create_description(description, false))

  CommandLine.Print(plaintext)

  true
end

- (Object) initialize_sysconfig_cmdline(include_target)



21
22
23
24
25
26
27
28
29
30
31
# File '../../src/include/sysconfig/cmdline.rb', line 21

def initialize_sysconfig_cmdline(include_target)
  Yast.import "UI"
  Yast.import "Sysconfig"
  Yast.import "RichText"
  Yast.import "CommandLine"
  Yast.import "Progress"

  Yast.include include_target, "sysconfig/complex.rb"

  textdomain "sysconfig"
end

- (Boolean) listHandler(options)

Command line interface - handler for list command

Parameters:

  • options (Hash)

    list command options

Returns:

  • (Boolean)

    Returns true (succeess)



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
# File '../../src/include/sysconfig/cmdline.rb', line 36

def listHandler(options)
  options = deep_copy(options)
  # display all variables or only modified ones?
  all = Builtins.haskey(options, "all")

  # header (command line mode output)
  CommandLine.Print(
    all == true ? _("All Variables:\n") : _("Modified Variables:\n")
  )

  modif = all == false ? Sysconfig.get_modified : Sysconfig.get_all
  result = ""

  Builtins.foreach(modif) do |v|
    descr = Sysconfig.get_description(v)
    # display a new value for modified variables
    value = Ops.get(descr, "new_value") != nil ?
      Ops.get_string(descr, "new_value", "") :
      Ops.get_string(descr, "value", "")
    result = Ops.add(
      result,
      Builtins.sformat("%1=\"%2\"\n", Sysconfig.get_name_from_id(v), value)
    )
  end 


  CommandLine.Print(result)

  true
end

- (Boolean) setHandler(options)

Command line interface - handler for set command

Parameters:

  • options (Hash{String => Object})

    list command options

Returns:

  • (Boolean)

    True on success



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File '../../src/include/sysconfig/cmdline.rb', line 93

def setHandler(options)
  options = deep_copy(options)
  variable = ""
  value = ""
  force = Ops.get_boolean(options, "force", true)

  if Builtins.haskey(options, "variable") &&
      Builtins.haskey(options, "value")
    variable = Ops.get_string(options, "variable")
    value = Ops.get_string(options, "value")
  # there is just one pair in the option map,
  # user has called the module with option VARIABLE=value
  elsif Builtins.size(options) == 1
    Builtins.y2milestone("options: %1", options)

    Builtins.foreach(options) do |key, val|
      variable = key
      value = Convert.to_string(val)
    end
  end

  if variable != ""
    vid = variable2id(variable)

    if vid == nil
      # the variable was not found
      return false
    end

    # set the value
    return setHanlerProcess(variable, value, force)
  end

  false
end

- (Object) setHanlerProcess(variable, value, force)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File '../../src/include/sysconfig/cmdline.rb', line 67

def setHanlerProcess(variable, value, force)
  vid = variable2id(variable)

  return false if vid == nil

  result = Sysconfig.set_value(vid, value, force, false)

  # status message - %1 is a device name (/dev/hdc), %2 is a mode name (udma2), %3 is a result (translated Success/Failed text)
  CommandLine.Print(
    Builtins.sformat(
      _("\nSetting variable '%1' to '%2': %3"),
      variable,
      value,
      # result message
      result == :ok ?
        _("Success") :
        _("Failed")
    )
  )

  result == :ok
end

- (Object) variable2id(variable)



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File '../../src/include/sysconfig/cmdline.rb', line 178

def variable2id(variable)
  if variable != nil
    all_names = Sysconfig.get_all_names
    vids = Ops.get(all_names, variable)

    if vids == nil
      # variable was not found
      # check whether variable name is complete variable identification
      all_vids = Sysconfig.get_all
      Builtins.y2milestone("variable: %2 all_vids: %1", all_vids, variable)

      if Builtins.contains(all_vids, variable)
        return variable
      else
        # command line output
        CommandLine.Print(
          Builtins.sformat(_("Variable %1 was not found."), variable)
        )
      end
    elsif Builtins.size(vids) == 1
      return Ops.get(vids, 0)
    else
      # duplicated variable, print found files
      CommandLine.Print(
        Builtins.sformat(
          "Variable %1 is located in the following files:\n",
          variable
        )
      )

      Builtins.foreach(vids) do |vid|
        fname = Sysconfig.get_file_from_id(vid)
        CommandLine.Print(fname)
      end 


      # variable name conflict - full name (with file name) is required
      CommandLine.Print(
        Builtins.sformat(
          _(
            "\n" +
              "Use a full variable name in the form <VARIABLE_NAME>$<FILE_NAME>\n" +
              "(e.g., %1$%2).\n"
          ),
          variable,
          Sysconfig.get_file_from_id(
            Ops.get(vids, 0, "/etc/sysconfig/unknown")
          )
        )
      )
    end
  end

  nil
end

- (Boolean) writeHandler

Write handler - disable progress bar (there is no UI) and write settings to the system.

Returns:

  • (Boolean)

    True on sucess



236
237
238
239
240
241
242
# File '../../src/include/sysconfig/cmdline.rb', line 236

def writeHandler
  # disable progress bar
  Progress.off

  # write changes, start activation commands
  Sysconfig.Write
end