diff options
Diffstat (limited to 'scripts/lib/wic/utils')
-rw-r--r-- | scripts/lib/wic/utils/partitionedfs.py | 154 | ||||
-rw-r--r-- | scripts/lib/wic/utils/runner.py | 16 |
2 files changed, 85 insertions, 85 deletions
diff --git a/scripts/lib/wic/utils/partitionedfs.py b/scripts/lib/wic/utils/partitionedfs.py index 2f884a3cb8..5a103bbc7e 100644 --- a/scripts/lib/wic/utils/partitionedfs.py +++ b/scripts/lib/wic/utils/partitionedfs.py @@ -129,14 +129,14 @@ class Image(object): self._partitions_layed_out = True # Go through partitions in the order they are added in .ks file - for n in range(len(self.partitions)): - p = self.partitions[n] + for num in range(len(self.partitions)): + part = self.partitions[num] - if not self.disks.has_key(p['disk_name']): + if not self.disks.has_key(part['disk_name']): raise ImageError("No disk %s for partition %s" \ - % (p['disk_name'], p['mountpoint'])) + % (part['disk_name'], part['mountpoint'])) - if ptable_format == 'msdos' and p['part_type']: + if ptable_format == 'msdos' and part['part_type']: # The --part-type can also be implemented for MBR partitions, # in which case it would map to the 1-byte "partition type" # filed at offset 3 of the partition entry. @@ -144,79 +144,79 @@ class Image(object): "implemented for msdos partitions") # Get the disk where the partition is located - d = self.disks[p['disk_name']] - d['numpart'] += 1 - if not p['no_table']: - d['realpart'] += 1 - d['ptable_format'] = ptable_format + disk = self.disks[part['disk_name']] + disk['numpart'] += 1 + if not part['no_table']: + disk['realpart'] += 1 + disk['ptable_format'] = ptable_format - if d['numpart'] == 1: + if disk['numpart'] == 1: if ptable_format == "msdos": overhead = MBR_OVERHEAD elif ptable_format == "gpt": overhead = GPT_OVERHEAD # Skip one sector required for the partitioning scheme overhead - d['offset'] += overhead + disk['offset'] += overhead - if d['realpart'] > 3: + if disk['realpart'] > 3: # Reserve a sector for EBR for every logical partition # before alignment is performed. if ptable_format == "msdos": - d['offset'] += 1 + disk['offset'] += 1 - if p['align']: + if part['align']: # If not first partition and we do have alignment set we need # to align the partition. # FIXME: This leaves a empty spaces to the disk. To fill the # gaps we could enlargea the previous partition? # Calc how much the alignment is off. - align_sectors = d['offset'] % (p['align'] * 1024 / self.sector_size) + align_sectors = disk['offset'] % (part['align'] * 1024 / self.sector_size) if align_sectors: # If partition is not aligned as required, we need # to move forward to the next alignment point - align_sectors = (p['align'] * 1024 / self.sector_size) - align_sectors + align_sectors = (part['align'] * 1024 / self.sector_size) - align_sectors msger.debug("Realignment for %s%s with %s sectors, original" " offset %s, target alignment is %sK." % - (p['disk_name'], d['numpart'], align_sectors, - d['offset'], p['align'])) + (part['disk_name'], disk['numpart'], align_sectors, + disk['offset'], part['align'])) # increase the offset so we actually start the partition on right alignment - d['offset'] += align_sectors + disk['offset'] += align_sectors - p['start'] = d['offset'] - d['offset'] += p['size'] + part['start'] = disk['offset'] + disk['offset'] += part['size'] - p['type'] = 'primary' - if not p['no_table']: - p['num'] = d['realpart'] + part['type'] = 'primary' + if not part['no_table']: + part['num'] = disk['realpart'] else: - p['num'] = 0 + part['num'] = 0 - if d['ptable_format'] == "msdos": - if d['realpart'] > 3: - p['type'] = 'logical' - p['num'] = d['realpart'] + 1 + if disk['ptable_format'] == "msdos": + if disk['realpart'] > 3: + part['type'] = 'logical' + part['num'] = disk['realpart'] + 1 - d['partitions'].append(n) + disk['partitions'].append(num) msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " "sectors (%d bytes)." \ - % (p['mountpoint'], p['disk_name'], p['num'], - p['start'], p['start'] + p['size'] - 1, - p['size'], p['size'] * self.sector_size)) + % (part['mountpoint'], part['disk_name'], part['num'], + part['start'], part['start'] + part['size'] - 1, + part['size'], part['size'] * self.sector_size)) # Once all the partitions have been layed out, we can calculate the # minumim disk sizes. - for d in self.disks.values(): - d['min_size'] = d['offset'] - if d['ptable_format'] == "gpt": - d['min_size'] += GPT_OVERHEAD + for disk in self.disks.values(): + disk['min_size'] = disk['offset'] + if disk['ptable_format'] == "gpt": + disk['min_size'] += GPT_OVERHEAD - d['min_size'] *= self.sector_size + disk['min_size'] *= self.sector_size def __create_partition(self, device, parttype, fstype, start, size): """ Create a partition on an image described by the 'device' object. """ @@ -237,21 +237,21 @@ class Image(object): self.layout_partitions() for dev in self.disks.keys(): - d = self.disks[dev] + disk = self.disks[dev] msger.debug("Initializing partition table for %s" % \ - (d['disk'].device)) + (disk['disk'].device)) exec_native_cmd("parted -s %s mklabel %s" % \ - (d['disk'].device, d['ptable_format']), + (disk['disk'].device, disk['ptable_format']), self.native_sysroot) msger.debug("Creating partitions") - for p in self.partitions: - if p['num'] == 0: + for part in self.partitions: + if part['num'] == 0: continue - d = self.disks[p['disk_name']] - if d['ptable_format'] == "msdos" and p['num'] == 5: + disk = self.disks[part['disk_name']] + if disk['ptable_format'] == "msdos" and part['num'] == 5: # Create an extended partition (note: extended # partition is described in MBR and contains all # logical partitions). The logical partitions save a @@ -263,17 +263,17 @@ class Image(object): # starts a sector before the first logical partition, # add a sector at the back, so that there is enough # room for all logical partitions. - self.__create_partition(d['disk'].device, "extended", - None, p['start'] - 1, - d['offset'] - p['start'] + 1) + self.__create_partition(disk['disk'].device, "extended", + None, part['start'] - 1, + disk['offset'] - part['start'] + 1) - if p['fstype'] == "swap": + if part['fstype'] == "swap": parted_fs_type = "linux-swap" - elif p['fstype'] == "vfat": + elif part['fstype'] == "vfat": parted_fs_type = "fat32" - elif p['fstype'] == "msdos": + elif part['fstype'] == "msdos": parted_fs_type = "fat16" - elif p['fstype'] == "ontrackdm6aux3": + elif part['fstype'] == "ontrackdm6aux3": parted_fs_type = "ontrackdm6aux3" else: # Type for ext2/ext3/ext4/btrfs @@ -281,55 +281,55 @@ class Image(object): # Boot ROM of OMAP boards require vfat boot partition to have an # even number of sectors. - if p['mountpoint'] == "/boot" and p['fstype'] in ["vfat", "msdos"] \ - and p['size'] % 2: + if part['mountpoint'] == "/boot" and part['fstype'] in ["vfat", "msdos"] \ + and part['size'] % 2: msger.debug("Substracting one sector from '%s' partition to " \ "get even number of sectors for the partition" % \ - p['mountpoint']) - p['size'] -= 1 + part['mountpoint']) + part['size'] -= 1 - self.__create_partition(d['disk'].device, p['type'], - parted_fs_type, p['start'], p['size']) + self.__create_partition(disk['disk'].device, part['type'], + parted_fs_type, part['start'], part['size']) - if p['part_type']: + if part['part_type']: msger.debug("partition %d: set type UID to %s" % \ - (p['num'], p['part_type'])) + (part['num'], part['part_type'])) exec_native_cmd("sgdisk --typecode=%d:%s %s" % \ - (p['num'], p['part_type'], - d['disk'].device), self.native_sysroot) + (part['num'], part['part_type'], + disk['disk'].device), self.native_sysroot) - if p['uuid']: + if part['uuid']: msger.debug("partition %d: set UUID to %s" % \ - (p['num'], p['uuid'])) + (part['num'], part['uuid'])) exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ - (p['num'], p['uuid'], d['disk'].device), + (part['num'], part['uuid'], disk['disk'].device), self.native_sysroot) - if p['boot']: - flag_name = "legacy_boot" if d['ptable_format'] == 'gpt' else "boot" + if part['boot']: + flag_name = "legacy_boot" if disk['ptable_format'] == 'gpt' else "boot" msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \ - (flag_name, p['num'], d['disk'].device)) + (flag_name, part['num'], disk['disk'].device)) exec_native_cmd("parted -s %s set %d %s on" % \ - (d['disk'].device, p['num'], flag_name), + (disk['disk'].device, part['num'], flag_name), self.native_sysroot) # Parted defaults to enabling the lba flag for fat16 partitions, # which causes compatibility issues with some firmware (and really # isn't necessary). if parted_fs_type == "fat16": - if d['ptable_format'] == 'msdos': + if disk['ptable_format'] == 'msdos': msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \ - (p['num'], d['disk'].device)) + (part['num'], disk['disk'].device)) exec_native_cmd("parted -s %s set %d lba off" % \ - (d['disk'].device, p['num']), + (disk['disk'].device, part['num']), self.native_sysroot) def cleanup(self): if self.disks: for dev in self.disks: - d = self.disks[dev] + disk = self.disks[dev] try: - d['disk'].cleanup() + disk['disk'].cleanup() except: pass @@ -354,8 +354,8 @@ class Image(object): def create(self): for dev in self.disks.keys(): - d = self.disks[dev] - d['disk'].create() + disk = self.disks[dev] + disk['disk'].create() self.__format_disks() diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py index f6a1d0828c..7431917ff0 100644 --- a/scripts/lib/wic/utils/runner.py +++ b/scripts/lib/wic/utils/runner.py @@ -62,13 +62,13 @@ def runtool(cmdln_or_args, catch=1): serr = subprocess.STDOUT try: - p = subprocess.Popen(cmdln_or_args, stdout=sout, - stderr=serr, shell=shell) - (sout, serr) = p.communicate() + process = subprocess.Popen(cmdln_or_args, stdout=sout, + stderr=serr, shell=shell) + (sout, serr) = process.communicate() # combine stdout and stderr, filter None out out = ''.join(filter(None, [sout, serr])) - except OSError, e: - if e.errno == 2: + except OSError, err: + if err.errno == 2: # [Errno 2] No such file or directory msger.error('Cannot run command: %s, lost dependency?' % cmd) else: @@ -77,12 +77,12 @@ def runtool(cmdln_or_args, catch=1): if catch != 3: os.close(dev_null) - return (p.returncode, out) + return (process.returncode, out) def show(cmdln_or_args): # show all the message using msger.verbose - rc, out = runtool(cmdln_or_args, catch=3) + rcode, out = runtool(cmdln_or_args, catch=3) if isinstance(cmdln_or_args, list): cmd = ' '.join(cmdln_or_args) @@ -100,7 +100,7 @@ def show(cmdln_or_args): msg += '\n +----------------' msger.verbose(msg) - return rc + return rcode def outs(cmdln_or_args, catch=1): # get the outputs of tools |