Module: Yast::CheckmediaUiInclude
- Defined in:
- ../../src/include/checkmedia/ui.rb
Instance Method Summary (collapse)
- - (Object) CDdevices(preferred)
- - (Object) initialize_checkmedia_ui(include_target)
-
- (Object) InsertedCD1
mount CD drive and check whether there is directory 'media.1' (the first medium) and 'boot' (bootable product CD).
- - (Object) LogLine(line)
-
- (Symbol) MainDialog
Main dialog.
-
- (Object) MainSequence
Main workflow of the idedma configuration.
-
- (Object) md5sumTagPresent(input)
does the medium contain MD5 checksum in the application area?.
- - (Object) RequireFirstMedium
- - (Object) SetButtonState(running)
- - (Object) TranslateInfo(info)
Instance Method Details
- (Object) CDdevices(preferred)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File '../../src/include/checkmedia/ui.rb', line 45 def CDdevices(preferred) cds = Convert.convert( SCR.Read(path(".probe.cdrom")), :from => "any", :to => "list <map>" ) ret = [] Builtins.foreach(cds) do |cd| dev = Ops.get_string(cd, "dev_name", "") model = Ops.get_string(cd, "model", "") deflt = preferred == dev if dev != nil && dev != "" && model != nil ret = Builtins.add( ret, Item(Id(dev), Ops.add(model, Builtins.sformat(" (%1)", dev)), deflt) ) end end if cds != nil deep_copy(ret) end |
- (Object) initialize_checkmedia_ui(include_target)
18 19 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/include/checkmedia/ui.rb', line 18 def initialize_checkmedia_ui(include_target) Yast.import "Pkg" Yast.import "UI" textdomain "packager" Yast.import "Wizard" Yast.import "CheckMedia" Yast.import "Popup" Yast.import "Label" Yast.import "Sequencer" Yast.import "String" Yast.import "Stage" Yast.import "PackageSystem" Yast.import "GetInstArgs" Yast.import "Directory" # selected input file (used when checking a file instead of physical CD/DVD medium) @iso_filename = "" # checking file (ISO image) instead of a medium is in progress @checking_file = false @log_content = "" end |
- (Object) InsertedCD1
mount CD drive and check whether there is directory 'media.1' (the first medium) and 'boot' (bootable product CD)
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 |
# File '../../src/include/checkmedia/ui.rb', line 180 def InsertedCD1 ret = true instmode = Convert.to_string(SCR.Read(path(".etc.install_inf.InstMode"))) if instmode == "cd" || instmode == "dvd" cdrom_device = Convert.to_string( SCR.Read(path(".etc.install_inf.Cdrom")) ) # bugzilla #305495 if cdrom_device == nil || cdrom_device == "" Builtins.y2error("No Cdrom present in install.inf") # try to recover return true end # get CD device name bootcd = Ops.add("/dev/", cdrom_device) # is the device mounted? mounts = Convert.convert( SCR.Read(path(".proc.mounts")), :from => "any", :to => "list <map>" ) mnt = Builtins.listmap(mounts) do |m| { Ops.get_string(m, "spec", "") => Ops.get_string(m, "file", "") } end dir = "" mounted = false if Builtins.haskey(mnt, bootcd) dir = Ops.get(mnt, bootcd, "") else dir = Ops.add( Convert.to_string(SCR.Read(path(".target.tmpdir"))), "/YaST.mnt" ) SCR.Execute(path(".target.mkdir"), dir) mounted = Convert.to_boolean( SCR.Execute(path(".target.mount"), [bootcd, dir], "-o ro") ) end # check for the first medium succ = Convert.to_integer( SCR.Execute( path(".target.bash"), Builtins.sformat("test -d %1/media.1 && test -d %1/boot", dir) ) ) ret = succ == 0 # reset to the previous state if mounted # unmount back umnt = Convert.to_boolean(SCR.Execute(path(".target.umount"), dir)) Builtins.y2milestone("unmounted %1: %2", dir, umnt) end end ret end |
- (Object) LogLine(line)
263 264 265 266 267 268 269 |
# File '../../src/include/checkmedia/ui.rb', line 263 def LogLine(line) @log_content = Ops.add(@log_content, line) UI.ChangeWidget(Id(:log), :Value, @log_content) Builtins.y2debug("content: %1", @log_content) nil end |
- (Symbol) MainDialog
Main dialog
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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File '../../src/include/checkmedia/ui.rb', line 273 def MainDialog req_package = "checkmedia" if Ops.less_than(SCR.Read(path(".target.size"), CheckMedia.checkmedia), 0) && !PackageSystem.CheckAndInstallPackagesInteractive([req_package]) return :abort end # set wizard buttons at first Wizard.SetNextButton(:next, Label.CloseButton) if !CheckMedia.forced_start # set buttons according to mode if !Stage.initial # remove Back button - workflow has only one dialog Wizard.HideBackButton # remove Abort button - it's useless Wizard.HideAbortButton end # umount CD drives (release all sources) if Stage.initial # release all media Pkg.SourceReleaseAll end # dialog header caption = _("Media Check") # help text - media check (header) 1/8 help = _("<P><B>Media Check</B></P>") + # help text - media check 2/8 _( "<P>When you have a problem with\n" + "the installation and you are using a CD or DVD installation medium, you should check\n" + "whether the medium is broken.</P>\n" ) + # help text - media check 3/8 _( "<P>Select a drive, insert a medium into the drive and press <B>Start Check</B>\n" + "or use <B>Check ISO File</B> and select an ISO file.\n" + "The check can take several minutes depending on speed of the\n" + "drive and size of the medium. The check verifies the MD5 checksum.</P> " ) + # help text - media check 4/8 _( "<P>If the check of the medium fails, you should not continue the installation.\nIt may fail or you may lose your data. Better replace the broken medium.</P>\n" ) + # help text - media check 5/8 _( "After the check, insert the next medium and start the procedure again. \nThe order of the media is irrelevant.\n" ) + # help text - media check 6/8 _( "<P><B>Note:</B> You cannot change the medium while it is used by the system.</P>" ) + # help text - media check 7/8 _( "<P>To check media before the installation, use the media check item in the boot menu.</P>" ) + # help text - media check 8/8 _( "<P>If you burn the media yourself, use the <B>pad</B> option in your recording\nsoftware. It avoids read errors at the end of the media during the check.</P>\n" ) # advice check of the media # for translators: split the message to more lines if needed, use max. 50 characters per line label = _( "It is recommended to check all installation media\nto avoid installation problems. To skip this step press 'Next'" ) contents = VBox( # combobox label CheckMedia.forced_start ? VBox(Left(Label(label)), VSpacing(0.6)) : Empty(), # combo box HBox( ComboBox( Id(:cddevices), _("&CD or DVD Drive"), CDdevices(CheckMedia.preferred_drive) ), VBox( # empty label for aligning the widgets Label(""), HBox( # push button label PushButton(Id(:start), _("&Start Check")), PushButton(Id(:eject), _("&Eject")) ) ), HStretch() ), # push button label Left(PushButton(Id(:iso_file), _("Check ISO File..."))), VSpacing(0.4), # widget label Left(Label(_("Status Information"))), RichText(Id(:log), Opt(:autoScrollDown), ""), VSpacing(0.4), # progress bar label ProgressBar(Id(:progress), _("Progress")), VSpacing(0.4), # push button label PushButton(Id(:stop), Label.CancelButton) ) Wizard.SetContents( caption, contents, help, GetInstArgs.enable_back, GetInstArgs.enable_next ) ret = nil while true # update state of the buttons (enabled/disabled) SetButtonState(false) ret = Convert.to_symbol(UI.UserInput) Builtins.y2milestone("ui: %1", ret) if ret == :next || ret == :back # avoid reproposing of the installation - always return `back in # the initial mode when the module start wasn't forced (after # language selection) ret = :back if Stage.initial && !CheckMedia.forced_start break elsif ret == :cancel ret = :abort break elsif ret == :abort if Popup.ConfirmAbort(:painless) ret = :abort break end elsif ret == :start || ret == :iso_file selecteddrive = "" @checking_file = ret == :iso_file if @checking_file # window title - open file dialog selecteddrive = UI.AskForExistingFile( @iso_filename, "*.iso", _("Select an ISO File to Check") ) # remember for the next run @iso_filename = selecteddrive if selecteddrive != nil else selecteddrive = Convert.to_string( UI.QueryWidget(Id(:cddevices), :Value) ) end if selecteddrive != nil && selecteddrive != "" SetButtonState(true) Builtins.y2milestone( "starting media check at drive %1", selecteddrive ) # progress message, %1 is CD device name (e.g. /dev/hdc) #UI::ChangeWidget(`id(`log), `LastLine, sformat(_("Check started (%1)...\n"), selecteddrive)); #LogLine(sformat(_("Check started (%1)...\n"), selecteddrive)); # try to read one byte from the medium res = Convert.to_integer( SCR.Execute( path(".target.bash"), Builtins.sformat( "/usr/bin/head -c 1 %1 > /dev/null", selecteddrive ) ) ) if res != 0 # error message: the medium cannot be read or no medium in the drive; %1 = drive, e.g. /dev/hdc LogLine( Ops.add( Ops.add( "<FONT COLOR=red>", Builtins.sformat( _("Cannot read medium in drive %1."), selecteddrive ) ), "</FONT>" ) ) else if md5sumTagPresent(selecteddrive) == false if !Popup.ContinueCancel( _( "The medium does not contain a MD5 checksum.\n" + "The content of the medium cannot be verified.\n" + "\n" + "Only readability of the medium will be checked.\n" ) ) next end end CheckMedia.Start(selecteddrive) loop = true aborted = false while loop loop = CheckMedia.Running CheckMedia.Process progress = CheckMedia.Progress data2 = CheckMedia.Info if data2 != nil && Ops.greater_than(Builtins.size(data2), 0) data2 = TranslateInfo(data2) # add new output to the log view info = Builtins.mergestring(data2, "") LogLine(info) end if Ops.greater_than(progress, 0) UI.ChangeWidget(Id(:progress), :Value, progress) end ui = Convert.to_symbol(UI.PollInput) if ui == :stop || ui == :cancel CheckMedia.Stop loop = false aborted = true elsif ui == :abort if Popup.ConfirmAbort(:painless) CheckMedia.Stop return :abort end end # sleep for a while Builtins.sleep(200) end SetButtonState(false) if aborted # the check has been canceled LogLine( Builtins.sformat( _("<UL><LI>Result: %1</LI></UL>"), _("<B>Canceled</B>") ) ) end end # process remaining output CheckMedia.Process data = CheckMedia.Info if data != nil && Ops.greater_than(Builtins.size(data), 0) data = TranslateInfo(data) # add new output to the log view info = Builtins.mergestring(data, "") LogLine(info) end CheckMedia.Release # finish the paragraph LogLine("<BR></P>") # set zero progress UI.ChangeWidget(Id(:progress), :Value, 0) end elsif ret == :eject selecteddrive = Convert.to_string( UI.QueryWidget(Id(:cddevices), :Value) ) command = Ops.add("/bin/eject ", selecteddrive) Builtins.y2milestone("Executing '%1'", command) res = Convert.to_map( SCR.Execute(path(".target.bash_output"), command) ) Builtins.y2milestone("Result: %1", res) else Builtins.y2warning("unknown UserInput: %1", ret) end end if Stage.initial # is the first medium in drive? RequireFirstMedium() end ret end |
- (Object) MainSequence
Main workflow of the idedma configuration
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File '../../src/include/checkmedia/ui.rb', line 583 def MainSequence aliases = { "checkmedia" => lambda { MainDialog() } } sequence = { "ws_start" => "checkmedia", "checkmedia" => { :abort => :abort, :next => :next } } Wizard.CreateDialog Wizard.SetDesktopIcon("checkmedia") ret = Sequencer.Run(aliases, sequence) UI.CloseDialog deep_copy(ret) end |
- (Object) md5sumTagPresent(input)
does the medium contain MD5 checksum in the application area?
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File '../../src/include/checkmedia/ui.rb', line 161 def md5sumTagPresent(input) command = Builtins.sformat("dd if=%1 bs=1 skip=33651 count=512", input) res = Convert.to_map(SCR.Execute(path(".target.bash_output"), command)) if Ops.get_integer(res, "exit", -1) != 0 Builtins.y2warning("command failed: %1", command) return nil end Builtins.y2milestone( "Read application area: %1", Ops.get_string(res, "stdout", "") ) Builtins.regexpmatch(Ops.get_string(res, "stdout", ""), "md5sum=") end |
- (Object) RequireFirstMedium
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File '../../src/include/checkmedia/ui.rb', line 246 def RequireFirstMedium while !InsertedCD1() # warning popup - the CD/DVD drive doesn't contain the first medium (CD1/DVD1) if Popup.AnyQuestion( Popup.NoHeadline, _("Insert the first installation medium."), Label.OKButton, Label.CancelButton, :focus_yes ) == false break end end nil end |
- (Object) SetButtonState(running)
68 69 70 71 72 73 74 75 76 |
# File '../../src/include/checkmedia/ui.rb', line 68 def SetButtonState(running) UI.ChangeWidget(Id(:stop), :Enabled, running) UI.ChangeWidget(Id(:progress), :Enabled, running) UI.ChangeWidget(Id(:next), :Enabled, !running) UI.ChangeWidget(Id(:start), :Enabled, !running) UI.ChangeWidget(Id(:back), :Enabled, !running) nil end |
- (Object) TranslateInfo(info)
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 |
# File '../../src/include/checkmedia/ui.rb', line 78 def TranslateInfo(info) info = deep_copy(info) ret = [] Builtins.foreach(info) do |i| parts = Builtins.splitstring(i, ":") key = String.CutBlanks(Ops.get(parts, 0, "")) val = String.CutBlanks(Ops.get(parts, 1, "")) trasmap = { # rich text message, %1 = CD identification "app" => Ops.add( Ops.add( Ops.add( Ops.add("<P><IMG SRC=\"", Directory.icondir), "/22x22/apps/yast-checkmedia.png\"> " ), _("<BIG><B>%1</B></BIG>") ), @checking_file ? Builtins.sformat(" (%1)", @iso_filename) : "" ), # rich text message, %1 medium number, e.g. CD1,CD2... "media" => _( "<UL><LI>Medium: %1</LI></UL>" ), # rich text message, %1 = size of the medium "size" => _( "<UL><LI>Size: %1</LI></UL>" ), # rich text message, %1 = result of the check "check" => _( "<UL><LI>Result: %1</LI></UL>" ), # rich text - error message "not an iso" => "<FONT COLOR=red>" + _( "The drive does not contain a medium or the ISO file system is broken." ) + "</FONT>" } if key == "check" # try to translate result string # correct MD5 if val == "md5sum ok" # result of the check - success val = "<FONT COLOR=\"darkGreen\">" + _("<B>OK</B> -- The medium has been successfully verified.") + "</FONT>" elsif val == "md5sum wrong" # wrong MD5 val = "<FONT COLOR=red>" + _( "<B>Error</B> -- MD5 sum does not match<BR>This medium should not be used." ) + "</FONT>" elsif val == "md5sum not checked" # the correct MD5 is unknown val = _( "<B>Unknown</B> -- The correct MD5 sum of the medium is unknown." ) # progress output elsif Builtins.issubstring(val, "%") key = "" Builtins.y2milestone( "Ignoring progress output: %1", Builtins.mergestring(Builtins.splitstring(val, ""), "\\b") ) end # don't print MD5 sum (it doesn't help user) elsif key == "md5" Builtins.y2milestone("Expected MD5 of the medium: %1", val) key = "" end newstr = Ops.get(trasmap, key, "") if newstr != nil && newstr != "" newstr = Builtins.sformat(newstr, val) ret = Builtins.add(ret, newstr) end end if info != nil Builtins.y2milestone("Translated info: %1", ret) deep_copy(ret) end |