Cleanup disklabel.py
[snf-image] / snf-image-helper / disklabel.py
index 527d01c..b0c4b5e 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+#
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2013 GRNET S.A.
@@ -232,7 +233,7 @@ class Disklabel:
             """Print the Partition table"""
             val = ""
             for i in range(len(self.part)):
-                val = "%s%s\n" % (val, str(self.part[i]))
+                val += "%c: %s\n" % (chr(ord('a') + i), str(self.part[i]))
             return val
 
         def pack(self):
@@ -354,7 +355,7 @@ class Disklabel:
                            self.bbsize,
                            self.sbsize,
                            self.ptable.pack() +
-                           ((364 - self.npartitions*16) * '\x00'))
+                           ((364 - self.npartitions * 16) * '\x00'))
 
     def compute_checksum(self):
         """Compute the checksum of the disklabel"""
@@ -479,8 +480,8 @@ class Disklabel:
             "Magic Number: 0x%x\n" % self.magic + \
             "Drive type: %d\n" % self.dtype + \
             "Subtype: %d\n" % self.subtype + \
-            "Typename: %s\n" % self.typename + \
-            "Pack Identifier: %s\n" % self.packname + \
+            "Typename: %s\n" % self.typename.strip('\x00').strip() + \
+            "Pack Identifier: %s\n" % self.packname.strip('\x00').strip() + \
             "Number of bytes per sector: %d\n" % self.secsize + \
             "Number of data sectors per track: %d\n" % self.nsectors + \
             "Number of tracks per cylinder: %d\n" % self.ntracks + \
@@ -514,13 +515,10 @@ if __name__ == '__main__':
     parser.add_option("-l", "--list", action="store_true", dest="list",
                       default=False,
                       help="list the disklabel on the specified media")
-    parser.add_option("--print-last", action="store_true", dest="last_part",
-                      default=False,
+    parser.add_option("--get-last-partition", action="store_true",
+                      dest="last_part", default=False,
                       help="print the label of the last partition")
-    parser.add_option("--print-last-linux", action="store_true",
-                      dest="last_linux", default=False,
-                      help="print the linux number for the last partition")
-    parser.add_option("--print-duid", action="store_true", dest="duid",
+    parser.add_option("--get-duid", action="store_true", dest="duid",
                       default=False,
                       help="print the disklabel unique identifier")
     parser.add_option("-d", "--enlarge-disk", type="int", dest="disk_size",
@@ -549,12 +547,6 @@ if __name__ == '__main__':
     if options.last_part:
         print "%c" % chr(ord('a') + disklabel.get_last_partition_id())
 
-    if options.last_linux:
-        part_id = disklabel.get_last_partition_id()
-        # The linux kernel does not assign a partition for label 'c' that
-        # describes the whole disk
-        print part_id + (4 if part_id > 2 else 5)
-
     if options.disk_size is not None:
         disklabel.enlarge_disk(options.disk_size)