Class: Yast::InitHWinfoClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Array) DetectedHardware(force, abort)

Detect all hardware present in the system

Parameters:

  • force (Boolean)

    If force is true then detection is always started (cached value is discarded)

Returns:

  • (Array)

    list of maps - detected hardware items ()



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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File '../../src/modules/InitHWinfo.rb', line 179

def DetectedHardware(force, abort)
  abort = deep_copy(abort)
  # return cached values if possible
  return deep_copy(@detectedHW) if @detectedHW != nil && force != true

  @detectedHW = []

  # probe devices, store model, class, uniq. ID for each device

  # probe by bus
  # list(string) paths = [ "cpu", "memory", "ide", "pci", "scsi", "isapnp", "floppy", "usb", "monitor" ];

  # probe by device class
  paths = [
    "cpu",
    "memory",
    "disk",
    "display",
    "mouse",
    "keyboard",
    "storage",
    "netcard",
    "monitor",
    "braille",
    "bios"
  ]

  if !Arch.is_uml
    paths = Convert.convert(
      Builtins.union(
        paths,
        [
          "cdrom",
          "floppy",
          "sound",
          "isdn",
          "modem",
          "printer",
          "tv",
          "dvb",
          "scanner",
          "camera",
          "chipcard",
          "usbctrl",
          "ieee1394ctrl",
          "hub",
          "joystick",
          "pppoe"
        ]
      ),
      :from => "list",
      :to   => "list <string>"
    )
  end

  Progress.New(
    _("Hardware Detection"),
    "",
    Builtins.size(paths),
    [_("Detect hardware")],
    [_("Detecting hardware...")],
    _("Hardware detection is in progress. Please wait.")
  )

  Progress.NextStage

  aborted = false

  Builtins.foreach(paths) do |subpath|
    aborted = Builtins.eval(abort) if abort != nil && aborted != true
    Builtins.y2debug("aborted: %1", aborted)
    if !aborted
      p = Builtins.add(path(".probe"), subpath)

      # translate path name
      pathname = trans_str(subpath)

      # use untranslated string if translation failed
      pathname = subpath if pathname == nil

      # set progress bar label
      Progress.Title(Builtins.sformat(_("%1..."), pathname))

      # don't ask for probing CPU and memory, they were already probed and detection should be harmless
      detect = subpath == "cpu" || subpath == "memory" ?
        true :
        Confirm.Detection(pathname, nil)

      # confirm hardware detection in the manual mode
      if detect == true
        Builtins.y2milestone("Probing: %1", p)
        result = Convert.convert(
          SCR.Read(p),
          :from => "any",
          :to   => "list <map <string, any>>"
        )

        if Ops.greater_than(Builtins.size(result), 0)
          Builtins.foreach(result) do |info|
            # device name (CPU model name string has key "name" instead of "model")
            model = subpath == "cpu" ?
              Ops.get_locale(info, "name", _("Unknown device")) :
              Ops.get_locale(info, "model", _("Unknown device"))
            Builtins.y2debug("Model: %1", model)
            @detectedHW = Builtins.add(
              @detectedHW,
              { "model" => model, "info" => info }
            )
          end
        end
      end

      # update progress bar
      Progress.NextStep
    end
  end 


  if aborted == true
    # set to non-initialized state when detection is aborted
    @detectedHW = nil
  end

  Builtins.y2milestone("Detected HW: %1", @detectedHW)

  deep_copy(@detectedHW)
end

- (Boolean) Initialize(force)

Start hardware detection (only CPU and main memory)

Parameters:

  • force (Boolean)

    If true then start detection again (discard cached values)

Returns:

  • (Boolean)

    True on success



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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File '../../src/modules/InitHWinfo.rb', line 44

