gpt_parser: return a dict from get_partitions
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Wed, 10 Apr 2013 11:27:16 +0000 (14:27 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 19 Apr 2013 13:27:40 +0000 (16:27 +0300)
This makes the code more redable.

Change-Id: I1b41de463d108937ace8b9ce46f08deb0a4d6081
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
mic/utils/gpt_parser.py
mic/utils/partitionedfs.py

index e065b72..03e3aa3 100644 (file)
@@ -168,15 +168,18 @@ class GptParser:
 
     def get_partitions(self, primary = True):
         """ This is a generator which parses the GPT partition table and
 
     def get_partitions(self, primary = True):
         """ This is a generator which parses the GPT partition table and
-        generates the following tuples for each partition:
+        generates the following dictionary for each partition:
 
 
-        (Index, Partition type GUID, Partition GUID, First LBA, Last LBA,
-        Attribute flags, Partition name)
+        'index'     : the index of the partition in the partition table
+        'type_uuid' : partition type UUID
+        'part_uuid' : partition UUID
+        'first_lba' : the first LBA
+        'last_lba'  : the last LBA
+        'flags'     : attribute flags
+        'name'      : partition name
 
 
-        All the elements in the tuple except 'Index' correspond to the GPT
-        partition record format. Please, see the UEFI standard for the
-        description of these fields. The 'Index' element is simply the index
-        number of this entry in the partition table.
+        This dictionary corresponds to the GPT header format. Please, see the
+        UEFI standard for the description of these fields.
 
         If the 'primary' parameter is 'True', partitions from the primary GPT
         partition table are generated, otherwise partitions from the backup GPT
 
         If the 'primary' parameter is 'True', partitions from the primary GPT
         partition table are generated, otherwise partitions from the backup GPT
@@ -199,10 +202,10 @@ class GptParser:
 
             part_name = str(entry[5].decode('UTF-16').split('\0', 1)[0])
 
 
             part_name = str(entry[5].decode('UTF-16').split('\0', 1)[0])
 
-            yield (index,                     # 0. Partition table entry number
-                   _stringify_uuid(entry[0]), # 1. Partition type GUID
-                   _stringify_uuid(entry[1]), # 2. Partition GUID
-                   entry[2],                  # 3. First LBA
-                   entry[3],                  # 4. Last LBA
-                   entry[4],                  # 5. Attribute flags
-                   part_name)                 # 6. Partition name
+            yield { 'index'     : index,
+                    'type_uuid' : _stringify_uuid(entry[0]),
+                    'part_uuid' : _stringify_uuid(entry[1]),
+                    'first_lba' : entry[2],
+                    'last_lba'  : entry[3],
+                    'flags'     : entry[4],
+                    'name'      : part_name }
index f6ddd04..03999c5 100644 (file)
@@ -354,7 +354,7 @@ class PartitionedMount(Mount):
                     p = self.partitions[n]
                     if p['num'] == pnum:
                         # Found, assign PARTUUID
                     p = self.partitions[n]
                     if p['num'] == pnum:
                         # Found, assign PARTUUID
-                        p['partuuid'] = entry[2]
+                        p['partuuid'] = entry['part_uuid']
                         msger.debug("PARTUUID for partition %d of disk '%s' " \
                                     "(mount point '%s') is '%s'" % (pnum, \
                                     disk_name, p['mountpoint'], p['partuuid']))
                         msger.debug("PARTUUID for partition %d of disk '%s' " \
                                     "(mount point '%s') is '%s'" % (pnum, \
                                     disk_name, p['mountpoint'], p['partuuid']))