home *** CD-ROM | disk | FTP | other *** search
- /**
- * File:
- * modules/CheckMedia.ycp
- *
- * Summary:
- * Module for checking media intergrity
- *
- * Authors:
- * Ladislav Slezak <lslezak@suse.cz>
- *
- * $Id: CheckMedia.ycp 33383 2006-10-13 09:12:02Z lslezak $
- *
- * Input and output routines.
- *
- */
-
- {
- // Set the name of the module
- module "CheckMedia";
- import "Linuxrc";
- import "Report";
-
- textdomain "packager";
-
- string checkmedia = "/usr/bin/checkmedia";
-
- list<string> output = [];
- integer progress = 0;
- boolean inprogress = false;
-
- global string preferred_drive = "";
-
- // true if module start was forced - check=1 was found in the application area,
- // effects UI a little
- global boolean forced_start = false;
-
- // cache .probe.cdrom value
- // avoid reprobind during installation
- list<map> cd_cache = nil;
-
- global define list<map> DetectedCDDevices()
- {
- if (cd_cache == nil)
- {
- // the cache is not initialied, do it now
- list<map> cds = (list<map>)SCR::Read(.probe.cdrom);
-
- if (cds == nil)
- {
- // initialize to empty list
- cds = [];
- }
-
- cd_cache = cds;
- }
-
- return cd_cache;
- }
-
- global define boolean Start(string device) {
- // reset values
- output = [];
- progress = 0;
- inprogress = false;
-
- boolean ret = (boolean)SCR::Execute(.background.run_output, checkmedia + " " + device);
- return ret;
- }
-
- global define boolean Stop() {
- boolean ret = (boolean)SCR::Execute(.background.kill);
-
- return ret;
- }
-
- global define void Process() {
- if (inprogress)
- {
- // try to read whole lines
- list<string> out = (list<string>)SCR::Read(.background.newout);
-
- if (out != nil && size(out) > 0)
- {
- // remove the first part of the output
- // out = remove(out, 0);
- output = (list<string>)merge(output, out);
-
- // finished
- progress = 100;
- inprogress = false;
- }
- else
- {
- // read progress status
- string buffer = (string)SCR::Read(.background.buffer_out);
-
- if (buffer != "")
- {
- y2debug("buffer: %1", buffer);
-
- string percent = regexpsub(buffer, "([0-9]*)%.*$", "\\1");
-
- if (percent != nil)
- {
- progress = tointeger(percent);
- y2milestone("progress: %1%%", progress);
- }
- }
- }
- }
- else
- {
- list<string> out = (list<string>)SCR::Read(.background.newout);
-
- if (out != nil && size(out) > 0)
- {
- output = (list<string>)merge(output, out);
-
- // check whether we need to switch to progress mode
- string last = out[size(out) - 1]:"";
- if (regexpmatch(last, "^ *pad: "))
- {
- inprogress = true;
- y2milestone("Switching into progress mode");
- }
- }
- }
-
- return;
- }
-
- global define boolean Running() {
- boolean ret = (boolean)SCR::Read(.background.output_open);
- return ret;
- }
-
- /**
- * Return information printed by checkmedia utility
- * @ret list<string> checkmedia output
- */
- global define list<string> Info() {
- list<string> ret = output;
- output = [];
- return ret;
- }
-
- global define integer Progress() {
- return progress;
- }
-
- /* 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 installation source is not CD/DVD it returns
- * empty list.
- *
- * @return list<string> List of CD/DVD device names
- */
- global define list<string> GetReadyCDs() {
- // check whether we are using CD installation source
- string instmode = Linuxrc::InstallInf ("InstMode");
- y2milestone("Installation mode: %1", instmode);
-
- list<string> readycddrives = [];
-
- if (instmode == "cd" || instmode == "dvd")
- {
- // get CD device name
- string bootcd = Linuxrc::InstallInf ("Cdrom");
-
- if (bootcd != nil && bootcd != "")
- {
- readycddrives = [ sformat("/dev/%1", bootcd) ];
- }
- else
- {
- y2milestone("CD device device is not known, probing...");
- // booted from another location (network), test all CD drives
- list<map> cds = DetectedCDDevices();
-
- if (cds != nil)
- {
- foreach(map cd, cds, {
- string devname = cd["dev_name"]:"";
-
- // check whether the CD is ready
- if (cd["notready"]:false == false && devname != nil && devname != "")
- {
- readycddrives = add(readycddrives, devname);
- }
- }
- );
- }
- }
-
- y2milestone("Ready CD drives: %1", readycddrives);
- }
-
- return readycddrives;
- }
- }
-