Initialize/format harddisk in background
authorMike Looijmans <milo-software@users.sourceforge.net>
Mon, 4 Oct 2010 17:00:05 +0000 (19:00 +0200)
committerMike Looijmans <milo-software@users.sourceforge.net>
Mon, 4 Oct 2010 17:26:14 +0000 (19:26 +0200)
Tested with USB stick on VU. Still needs decent error reporting, but the
"good weather" behaviour is nice: No spinners.

Also a few minor fixes, harddisk initialization now works on OpenPLi 2.0 too.

lib/python/Components/Harddisk.py
lib/python/Components/Task.py
lib/python/Screens/HarddiskSetup.py

index 729c269..414c5cd 100755 (executable)
@@ -116,14 +116,18 @@ class Harddisk:
                return "%d.%03d GB" % (cap/1000, cap%1000)
 
        def model(self):
-               if self.device[:2] == "hd":
-                       return readFile('/proc/ide/' + self.device + '/model')
-               elif self.device[:2] == "sd":
-                       vendor = readFile(self.sysfsPath('device/vendor'))
-                       model = readFile(self.sysfsPath('device/model'))
-                       return vendor + '(' + model + ')'
-               else:
-                       assert False, "no hdX or sdX"
+               try:
+                       if self.device[:2] == "hd":
+                               return readFile('/proc/ide/' + self.device + '/model')
+                       elif self.device[:2] == "sd":
+                               vendor = readFile(self.sysfsPath('device/vendor'))
+                               model = readFile(self.sysfsPath('device/model'))
+                               return vendor + '(' + model + ')'
+                       else:
+                               raise Exception, "no hdX or sdX" 
+               except Exception, e:
+                       print "[Harddisk] Failed to get model:", e
+                       return "-?-"
 
        def free(self):
                dev = self.findMount()
@@ -219,7 +223,7 @@ class Harddisk:
                res = -1
                if self.type == self.DEVTYPE_UDEV:
                        # we can let udev do the job, re-read the partition table
-                       res = system('/sbin/sfdisk -R ' + self.disk_path)
+                       res = system('sfdisk -R ' + self.disk_path)
                        # give udev some time to make the mount, which it will do asynchronously
                        from time import sleep
                        sleep(3)
@@ -236,7 +240,11 @@ class Harddisk:
        def fsck(self):
                # We autocorrect any failures
                # TODO: we could check if the fs is actually ext3
-               cmd = "fsck.ext3 -f -p " + self.disk_path
+               if self.mount_device is None:
+                       dev = self.partitionPath("1")
+               else:
+                       dev = self.mount_device
+               cmd = "fsck.ext3 -f -p " + dev
                res = system(cmd)
                return (res >> 8)
 
index da463b2..19fb45b 100644 (file)
@@ -401,7 +401,6 @@ class DiskspacePrecondition(Condition):
 class ToolExistsPrecondition(Condition):
        def check(self, task):
                import os
-               
                if task.cmd[0]=='/':
                        self.realpath = task.cmd
                        print "[Task.py][ToolExistsPrecondition] WARNING: usage of absolute paths for tasks should be avoided!" 
@@ -411,8 +410,8 @@ class ToolExistsPrecondition(Condition):
                        path = os.environ.get('PATH', '').split(os.pathsep)
                        path.append(task.cwd + '/')
                        absolutes = filter(lambda file: os.access(file, os.X_OK), map(lambda directory, file = task.cmd: os.path.join(directory, file), path))
-                       if len(absolutes) > 0:
-                               self.realpath = task.cmd[0]
+                       if absolutes:
+                               self.realpath = absolutes[0]
                                return True
                return False 
 
index 6a8accd..9c95837 100644 (file)
@@ -6,31 +6,7 @@ from Components.Label import Label
 from Components.Pixmap import Pixmap
 from Screens.MessageBox import MessageBox
 import Components.Task
-from enigma import eTimer
 
-class HarddiskWait(Screen):
-       def doInit(self):
-               self.timer.stop()
-               result = self.hdd.initialize()
-               self.close(result)
-
-       def doCheck(self):
-               self.timer.stop()
-               Components.Task.job_manager.AddJob(self.hdd.createCheckJob())
-               self.close(None)
-
-       def __init__(self, session, hdd, type):
-               Screen.__init__(self, session)
-               self.hdd = hdd
-               self.timer = eTimer()
-               if type == HarddiskSetup.HARDDISK_INITIALIZE:
-                       text = _("Initializing storage device...")
-                       self.timer.callback.append(self.doInit)
-               else:
-                       text = _("Checking Filesystem...")
-                       self.timer.callback.append(self.doCheck)
-               self["wait"] = Label(text)
-               self.timer.start(100)
 
 class HarddiskSetup(Screen):
        HARDDISK_INITIALIZE = 1
@@ -86,14 +62,19 @@ class HarddiskSetup(Screen):
                        message = _("Do you really want to initialize the device?\nAll data on the disk will be lost!")
                else:
                        message = _("Do you really want to check the filesystem?\nThis could take lots of time!")
+               message += "\n" + _("You can continue watching TV etc. while this is running.")
                self.session.openWithCallback(self.hddConfirmed, MessageBox, message)
 
        def hddConfirmed(self, confirmed):
                if not confirmed:
                        return
-
                print "this will start either the initialize or the fsck now!"
-               self.session.openWithCallback(self.hddReady, HarddiskWait, self.hdd, self.type)
+               if self.type == self.HARDDISK_INITIALIZE:
+                       Components.Task.job_manager.AddJob(self.hdd.createInitializeJob())
+               else:
+                       Components.Task.job_manager.AddJob(self.hdd.createCheckJob())
+               self.close()
+
 
 class HarddiskSelection(Screen):
        def __init__(self, session):