Class: Yast::CheckMediaClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) DetectedCDDevices



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File '../../src/modules/CheckMedia.rb', line 45

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

- (Object) GetReadyCDs

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.



174
175
176
177
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
# File '../../src/modules/CheckMedia.rb', line 174

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

- (Object) Info

Return information printed by checkmedia utility



156
157
158
159
160
# File '../../src/modules/CheckMedia.rb', line 156

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

- (Object) main



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File '../../src/modules/CheckMedia.rb', line 20

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

- (Object) Process



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

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

- (Object) Progress



162
163
164
# File '../../src/modules/CheckMedia.rb', line 162

def Progress
  @progress
end

- (Object) Release

Release resources used by the subprocess



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

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

  nil
end

- (Object) Running



148
149
150
151
152
# File '../../src/modules/CheckMedia.rb', line 148

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

  ret
end

- (Object) Start(device)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File '../../src/modules/CheckMedia.rb', line 65

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

- (Object) Stop



80
81
82
83
84
85
86
87
88
89
90
91
# File '../../src/modules/CheckMedia.rb', line 80

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