Class: Yast::CheckMediaClass

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

Overview

Module for checking media intergrity

Instance Method Summary collapse

Instance Method Details

#DetectedCDDevicesObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'src/modules/CheckMedia.rb', line 34

def DetectedCDDevices
  if @cd_cache.nil?
    # the cache is not initialied, do it now
    cds = Convert.convert(
      SCR.Read(path(".probe.cdrom")),
      from: "any",
      to:   "list <map>"
    )

    if cds.nil?
      # initialize to empty list
      cds = []
    end

    @cd_cache = deep_copy(cds)
  end

  deep_copy(@cd_cache)
end

#GetReadyCDsArray<String>

Return list of ready CD devices for installation. It works properly only in the first installation stage - it reads content of /etc/install.inf file. It returns the installation (boot) CD device if it's known or it probes for all CD devices and returns ready devices (the devices which contain a medium). If repository is not CD/DVD it returns empty list.


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'src/modules/CheckMedia.rb', line 163

def GetReadyCDs
  # check whether we are using CD repository
  instmode = Linuxrc.InstallInf("InstMode")
  Builtins.y2milestone("Installation mode: %1", instmode)

  readycddrives = []

  if instmode == "cd" || instmode == "dvd"
    # get CD device name
    bootcd = Linuxrc.InstallInf("Cdrom")

    if !bootcd.nil? && bootcd != ""
      readycddrives = [Builtins.sformat("/dev/%1", bootcd)]
    else
      Builtins.y2milestone("CD device device is not known, probing...")
      # booted from another location (network), test all CD drives
      cds = DetectedCDDevices()

      Builtins.foreach(cds) do |cd|
        devname = Ops.get_string(cd, "dev_name", "")
        # check whether the CD is ready
        if Ops.get_boolean(cd, "notready", false) == false && !devname.nil? &&
            devname != ""
          readycddrives = Builtins.add(readycddrives, devname)
        end
      end if !cds.nil?
    end

    Builtins.y2milestone("Ready CD drives: %1", readycddrives)
  end

  deep_copy(readycddrives)
end

#InfoArray<String>

Return information printed by checkmedia utility


145
146
147
148
149
# File 'src/modules/CheckMedia.rb', line 145

def Info
  ret = deep_copy(@output)
  @output = []
  deep_copy(ret)
end

#mainObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'src/modules/CheckMedia.rb', line 9

def main
  Yast.import "Linuxrc"
  Yast.import "Report"

  textdomain "packager"

  @checkmedia = "/usr/bin/checkmedia"

  @output = []
  @progress = 0
  @inprogress = false

  @preferred_drive = ""

  # true if module start was forced - check=1 was found in the application area,
  # effects UI a little
  @forced_start = false

  # cache .probe.cdrom value
  # avoid reprobind during installation
  @cd_cache = nil

  @process = nil
end

#ProcessObject


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

def Process
  return if @process.nil?

  if @inprogress
    # try to read whole lines
    out = Convert.to_string(SCR.Read(path(".process.read_line"), @process))

    if !out.nil?
      @output = Builtins.add(@output, out)

      out = Convert.to_string(SCR.Read(path(".process.read"), @process))

      if !out.nil?
        @output = Convert.convert(
          Builtins.merge(@output, Builtins.splitstring(out, "\n")),
          from: "list",
          to:   "list <string>"
        )
      end

      # finished
      @progress = 100
      @inprogress = false
    else
      # read progress status
      buffer = Convert.to_string(SCR.Read(path(".process.read"), @process))

      if !buffer.nil?
        Builtins.y2debug("buffer: %1", buffer)

        percent = Builtins.regexpsub(buffer, "([0-9]*)%.*$", "\\1")

        if !percent.nil?
          @progress = Builtins.tointeger(percent)
          Builtins.y2milestone("progress: %1%%", @progress)
        end
      end
    end
  else
    out = Convert.to_string(SCR.Read(path(".process.read_line"), @process))

    if !out.nil?
      @output = Builtins.add(@output, out)

      # check whether we need to switch to progress mode
      if Builtins.regexpmatch(out, "^ *pad: ")
        @inprogress = true
        Builtins.y2milestone("Switching into progress mode")
      end
    end
  end

  nil
end

#ProgressObject


151
152
153
# File 'src/modules/CheckMedia.rb', line 151

def Progress
  @progress
end

#ReleaseObject

Release resources used by the subprocess


198
199
200
201
202
203
204
205
# File 'src/modules/CheckMedia.rb', line 198

def Release
  if !@process.nil?
    SCR.Execute(path(".process.release"), @process)
    @process = nil
  end

  nil
end

#RunningObject


137
138
139
140
141
# File 'src/modules/CheckMedia.rb', line 137

def Running
  ret = Convert.to_boolean(SCR.Read(path(".process.running"), @process))

  ret
end

#Start(device) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/modules/CheckMedia.rb', line 54

def Start(device)
  # reset values
  @output = []
  @progress = 0
  @inprogress = false

  @process = Convert.to_integer(
    SCR.Execute(
      path(".process.start_shell"),
      Ops.add(Ops.add(@checkmedia, " "), device)
    )
  )
  true
end

#StopObject


69
70
71
72
73
74
75
76
77
78
79
80
# File 'src/modules/CheckMedia.rb', line 69

def Stop
  ret = Convert.to_boolean(SCR.Execute(path(".process.kill"), @process))

  # wait for the process
  SCR.Execute(path(".process.close"), @process)

  # release the process from the agent
  SCR.Execute(path(".process.release"), @process)
  @process = nil

  ret
end