Fix error message for unintialized partition [Closes: 857]
authorUlrich Dangel <uli@spamt.net>
Sat, 12 Jun 2010 21:56:57 +0000 (23:56 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 25 Jun 2010 11:06:42 +0000 (13:06 +0200)
Do an explicit check if specified partition is at least readable and do
not use blkid for it as blkid uses returnvalue 2 for the same reason (no
information availabe, wrong permissions). This will give better feedback
to the user, e.g. if he forget to format the partition.

grml2usb

index 3982380..e85d574 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -974,19 +974,19 @@ def check_for_fat(partition):
 
     @partition: device name of partition"""
 
 
     @partition: device name of partition"""
 
+    if not os.access(partition, os.R_OK):
+        raise CriticalException("Failed to read device %s"
+                " (wrong UID/permissions or device/directory not present?)" % partition)
+
     try:
         udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
                                      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         filesystem = udev_info.communicate()[0].rstrip()
 
     try:
         udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
                                      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         filesystem = udev_info.communicate()[0].rstrip()
 
-        if udev_info.returncode == 2:
-            raise CriticalException("Failed to read device %s"
-                                    " (wrong UID/permissions or device/directory not present?)" % partition)
-
         if filesystem != "vfat":
             raise CriticalException(
         if filesystem != "vfat":
             raise CriticalException(
-                    "Partition %s does not contain a FAT16 filesystem." % (partition) \
-                    + "(Use --fat16 or run mkfs.vfat %s)" % (partition))
+                    "Partition %s does not contain a FAT16 filesystem. "
+                    "(Use --fat16 or run mkfs.vfat %s)" % (partition, partition))
 
     except OSError:
         raise CriticalException("Sorry, /sbin/blkid not available (install e2fsprogs?)")
 
     except OSError:
         raise CriticalException("Sorry, /sbin/blkid not available (install e2fsprogs?)")