def Initialize(force)
  return true if @initialized == true && force == false

  # initialize procesor string
  cpu_result = Convert.convert(
    SCR.Read(path(".probe.cpu")),
    :from => "any",
    :to   => "list <map>"
  )

  # group by CPU names, strip possible white space (see bnc#803000)
  cpu_names = cpu_result.group_by do |cpu|
    cpu_name = cpu["name"] || _("Unknown processor")
    cpu_name.strip
  end

  Builtins.y2milestone("Found CPU names: %1", cpu_names)

  cpu_summary_list = cpu_names.map do |name, list|
    if list.size > 1
      # create processor count string
      # the first %s is integer number (greater than 1)
      # the second %s is processor model name
      (_("%sx %s") % [ list.size, name ])
    else
      name
    end
  end

  # list separator (placed between items)
  @cpu_string = cpu_summary_list.join(_(", "))

  memory = Convert.convert(
    SCR.Read(path(".probe.memory")),
    :from => "any",
    :to   => "list <map>"
  )

  Builtins.y2milestone("memory: %1", memory)
  @memory_size = 0

  Builtins.foreach(memory) do |info|
    # internal class, main memory
    if Ops.get_integer(info, "class_id", 0) == 257 &&
        Ops.get_integer(info, "sub_class_id", 0) == 2
      minf = Ops.get_list(info, ["resource", "phys_mem"], [])
      Builtins.foreach(minf) do |i|
        @memory_size = Ops.add(@memory_size, Ops.get_integer(i, "range", 0))
      end
    end
  end 


  # initialize system string
  bios = Convert.to_list(SCR.Read(path(".probe.bios")))

  if Builtins.size(bios) != 1
    Builtins.y2warning("Warning: BIOS list size is %1", Builtins.size(bios))
  end

  biosinfo = Ops.get_map(bios, 0, {})
  smbios = Ops.get_list(biosinfo, "smbios", [])

  sysinfo = {}

  Builtins.foreach(smbios) do |inf|
    sysinfo = deep_copy(inf) if Ops.get_string(inf, "type", "") == "sysinfo"
  end 


  @system_string = ""

  if Ops.greater_than(Builtins.size(sysinfo), 0)
    # system manufacturer is unknown
    manufacturer = Ops.get_locale(sysinfo, "manufacturer", _("Unknown"))
    # system product name is unknown
    product = Ops.get_locale(sysinfo, "product", _("Unknown"))
    version = Ops.get_string(sysinfo, "version", "")

    @system_string = Builtins.sformat("%1 - %2", manufacturer, product)

    if Ops.greater_than(Builtins.size(version), 0)
      @system_string = Ops.add(
        @system_string,
        Builtins.sformat(" (%1)", version)
      )
    end
  # PPC architecture - use board and generation information
  elsif Arch.ppc
    board = ""
    generation = ""

    systemProbe = Convert.convert(
      SCR.Read(path(".probe.system")),
      :from => "any",
      :to   => "list <map>"
    )
    systemProbe = [] if systemProbe == nil

    Builtins.foreach(systemProbe) do |systemEntry|
      board_tmp = Ops.get_string(systemEntry, "system", "")
      board = board_tmp if board_tmp != nil && board_tmp != ""
      generation_tmp = Ops.get_string(systemEntry, "generation", "")
      if generation_tmp != nil && generation_tmp != ""
        generation = generation_tmp
      end
    end

    @system_string = board

    if @system_string != "" && generation != ""
      @system_string = Ops.add(
        @system_string,
        Builtins.sformat(" (%1)", generation)
      )
    end
  end

  Builtins.y2milestone("System string: %1", @system_string)

  @initialized = true

  true
end

- (Object) main



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File '../../src/modules/InitHWinfo.rb', line 15

def main
  Yast.import "UI"

  Yast.import "String"
  Yast.import "Confirm"
  Yast.import "Progress"
  Yast.import "Arch"
  Yast.import "SystemSettings"

  Yast.include self, "hwinfo/routines.rb"

  textdomain "tune"

  @initialized = false

  # CPU summary string
  @cpu_string = ""
  # memory size
  @memory_size = 0
  # system summary string
  @system_string = ""

  # list of detected devices
  @detectedHW = nil
end

- (Boolean) MakeProposal(reset)

Return short system description

Parameters:

  • reset (Boolean)

    If reset is true then always do hardware detection

Returns:

  • (Boolean)

    if proposal succeed



172
173
174
# File '../../src/modules/InitHWinfo.rb', line 172

def MakeProposal(reset)
  Initialize(reset)
end