Bump version to 0.2.2
[snf-image-creator] / image_creator / os_type / linux.py
index e38e777..0166129 100644 (file)
@@ -50,10 +50,10 @@ class Linux(Unix):
         if dev in self._uuid:
             return self._uuid[dev]
 
         if dev in self._uuid:
             return self._uuid[dev]
 
-        for attr in self.g.blkid(dev):
-            if attr[0] == 'UUID':
-                self._uuid[dev] = attr[1]
-                return attr[1]
+        uuid = self.g.vfs_uuid(dev)
+        assert len(uuid)
+        self._uuid[dev] = uuid
+        return uuid
 
     @sysprep()
     def fix_acpid(self, print_header=True):
 
     @sysprep()
     def fix_acpid(self, print_header=True):
@@ -65,7 +65,7 @@ class Linux(Unix):
             self.out.output('Fixing acpid powerdown action')
 
         powerbtn_action = '#!/bin/sh\n\nPATH=/sbin:/bin:/usr/bin\n' \
             self.out.output('Fixing acpid powerdown action')
 
         powerbtn_action = '#!/bin/sh\n\nPATH=/sbin:/bin:/usr/bin\n' \
-                                'shutdown -h now \"Power button pressed\"\n'
+                          'shutdown -h now "Power button pressed"\n'
 
         events_dir = '/etc/acpi/events'
         if not self.g.is_dir(events_dir):
 
         events_dir = '/etc/acpi/events'
         if not self.g.is_dir(events_dir):
@@ -91,28 +91,31 @@ class Linux(Unix):
                     action = m.group(1)
                     continue
 
                     action = m.group(1)
                     continue
 
-            if event.strip() == "button[ /]power":
+            if event.strip() in ("button[ /]power", "button/power.*"):
                 if action:
                     if not self.g.is_file(action):
                         self.out.warn("Acpid action file: %s does not exist" %
                 if action:
                     if not self.g.is_file(action):
                         self.out.warn("Acpid action file: %s does not exist" %
-                                                                        action)
+                                      action)
                         return
                         return
-                    self.g.copy_file_to_file(action, \
-                      "%s.orig.snf-image-creator-%d" % (action, time.time()))
+                    self.g.copy_file_to_file(action,
+                                             "%s.orig.snf-image-creator-%d" %
+                                             (action, time.time()))
                     self.g.write(action, powerbtn_action)
                     return
                 else:
                     self.g.write(action, powerbtn_action)
                     return
                 else:
-                    self.out.warn(
-                            "Acpid event file %s does not contain and action")
+                    self.out.warn("Acpid event file %s does not contain and "
+                                  "action")
                     return
             elif event.strip() == ".*":
                     return
             elif event.strip() == ".*":
-                self.out.warn(
-                    "Found action `.*'. Don't know how to handle this. " \
-                    "Please edit \%s' image file manually to make the " \
-                    "system immediatelly shutdown when an power button acpi " \
-                    "event occures" % action)
+                self.out.warn("Found action `.*'. Don't know how to handle "
+                              "this. Please edit `%s' image file manually to "
+                              "make the system immediatelly shutdown when an "
+                              "power button acpi event occures." %
+                              action.strip().split()[0])
                 return
 
                 return
 
+        self.out.warn("No acpi power button event found!")
+
     @sysprep()
     def remove_persistent_net_rules(self, print_header=True):
         """Remove udev rules that will keep network interface names persistent
     @sysprep()
     def remove_persistent_net_rules(self, print_header=True):
         """Remove udev rules that will keep network interface names persistent
@@ -153,12 +156,12 @@ class Linux(Unix):
     @sysprep()
     def use_persistent_block_device_names(self, print_header=True):
         """Scan fstab & grub configuration files and replace all non-persistent
     @sysprep()
     def use_persistent_block_device_names(self, print_header=True):
         """Scan fstab & grub configuration files and replace all non-persistent
-        device appearences with UUIDs.
+        device references with UUIDs.
         """
 
         if print_header:
         """
 
         if print_header:
-            self.out.output(
-                    'Replacing fstab & grub non-persistent device appearences')
+            self.out.output("Replacing fstab & grub non-persistent device "
+                            "references")
 
         # convert all devices in fstab to persistent
         persistent_root = self._persistent_fstab()
 
         # convert all devices in fstab to persistent
         persistent_root = self._persistent_fstab()