wic: fix short variable names

Made short variable names longer and more readable.

Fixed pylint warnings "Invalid variable name" and
"Invalid argument name".

(From OE-Core rev: 872cb0d5d79b26f34e6b35d7be8870d245021be4)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2015-09-02 13:58:16 +03:00 committed by Richard Purdie
parent 14b47e22f9
commit 791a3912d9
16 changed files with 286 additions and 289 deletions

View File

@ -87,9 +87,9 @@ class ConfigMgr(object):
if not ksconf: if not ksconf:
return return
ks = kickstart.read_kickstart(ksconf) ksobj = kickstart.read_kickstart(ksconf)
self.create['ks'] = ks self.create['ks'] = ksobj
self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0] self.create['name'] = os.path.splitext(os.path.basename(ksconf))[0]
self.create['name'] = misc.build_name(ksconf, self.create['name'] = misc.build_name(ksconf,

View File

@ -53,17 +53,17 @@ def verify_build_env():
CANNED_IMAGE_DIR = "lib/wic/canned-wks" # relative to scripts CANNED_IMAGE_DIR = "lib/wic/canned-wks" # relative to scripts
SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR
def build_canned_image_list(dl): def build_canned_image_list(path):
layers_path = misc.get_bitbake_var("BBLAYERS") layers_path = misc.get_bitbake_var("BBLAYERS")
canned_wks_layer_dirs = [] canned_wks_layer_dirs = []
if layers_path is not None: if layers_path is not None:
for layer_path in layers_path.split(): for layer_path in layers_path.split():
path = os.path.join(layer_path, SCRIPTS_CANNED_IMAGE_DIR) cpath = os.path.join(layer_path, SCRIPTS_CANNED_IMAGE_DIR)
canned_wks_layer_dirs.append(path) canned_wks_layer_dirs.append(cpath)
path = os.path.join(dl, CANNED_IMAGE_DIR) cpath = os.path.join(path, CANNED_IMAGE_DIR)
canned_wks_layer_dirs.append(path) canned_wks_layer_dirs.append(cpath)
return canned_wks_layer_dirs return canned_wks_layer_dirs
@ -99,14 +99,13 @@ def list_canned_images(scripts_path):
continue continue
if fname.endswith(".wks"): if fname.endswith(".wks"):
fullpath = os.path.join(canned_wks_dir, fname) fullpath = os.path.join(canned_wks_dir, fname)
f = open(fullpath, "r") with open(fullpath) as wks:
lines = f.readlines() for line in wks:
for line in lines: desc = ""
desc = "" idx = line.find("short-description:")
idx = line.find("short-description:") if idx != -1:
if idx != -1: desc = line[idx + len("short-description:"):].strip()
desc = line[idx + len("short-description:"):].strip() break
break
basename = os.path.splitext(fname)[0] basename = os.path.splitext(fname)[0]
print " %s\t\t%s" % (basename.ljust(30), desc) print " %s\t\t%s" % (basename.ljust(30), desc)
@ -115,24 +114,23 @@ def list_canned_image_help(scripts_path, fullpath):
""" """
List the help and params in the specified canned image. List the help and params in the specified canned image.
""" """
f = open(fullpath, "r")
lines = f.readlines()
found = False found = False
for line in lines: with open(fullpath) as wks:
if not found: for line in wks:
idx = line.find("long-description:") if not found:
idx = line.find("long-description:")
if idx != -1:
print
print line[idx + len("long-description:"):].strip()
found = True
continue
if not line.strip():
break
idx = line.find("#")
if idx != -1: if idx != -1:
print print line[idx + len("#:"):].rstrip()
print line[idx + len("long-description:"):].strip() else:
found = True break
continue
if not line.strip():
break
idx = line.find("#")
if idx != -1:
print line[idx + len("#:"):].rstrip()
else:
break
def list_source_plugins(): def list_source_plugins():
@ -186,10 +184,10 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
if debug: if debug:
msger.set_loglevel('debug') msger.set_loglevel('debug')
cr = creator.Creator() crobj = creator.Creator()
cr.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, crobj.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
wks_file, image_output_dir, oe_builddir, compressor or ""]) wks_file, image_output_dir, oe_builddir, compressor or ""])
print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file

View File

@ -80,11 +80,11 @@ class DirectImageCreator(BaseImageCreator):
in the partition table and logical partitions in the partition table and logical partitions
""" """
realnum = 0 realnum = 0
for n, p in enumerate(parts, 1): for pnum, part in enumerate(parts, 1):
if not p.no_table: if not part.no_table:
realnum += 1 realnum += 1
if n == num: if pnum == num:
if p.no_table: if part.no_table:
return 0 return 0
if self.ptable_format == 'msdos' and realnum > 3: if self.ptable_format == 'msdos' and realnum > 3:
# account for logical partition numbering, ex. sda5.. # account for logical partition numbering, ex. sda5..
@ -154,9 +154,9 @@ class DirectImageCreator(BaseImageCreator):
if not self.ks.handler.partition.partitions: if not self.ks.handler.partition.partitions:
partstr = "part / --size 1900 --ondisk sda --fstype=ext3" partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
args = partstr.split() args = partstr.split()
pd = self.ks.handler.partition.parse(args[1:]) part = self.ks.handler.partition.parse(args[1:])
if pd not in self.ks.handler.partition.partitions: if part not in self.ks.handler.partition.partitions:
self.ks.handler.partition.partitions.append(pd) self.ks.handler.partition.partitions.append(part)
# partitions list from kickstart file # partitions list from kickstart file
return kickstart.get_partitions(self.ks) return kickstart.get_partitions(self.ks)
@ -221,19 +221,19 @@ class DirectImageCreator(BaseImageCreator):
self.__image = Image(self.native_sysroot) self.__image = Image(self.native_sysroot)
for p in parts: for part in parts:
# as a convenience, set source to the boot partition source # as a convenience, set source to the boot partition source
# instead of forcing it to be set via bootloader --source # instead of forcing it to be set via bootloader --source
if not self.ks.handler.bootloader.source and p.mountpoint == "/boot": if not self.ks.handler.bootloader.source and part.mountpoint == "/boot":
self.ks.handler.bootloader.source = p.source self.ks.handler.bootloader.source = part.source
fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
for p in parts: for part in parts:
# get rootfs size from bitbake variable if it's not set in .ks file # get rootfs size from bitbake variable if it's not set in .ks file
if not p.size: if not part.size:
# and if rootfs name is specified for the partition # and if rootfs name is specified for the partition
image_name = p.get_rootfs() image_name = part.get_rootfs()
if image_name: if image_name:
# Bitbake variable ROOTFS_SIZE is calculated in # Bitbake variable ROOTFS_SIZE is calculated in
# Image._get_rootfs_size method from meta/lib/oe/image.py # Image._get_rootfs_size method from meta/lib/oe/image.py
@ -242,7 +242,7 @@ class DirectImageCreator(BaseImageCreator):
rsize_bb = get_bitbake_var('ROOTFS_SIZE', image_name) rsize_bb = get_bitbake_var('ROOTFS_SIZE', image_name)
if rsize_bb: if rsize_bb:
# convert from Kb to Mb # convert from Kb to Mb
p.size = int(rsize_bb) / 1024 part.size = int(rsize_bb) / 1024
# need to create the filesystems in order to get their # need to create the filesystems in order to get their
# sizes before we can add them and do the layout. # sizes before we can add them and do the layout.
# Image.create() actually calls __format_disks() to create # Image.create() actually calls __format_disks() to create
@ -250,22 +250,22 @@ class DirectImageCreator(BaseImageCreator):
# self.assemble() calls Image.assemble() which calls # self.assemble() calls Image.assemble() which calls
# __write_partitition() for each partition to dd the fs # __write_partitition() for each partition to dd the fs
# into the partitions. # into the partitions.
p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir, part.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir,
self.bootimg_dir, self.kernel_dir, self.native_sysroot) self.bootimg_dir, self.kernel_dir, self.native_sysroot)
self.__image.add_partition(int(p.size), self.__image.add_partition(int(part.size),
p.disk, part.disk,
p.mountpoint, part.mountpoint,
p.source_file, part.source_file,
p.fstype, part.fstype,
p.label, part.label,
fsopts=p.fsopts, fsopts=part.fsopts,
boot=p.active, boot=part.active,
align=p.align, align=part.align,
no_table=p.no_table, no_table=part.no_table,
part_type=p.part_type, part_type=part.part_type,
uuid=p.uuid) uuid=part.uuid)
if fstab_path: if fstab_path:
shutil.move(fstab_path + ".orig", fstab_path) shutil.move(fstab_path + ".orig", fstab_path)
@ -336,14 +336,14 @@ class DirectImageCreator(BaseImageCreator):
msg += ' %s\n\n' % full_path msg += ' %s\n\n' % full_path
msg += 'The following build artifacts were used to create the image(s):\n' msg += 'The following build artifacts were used to create the image(s):\n'
for p in parts: for part in parts:
if p.get_rootfs() is None: if part.get_rootfs() is None:
continue continue
if p.mountpoint == '/': if part.mountpoint == '/':
suffix = ':' suffix = ':'
else: else:
suffix = '["%s"]:' % (p.mountpoint or p.label) suffix = '["%s"]:' % (part.mountpoint or part.label)
msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), p.get_rootfs()) msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), part.get_rootfs())
msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
msg += ' KERNEL_DIR: %s\n' % self.kernel_dir msg += ' KERNEL_DIR: %s\n' % self.kernel_dir

View File

@ -58,65 +58,65 @@ def read_kickstart(path):
def __init__(self): def __init__(self):
superclass.__init__(self, mapping=commandMap[using_version]) superclass.__init__(self, mapping=commandMap[using_version])
ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=True) kickstart = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=True)
try: try:
ks.readKickstart(path) kickstart.readKickstart(path)
except (kserrors.KickstartParseError, kserrors.KickstartError), err: except (kserrors.KickstartParseError, kserrors.KickstartError), err:
msger.warning("Errors occurred when parsing kickstart file: %s\n" % path) msger.warning("Errors occurred when parsing kickstart file: %s\n" % path)
msger.error("%s" % err) msger.error("%s" % err)
return ks return kickstart
def get_image_size(ks, default=None): def get_image_size(kickstart, default=None):
__size = 0 __size = 0
for p in ks.handler.partition.partitions: for part in kickstart.handler.partition.partitions:
if p.mountpoint == "/" and p.size: if part.mountpoint == "/" and part.size:
__size = p.size __size = part.size
if __size > 0: if __size > 0:
return int(__size) * 1024L return int(__size) * 1024L
else: else:
return default return default
def get_image_fstype(ks, default=None): def get_image_fstype(kickstart, default=None):
for p in ks.handler.partition.partitions: for part in kickstart.handler.partition.partitions:
if p.mountpoint == "/" and p.fstype: if part.mountpoint == "/" and part.fstype:
return p.fstype return part.fstype
return default return default
def get_image_fsopts(ks, default=None): def get_image_fsopts(kickstart, default=None):
for p in ks.handler.partition.partitions: for part in kickstart.handler.partition.partitions:
if p.mountpoint == "/" and p.fsopts: if part.mountpoint == "/" and part.fsopts:
return p.fsopts return part.fsopts
return default return default
def get_timeout(ks, default=None): def get_timeout(kickstart, default=None):
if not hasattr(ks.handler.bootloader, "timeout"): if not hasattr(kickstart.handler.bootloader, "timeout"):
return default return default
if ks.handler.bootloader.timeout is None: if kickstart.handler.bootloader.timeout is None:
return default return default
return int(ks.handler.bootloader.timeout) return int(kickstart.handler.bootloader.timeout)
def get_kernel_args(ks, default="ro rd.live.image"): def get_kernel_args(kickstart, default="ro rd.live.image"):
if not hasattr(ks.handler.bootloader, "appendLine"): if not hasattr(kickstart.handler.bootloader, "appendLine"):
return default return default
if ks.handler.bootloader.appendLine is None: if kickstart.handler.bootloader.appendLine is None:
return default return default
return "%s %s" %(default, ks.handler.bootloader.appendLine) return "%s %s" %(default, kickstart.handler.bootloader.appendLine)
def get_menu_args(ks, default=""): def get_menu_args(kickstart, default=""):
if not hasattr(ks.handler.bootloader, "menus"): if not hasattr(kickstart.handler.bootloader, "menus"):
return default return default
if ks.handler.bootloader.menus in (None, ""): if kickstart.handler.bootloader.menus in (None, ""):
return default return default
return "%s" % ks.handler.bootloader.menus return "%s" % kickstart.handler.bootloader.menus
def get_default_kernel(ks, default=None): def get_default_kernel(kickstart, default=None):
if not hasattr(ks.handler.bootloader, "default"): if not hasattr(kickstart.handler.bootloader, "default"):
return default return default
if not ks.handler.bootloader.default: if not kickstart.handler.bootloader.default:
return default return default
return ks.handler.bootloader.default return kickstart.handler.bootloader.default
def get_partitions(ks): def get_partitions(kickstart):
return ks.handler.partition.partitions return kickstart.handler.partition.partitions

View File

@ -154,7 +154,7 @@ class Wic_PartData(FC4_PartData):
else: else:
return 0 return 0
def prepare(self, cr, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir, def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir,
kernel_dir, native_sysroot): kernel_dir, native_sysroot):
""" """
Prepare content for individual partitions, depending on Prepare content for individual partitions, depending on
@ -199,18 +199,18 @@ class Wic_PartData(FC4_PartData):
self._source_methods = pluginmgr.get_source_plugin_methods(\ self._source_methods = pluginmgr.get_source_plugin_methods(\
self.source, partition_methods) self.source, partition_methods)
self._source_methods["do_configure_partition"](self, self.sourceparams_dict, self._source_methods["do_configure_partition"](self, self.sourceparams_dict,
cr, cr_workdir, creator, cr_workdir,
oe_builddir, oe_builddir,
bootimg_dir, bootimg_dir,
kernel_dir, kernel_dir,
native_sysroot) native_sysroot)
self._source_methods["do_stage_partition"](self, self.sourceparams_dict, self._source_methods["do_stage_partition"](self, self.sourceparams_dict,
cr, cr_workdir, creator, cr_workdir,
oe_builddir, oe_builddir,
bootimg_dir, kernel_dir, bootimg_dir, kernel_dir,
native_sysroot) native_sysroot)
self._source_methods["do_prepare_partition"](self, self.sourceparams_dict, self._source_methods["do_prepare_partition"](self, self.sourceparams_dict,
cr, cr_workdir, creator, cr_workdir,
oe_builddir, oe_builddir,
bootimg_dir, kernel_dir, rootfs_dir, bootimg_dir, kernel_dir, rootfs_dir,
native_sysroot) native_sysroot)
@ -441,21 +441,21 @@ class Wic_PartData(FC4_PartData):
msger.warning("Creating of an empty squashfs %s partition was attempted. " \ msger.warning("Creating of an empty squashfs %s partition was attempted. " \
"Proceeding as requested." % self.mountpoint) "Proceeding as requested." % self.mountpoint)
fs = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
os.path.isfile(fs) and os.remove(fs) os.path.isfile(path) and os.remove(path)
# it is not possible to create a squashfs without source data, # it is not possible to create a squashfs without source data,
# thus prepare an empty temp dir that is used as source # thus prepare an empty temp dir that is used as source
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
squashfs_cmd = "mksquashfs %s %s -noappend" % \ squashfs_cmd = "mksquashfs %s %s -noappend" % \
(tmpdir, fs) (tmpdir, path)
exec_native_cmd(squashfs_cmd, native_sysroot) exec_native_cmd(squashfs_cmd, native_sysroot)
os.rmdir(tmpdir) os.rmdir(tmpdir)
# get the rootfs size in the right units for kickstart (kB) # get the rootfs size in the right units for kickstart (kB)
du_cmd = "du -Lbks %s" % fs du_cmd = "du -Lbks %s" % path
out = exec_cmd(du_cmd) out = exec_cmd(du_cmd)
fs_size = out.split()[0] fs_size = out.split()[0]
@ -465,17 +465,17 @@ class Wic_PartData(FC4_PartData):
""" """
Prepare a swap partition. Prepare a swap partition.
""" """
fs = "%s/fs.%s" % (cr_workdir, self.fstype) path = "%s/fs.%s" % (cr_workdir, self.fstype)
dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
(fs, self.size) (path, self.size)
exec_cmd(dd_cmd) exec_cmd(dd_cmd)
import uuid import uuid
label_str = "" label_str = ""
if self.label: if self.label:
label_str = "-L %s" % self.label label_str = "-L %s" % self.label
mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), fs) mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
exec_native_cmd(mkswap_cmd, native_sysroot) exec_native_cmd(mkswap_cmd, native_sysroot)
@ -490,37 +490,37 @@ class Wic_Partition(FC4_Partition):
(option, value)) (option, value))
setattr(parser.values, option.dest, value) setattr(parser.values, option.dest, value)
op = FC4_Partition._getParser(self) parser = FC4_Partition._getParser(self)
# The alignment value is given in kBytes. e.g., value 8 means that # The alignment value is given in kBytes. e.g., value 8 means that
# the partition is aligned to start from 8096 byte boundary. # the partition is aligned to start from 8096 byte boundary.
op.add_option("--align", type="int", action="store", dest="align", parser.add_option("--align", type="int", action="store", dest="align",
default=None) default=None)
op.add_option("--extoptions", type="string", action="store", dest="extopts", parser.add_option("--extoptions", type="string", action="store", dest="extopts",
default=None) default=None)
op.add_option("--part-type", type="string", action="store", dest="part_type", parser.add_option("--part-type", type="string", action="store", dest="part_type",
default=None) default=None)
# use specified source file to fill the partition # use specified source file to fill the partition
# and calculate partition size # and calculate partition size
op.add_option("--source", type="string", action="store", parser.add_option("--source", type="string", action="store",
dest="source", default=None) dest="source", default=None)
# comma-separated list of param=value pairs # comma-separated list of param=value pairs
op.add_option("--sourceparams", type="string", action="store", parser.add_option("--sourceparams", type="string", action="store",
dest="sourceparams", default=None) dest="sourceparams", default=None)
# use specified rootfs path to fill the partition # use specified rootfs path to fill the partition
op.add_option("--rootfs-dir", type="string", action="store", parser.add_option("--rootfs-dir", type="string", action="store",
dest="rootfs", default=None) dest="rootfs", default=None)
# wether to add the partition in the partition table # wether to add the partition in the partition table
op.add_option("--no-table", dest="no_table", action="store_true", parser.add_option("--no-table", dest="no_table", action="store_true",
default=False) default=False)
# extra space beyond the partition size # extra space beyond the partition size
op.add_option("--extra-space", dest="extra_space", action="store", parser.add_option("--extra-space", dest="extra_space", action="store",
type="size", nargs=1, default="10M") type="size", nargs=1, default="10M")
op.add_option("--overhead-factor", dest="overhead_factor", parser.add_option("--overhead-factor", dest="overhead_factor",
action="callback", callback=overhead_cb, type="float", action="callback", callback=overhead_cb, type="float",
nargs=1, default=1.3) nargs=1, default=1.3)
op.add_option("--use-uuid", dest="use_uuid", action="store_true", parser.add_option("--use-uuid", dest="use_uuid", action="store_true",
default=False) default=False)
op.add_option("--uuid") parser.add_option("--uuid")
return op return parser

View File

@ -49,12 +49,12 @@ class Wic_Bootloader(F8_Bootloader):
return retval return retval
def _getParser(self): def _getParser(self):
op = F8_Bootloader._getParser(self) parser = F8_Bootloader._getParser(self)
op.add_option("--menus", dest="menus") parser.add_option("--menus", dest="menus")
op.add_option("--ptable", dest="ptable", choices=("msdos", "gpt"), parser.add_option("--ptable", dest="ptable", choices=("msdos", "gpt"),
default="msdos") default="msdos")
# use specified source plugin to implement bootloader-specific methods # use specified source plugin to implement bootloader-specific methods
op.add_option("--source", type="string", action="store", parser.add_option("--source", type="string", action="store",
dest="source", default=None) dest="source", default=None)
return op return parser

View File

@ -151,10 +151,10 @@ def _split_msg(head, msg):
msg = msg.lstrip() msg = msg.lstrip()
head = '\r' + head head = '\r' + head
m = PREFIX_RE.match(msg) match = PREFIX_RE.match(msg)
if m: if match:
head += ' <%s>' % m.group(1) head += ' <%s>' % match.group(1)
msg = m.group(2) msg = match.group(2)
return head, msg return head, msg
@ -271,9 +271,8 @@ def set_logfile(fpath):
def _savelogf(): def _savelogf():
if LOG_FILE_FP: if LOG_FILE_FP:
fp = open(LOG_FILE_FP, 'w') with open(LOG_FILE_FP, 'w') as log:
fp.write(LOG_CONTENT) log.write(LOG_CONTENT)
fp.close()
if LOG_FILE_FP is not None: if LOG_FILE_FP is not None:
warning('duplicate log file configuration') warning('duplicate log file configuration')

View File

@ -48,7 +48,7 @@ class PluginMgr(object):
self.plugin_dir = scripts_path + PLUGIN_DIR self.plugin_dir = scripts_path + PLUGIN_DIR
self.layers_path = None self.layers_path = None
def _build_plugin_dir_list(self, dl, ptype): def _build_plugin_dir_list(self, plugin_dir, ptype):
if self.layers_path is None: if self.layers_path is None:
self.layers_path = get_bitbake_var("BBLAYERS") self.layers_path = get_bitbake_var("BBLAYERS")
layer_dirs = [] layer_dirs = []
@ -58,7 +58,7 @@ class PluginMgr(object):
path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR, ptype) path = os.path.join(layer_path, SCRIPTS_PLUGIN_DIR, ptype)
layer_dirs.append(path) layer_dirs.append(path)
path = os.path.join(dl, ptype) path = os.path.join(plugin_dir, ptype)
layer_dirs.append(path) layer_dirs.append(path)
return layer_dirs return layer_dirs

View File

@ -51,7 +51,7 @@ class SourcePlugin(_Plugin):
""" """
@classmethod @classmethod
def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir, def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
bootimg_dir, kernel_dir, native_sysroot): bootimg_dir, kernel_dir, native_sysroot):
""" """
Called after all partitions have been prepared and assembled into a Called after all partitions have been prepared and assembled into a
@ -61,7 +61,7 @@ class SourcePlugin(_Plugin):
msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name) msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name)
@classmethod @classmethod
def do_stage_partition(cls, part, source_params, cr, cr_workdir, def do_stage_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -78,7 +78,7 @@ class SourcePlugin(_Plugin):
msger.debug("SourcePlugin: do_stage_partition: part: %s" % part) msger.debug("SourcePlugin: do_stage_partition: part: %s" % part)
@classmethod @classmethod
def do_configure_partition(cls, part, source_params, cr, cr_workdir, def do_configure_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -89,7 +89,7 @@ class SourcePlugin(_Plugin):
msger.debug("SourcePlugin: do_configure_partition: part: %s" % part) msger.debug("SourcePlugin: do_configure_partition: part: %s" % part)
@classmethod @classmethod
def do_prepare_partition(cls, part, source_params, cr, cr_workdir, def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, rootfs_dir, oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
native_sysroot): native_sysroot):
""" """
@ -99,9 +99,9 @@ class SourcePlugin(_Plugin):
msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part) msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
def get_plugins(typen): def get_plugins(typen):
ps = ImagerPlugin.get_plugins() plugins = ImagerPlugin.get_plugins()
if typen in ps: if typen in plugins:
return ps[typen] return plugins[typen]
else: else:
return None return None

View File

@ -50,8 +50,8 @@ class DirectPlugin(ImagerPlugin):
""" """
krootfs_dir = {} krootfs_dir = {}
for rootfs_dir in rootfs_dirs.split(' '): for rootfs_dir in rootfs_dirs.split(' '):
k, v = rootfs_dir.split('=') key, val = rootfs_dir.split('=')
krootfs_dir[k] = v krootfs_dir[key] = val
return krootfs_dir return krootfs_dir

View File

@ -41,16 +41,16 @@ class BootimgEFIPlugin(SourcePlugin):
name = 'bootimg-efi' name = 'bootimg-efi'
@classmethod @classmethod
def do_configure_grubefi(cls, hdddir, cr, cr_workdir): def do_configure_grubefi(cls, hdddir, creator, cr_workdir):
""" """
Create loader-specific (grub-efi) config Create loader-specific (grub-efi) config
""" """
options = cr.ks.handler.bootloader.appendLine options = creator.ks.handler.bootloader.appendLine
grubefi_conf = "" grubefi_conf = ""
grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
grubefi_conf += "default=boot\n" grubefi_conf += "default=boot\n"
timeout = kickstart.get_timeout(cr.ks) timeout = kickstart.get_timeout(creator.ks)
if not timeout: if not timeout:
timeout = 0 timeout = 0
grubefi_conf += "timeout=%s\n" % timeout grubefi_conf += "timeout=%s\n" % timeout
@ -59,7 +59,7 @@ class BootimgEFIPlugin(SourcePlugin):
kernel = "/bzImage" kernel = "/bzImage"
grubefi_conf += "linux %s root=%s rootwait %s\n" \ grubefi_conf += "linux %s root=%s rootwait %s\n" \
% (kernel, cr.rootdev, options) % (kernel, creator.rootdev, options)
grubefi_conf += "}\n" grubefi_conf += "}\n"
msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \ msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
@ -69,7 +69,7 @@ class BootimgEFIPlugin(SourcePlugin):
cfg.close() cfg.close()
@classmethod @classmethod
def do_configure_gummiboot(cls, hdddir, cr, cr_workdir): def do_configure_gummiboot(cls, hdddir, creator, cr_workdir):
""" """
Create loader-specific (gummiboot) config Create loader-specific (gummiboot) config
""" """
@ -79,9 +79,9 @@ class BootimgEFIPlugin(SourcePlugin):
install_cmd = "install -d %s/loader/entries" % hdddir install_cmd = "install -d %s/loader/entries" % hdddir
exec_cmd(install_cmd) exec_cmd(install_cmd)
options = cr.ks.handler.bootloader.appendLine options = creator.ks.handler.bootloader.appendLine
timeout = kickstart.get_timeout(cr.ks) timeout = kickstart.get_timeout(creator.ks)
if not timeout: if not timeout:
timeout = 0 timeout = 0
@ -100,7 +100,7 @@ class BootimgEFIPlugin(SourcePlugin):
boot_conf = "" boot_conf = ""
boot_conf += "title boot\n" boot_conf += "title boot\n"
boot_conf += "linux %s\n" % kernel boot_conf += "linux %s\n" % kernel
boot_conf += "options LABEL=Boot root=%s %s\n" % (cr.rootdev, options) boot_conf += "options LABEL=Boot root=%s %s\n" % (creator.rootdev, options)
msger.debug("Writing gummiboot config %s/hdd/boot/loader/entries/boot.conf" \ msger.debug("Writing gummiboot config %s/hdd/boot/loader/entries/boot.conf" \
% cr_workdir) % cr_workdir)
@ -110,7 +110,7 @@ class BootimgEFIPlugin(SourcePlugin):
@classmethod @classmethod
def do_configure_partition(cls, part, source_params, cr, cr_workdir, def do_configure_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -125,9 +125,9 @@ class BootimgEFIPlugin(SourcePlugin):
try: try:
if source_params['loader'] == 'grub-efi': if source_params['loader'] == 'grub-efi':
cls.do_configure_grubefi(hdddir, cr, cr_workdir) cls.do_configure_grubefi(hdddir, creator, cr_workdir)
elif source_params['loader'] == 'gummiboot': elif source_params['loader'] == 'gummiboot':
cls.do_configure_gummiboot(hdddir, cr, cr_workdir) cls.do_configure_gummiboot(hdddir, creator, cr_workdir)
else: else:
msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader']) msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
except KeyError: except KeyError:
@ -135,7 +135,7 @@ class BootimgEFIPlugin(SourcePlugin):
@classmethod @classmethod
def do_prepare_partition(cls, part, source_params, cr, cr_workdir, def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
rootfs_dir, native_sysroot): rootfs_dir, native_sysroot):
""" """
@ -148,7 +148,7 @@ class BootimgEFIPlugin(SourcePlugin):
if not bootimg_dir: if not bootimg_dir:
msger.error("Couldn't find HDDDIR, exiting\n") msger.error("Couldn't find HDDDIR, exiting\n")
# just so the result notes display it # just so the result notes display it
cr.set_bootimg_dir(bootimg_dir) creator.set_bootimg_dir(bootimg_dir)
staging_kernel_dir = kernel_dir staging_kernel_dir = kernel_dir

View File

@ -41,36 +41,36 @@ class BootimgPcbiosPlugin(SourcePlugin):
name = 'bootimg-pcbios' name = 'bootimg-pcbios'
@classmethod @classmethod
def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir, def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
bootimg_dir, kernel_dir, native_sysroot): bootimg_dir, kernel_dir, native_sysroot):
""" """
Called after all partitions have been prepared and assembled into a Called after all partitions have been prepared and assembled into a
disk image. In this case, we install the MBR. disk image. In this case, we install the MBR.
""" """
mbrfile = "%s/syslinux/" % bootimg_dir mbrfile = "%s/syslinux/" % bootimg_dir
if cr.ptable_format == 'msdos': if creator.ptable_format == 'msdos':
mbrfile += "mbr.bin" mbrfile += "mbr.bin"
elif cr.ptable_format == 'gpt': elif creator.ptable_format == 'gpt':
mbrfile += "gptmbr.bin" mbrfile += "gptmbr.bin"
else: else:
msger.error("Unsupported partition table: %s" % cr.ptable_format) msger.error("Unsupported partition table: %s" % creator.ptable_format)
if not os.path.exists(mbrfile): if not os.path.exists(mbrfile):
msger.error("Couldn't find %s. If using the -e option, do you " msger.error("Couldn't find %s. If using the -e option, do you "
"have the right MACHINE set in local.conf? If not, " "have the right MACHINE set in local.conf? If not, "
"is the bootimg_dir path correct?" % mbrfile) "is the bootimg_dir path correct?" % mbrfile)
full_path = cr._full_path(workdir, disk_name, "direct") full_path = creator._full_path(workdir, disk_name, "direct")
msger.debug("Installing MBR on disk %s as %s with size %s bytes" \ msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size'])) % (disk_name, full_path, disk['min_size']))
rc = runner.show(['dd', 'if=%s' % mbrfile, rcode = runner.show(['dd', 'if=%s' % mbrfile,
'of=%s' % full_path, 'conv=notrunc']) 'of=%s' % full_path, 'conv=notrunc'])
if rc != 0: if rcode != 0:
raise ImageError("Unable to set MBR to %s" % full_path) raise ImageError("Unable to set MBR to %s" % full_path)
@classmethod @classmethod
def do_configure_partition(cls, part, source_params, cr, cr_workdir, def do_configure_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -89,11 +89,11 @@ class BootimgPcbiosPlugin(SourcePlugin):
else: else:
splashline = "" splashline = ""
options = cr.ks.handler.bootloader.appendLine options = creator.ks.handler.bootloader.appendLine
syslinux_conf = "" syslinux_conf = ""
syslinux_conf += "PROMPT 0\n" syslinux_conf += "PROMPT 0\n"
timeout = kickstart.get_timeout(cr.ks) timeout = kickstart.get_timeout(creator.ks)
if not timeout: if not timeout:
timeout = 0 timeout = 0
syslinux_conf += "TIMEOUT " + str(timeout) + "\n" syslinux_conf += "TIMEOUT " + str(timeout) + "\n"
@ -110,7 +110,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
syslinux_conf += "KERNEL " + kernel + "\n" syslinux_conf += "KERNEL " + kernel + "\n"
syslinux_conf += "APPEND label=boot root=%s %s\n" % \ syslinux_conf += "APPEND label=boot root=%s %s\n" % \
(cr.rootdev, options) (creator.rootdev, options)
msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \ msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
% cr_workdir) % cr_workdir)
@ -119,7 +119,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
cfg.close() cfg.close()
@classmethod @classmethod
def do_prepare_partition(cls, part, source_params, cr, cr_workdir, def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
rootfs_dir, native_sysroot): rootfs_dir, native_sysroot):
""" """
@ -141,7 +141,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
if not _has_syslinux(bootimg_dir): if not _has_syslinux(bootimg_dir):
msger.error("Please build syslinux first\n") msger.error("Please build syslinux first\n")
# just so the result notes display it # just so the result notes display it
cr.set_bootimg_dir(bootimg_dir) creator.set_bootimg_dir(bootimg_dir)
staging_kernel_dir = kernel_dir staging_kernel_dir = kernel_dir

View File

@ -54,7 +54,7 @@ class IsoImagePlugin(SourcePlugin):
name = 'isoimage-isohybrid' name = 'isoimage-isohybrid'
@classmethod @classmethod
def do_configure_syslinux(cls, cr, cr_workdir): def do_configure_syslinux(cls, creator, cr_workdir):
""" """
Create loader-specific (syslinux) config Create loader-specific (syslinux) config
""" """
@ -64,9 +64,9 @@ class IsoImagePlugin(SourcePlugin):
else: else:
splashline = "" splashline = ""
options = cr.ks.handler.bootloader.appendLine options = creator.ks.handler.bootloader.appendLine
timeout = kickstart.get_timeout(cr.ks, 10) timeout = kickstart.get_timeout(creator.ks, 10)
syslinux_conf = "" syslinux_conf = ""
syslinux_conf += "PROMPT 0\n" syslinux_conf += "PROMPT 0\n"
@ -90,7 +90,7 @@ class IsoImagePlugin(SourcePlugin):
cfg.write(syslinux_conf) cfg.write(syslinux_conf)
@classmethod @classmethod
def do_configure_grubefi(cls, part, cr, cr_workdir): def do_configure_grubefi(cls, part, creator, cr_workdir):
""" """
Create loader-specific (grub-efi) config Create loader-specific (grub-efi) config
""" """
@ -100,13 +100,13 @@ class IsoImagePlugin(SourcePlugin):
else: else:
splashline = "" splashline = ""
options = cr.ks.handler.bootloader.appendLine options = creator.ks.handler.bootloader.appendLine
grubefi_conf = "" grubefi_conf = ""
grubefi_conf += "serial --unit=0 --speed=115200 --word=8 " grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
grubefi_conf += "--parity=no --stop=1\n" grubefi_conf += "--parity=no --stop=1\n"
grubefi_conf += "default=boot\n" grubefi_conf += "default=boot\n"
timeout = kickstart.get_timeout(cr.ks, 10) timeout = kickstart.get_timeout(creator.ks, 10)
grubefi_conf += "timeout=%s\n" % timeout grubefi_conf += "timeout=%s\n" % timeout
grubefi_conf += "\n" grubefi_conf += "\n"
grubefi_conf += "search --set=root --label %s " % part.label grubefi_conf += "search --set=root --label %s " % part.label
@ -185,7 +185,7 @@ class IsoImagePlugin(SourcePlugin):
return initrd return initrd
@classmethod @classmethod
def do_stage_partition(cls, part, source_params, cr, cr_workdir, def do_stage_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -231,7 +231,7 @@ class IsoImagePlugin(SourcePlugin):
exec_cmd("bitbake mtools-native") exec_cmd("bitbake mtools-native")
@classmethod @classmethod
def do_configure_partition(cls, part, source_params, cr, cr_workdir, def do_configure_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
native_sysroot): native_sysroot):
""" """
@ -249,11 +249,11 @@ class IsoImagePlugin(SourcePlugin):
msger.debug("%s" % source_params) msger.debug("%s" % source_params)
if 'image_name' in source_params and \ if 'image_name' in source_params and \
source_params['image_name'].strip(): source_params['image_name'].strip():
cr.name = source_params['image_name'].strip() creator.name = source_params['image_name'].strip()
msger.debug("The name of the image is: %s" % cr.name) msger.debug("The name of the image is: %s" % creator.name)
@classmethod @classmethod
def do_prepare_partition(cls, part, source_params, cr, cr_workdir, def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, oe_builddir, bootimg_dir, kernel_dir,
rootfs_dir, native_sysroot): rootfs_dir, native_sysroot):
""" """
@ -353,7 +353,7 @@ class IsoImagePlugin(SourcePlugin):
exec_cmd(install_cmd) exec_cmd(install_cmd)
if not os.path.isfile("%s/EFI/BOOT/boot.cfg" % bootimg_dir): if not os.path.isfile("%s/EFI/BOOT/boot.cfg" % bootimg_dir):
cls.do_configure_grubefi(part, cr, bootimg_dir) cls.do_configure_grubefi(part, creator, bootimg_dir)
# Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
# didn't contains it # didn't contains it
@ -463,7 +463,7 @@ class IsoImagePlugin(SourcePlugin):
install_cmd = "install -d %s/isolinux" % isodir install_cmd = "install -d %s/isolinux" % isodir
exec_cmd(install_cmd) exec_cmd(install_cmd)
cls.do_configure_syslinux(cr, cr_workdir) cls.do_configure_syslinux(creator, cr_workdir)
install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
install_cmd += "%s/isolinux/ldlinux.sys" % isodir install_cmd += "%s/isolinux/ldlinux.sys" % isodir
@ -508,7 +508,7 @@ class IsoImagePlugin(SourcePlugin):
part.set_source_file(iso_img) part.set_source_file(iso_img)
@classmethod @classmethod
def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir, def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
bootimg_dir, kernel_dir, native_sysroot): bootimg_dir, kernel_dir, native_sysroot):
""" """
Called after all partitions have been prepared and assembled into a Called after all partitions have been prepared and assembled into a
@ -516,9 +516,9 @@ class IsoImagePlugin(SourcePlugin):
utility for booting via BIOS from disk storage devices. utility for booting via BIOS from disk storage devices.
""" """
full_path = cr._full_path(workdir, disk_name, "direct") full_path = creator._full_path(workdir, disk_name, "direct")
iso_img = "%s.p1" % full_path iso_img = "%s.p1" % full_path
full_path_iso = cr._full_path(workdir, disk_name, "iso") full_path_iso = creator._full_path(workdir, disk_name, "iso")
isohybrid_cmd = "isohybrid -u %s" % iso_img isohybrid_cmd = "isohybrid -u %s" % iso_img
msger.debug("running command: %s" % \ msger.debug("running command: %s" % \

View File

@ -129,14 +129,14 @@ class Image(object):
self._partitions_layed_out = True self._partitions_layed_out = True
# Go through partitions in the order they are added in .ks file # Go through partitions in the order they are added in .ks file
for n in range(len(self.partitions)): for num in range(len(self.partitions)):
p = self.partitions[n] 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" \ 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, # The --part-type can also be implemented for MBR partitions,
# in which case it would map to the 1-byte "partition type" # in which case it would map to the 1-byte "partition type"
# filed at offset 3 of the partition entry. # filed at offset 3 of the partition entry.
@ -144,79 +144,79 @@ class Image(object):
"implemented for msdos partitions") "implemented for msdos partitions")
# Get the disk where the partition is located # Get the disk where the partition is located
d = self.disks[p['disk_name']] disk = self.disks[part['disk_name']]
d['numpart'] += 1 disk['numpart'] += 1
if not p['no_table']: if not part['no_table']:
d['realpart'] += 1 disk['realpart'] += 1
d['ptable_format'] = ptable_format disk['ptable_format'] = ptable_format
if d['numpart'] == 1: if disk['numpart'] == 1:
if ptable_format == "msdos": if ptable_format == "msdos":
overhead = MBR_OVERHEAD overhead = MBR_OVERHEAD
elif ptable_format == "gpt": elif ptable_format == "gpt":
overhead = GPT_OVERHEAD overhead = GPT_OVERHEAD
# Skip one sector required for the partitioning scheme 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 # Reserve a sector for EBR for every logical partition
# before alignment is performed. # before alignment is performed.
if ptable_format == "msdos": 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 # If not first partition and we do have alignment set we need
# to align the partition. # to align the partition.
# FIXME: This leaves a empty spaces to the disk. To fill the # FIXME: This leaves a empty spaces to the disk. To fill the
# gaps we could enlargea the previous partition? # gaps we could enlargea the previous partition?
# Calc how much the alignment is off. # 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 align_sectors:
# If partition is not aligned as required, we need # If partition is not aligned as required, we need
# to move forward to the next alignment point # 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" msger.debug("Realignment for %s%s with %s sectors, original"
" offset %s, target alignment is %sK." % " offset %s, target alignment is %sK." %
(p['disk_name'], d['numpart'], align_sectors, (part['disk_name'], disk['numpart'], align_sectors,
d['offset'], p['align'])) disk['offset'], part['align']))
# increase the offset so we actually start the partition on right alignment # increase the offset so we actually start the partition on right alignment
d['offset'] += align_sectors disk['offset'] += align_sectors
p['start'] = d['offset'] part['start'] = disk['offset']
d['offset'] += p['size'] disk['offset'] += part['size']
p['type'] = 'primary' part['type'] = 'primary'
if not p['no_table']: if not part['no_table']:
p['num'] = d['realpart'] part['num'] = disk['realpart']
else: else:
p['num'] = 0 part['num'] = 0
if d['ptable_format'] == "msdos": if disk['ptable_format'] == "msdos":
if d['realpart'] > 3: if disk['realpart'] > 3:
p['type'] = 'logical' part['type'] = 'logical'
p['num'] = d['realpart'] + 1 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 " msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d "
"sectors (%d bytes)." \ "sectors (%d bytes)." \
% (p['mountpoint'], p['disk_name'], p['num'], % (part['mountpoint'], part['disk_name'], part['num'],
p['start'], p['start'] + p['size'] - 1, part['start'], part['start'] + part['size'] - 1,
p['size'], p['size'] * self.sector_size)) part['size'], part['size'] * self.sector_size))
# Once all the partitions have been layed out, we can calculate the # Once all the partitions have been layed out, we can calculate the
# minumim disk sizes. # minumim disk sizes.
for d in self.disks.values(): for disk in self.disks.values():
d['min_size'] = d['offset'] disk['min_size'] = disk['offset']
if d['ptable_format'] == "gpt": if disk['ptable_format'] == "gpt":
d['min_size'] += GPT_OVERHEAD 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): def __create_partition(self, device, parttype, fstype, start, size):
""" Create a partition on an image described by the 'device' object. """ """ Create a partition on an image described by the 'device' object. """
@ -237,21 +237,21 @@ class Image(object):
self.layout_partitions() self.layout_partitions()
for dev in self.disks.keys(): for dev in self.disks.keys():
d = self.disks[dev] disk = self.disks[dev]
msger.debug("Initializing partition table for %s" % \ msger.debug("Initializing partition table for %s" % \
(d['disk'].device)) (disk['disk'].device))
exec_native_cmd("parted -s %s mklabel %s" % \ exec_native_cmd("parted -s %s mklabel %s" % \
(d['disk'].device, d['ptable_format']), (disk['disk'].device, disk['ptable_format']),
self.native_sysroot) self.native_sysroot)
msger.debug("Creating partitions") msger.debug("Creating partitions")
for p in self.partitions: for part in self.partitions:
if p['num'] == 0: if part['num'] == 0:
continue continue
d = self.disks[p['disk_name']] disk = self.disks[part['disk_name']]
if d['ptable_format'] == "msdos" and p['num'] == 5: if disk['ptable_format'] == "msdos" and part['num'] == 5:
# Create an extended partition (note: extended # Create an extended partition (note: extended
# partition is described in MBR and contains all # partition is described in MBR and contains all
# logical partitions). The logical partitions save a # logical partitions). The logical partitions save a
@ -263,17 +263,17 @@ class Image(object):
# starts a sector before the first logical partition, # starts a sector before the first logical partition,
# add a sector at the back, so that there is enough # add a sector at the back, so that there is enough
# room for all logical partitions. # room for all logical partitions.
self.__create_partition(d['disk'].device, "extended", self.__create_partition(disk['disk'].device, "extended",
None, p['start'] - 1, None, part['start'] - 1,
d['offset'] - p['start'] + 1) disk['offset'] - part['start'] + 1)
if p['fstype'] == "swap": if part['fstype'] == "swap":
parted_fs_type = "linux-swap" parted_fs_type = "linux-swap"
elif p['fstype'] == "vfat": elif part['fstype'] == "vfat":
parted_fs_type = "fat32" parted_fs_type = "fat32"
elif p['fstype'] == "msdos": elif part['fstype'] == "msdos":
parted_fs_type = "fat16" parted_fs_type = "fat16"
elif p['fstype'] == "ontrackdm6aux3": elif part['fstype'] == "ontrackdm6aux3":
parted_fs_type = "ontrackdm6aux3" parted_fs_type = "ontrackdm6aux3"
else: else:
# Type for ext2/ext3/ext4/btrfs # 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 # Boot ROM of OMAP boards require vfat boot partition to have an
# even number of sectors. # even number of sectors.
if p['mountpoint'] == "/boot" and p['fstype'] in ["vfat", "msdos"] \ if part['mountpoint'] == "/boot" and part['fstype'] in ["vfat", "msdos"] \
and p['size'] % 2: and part['size'] % 2:
msger.debug("Substracting one sector from '%s' partition to " \ msger.debug("Substracting one sector from '%s' partition to " \
"get even number of sectors for the partition" % \ "get even number of sectors for the partition" % \
p['mountpoint']) part['mountpoint'])
p['size'] -= 1 part['size'] -= 1
self.__create_partition(d['disk'].device, p['type'], self.__create_partition(disk['disk'].device, part['type'],
parted_fs_type, p['start'], p['size']) parted_fs_type, part['start'], part['size'])
if p['part_type']: if part['part_type']:
msger.debug("partition %d: set type UID to %s" % \ 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" % \ exec_native_cmd("sgdisk --typecode=%d:%s %s" % \
(p['num'], p['part_type'], (part['num'], part['part_type'],
d['disk'].device), self.native_sysroot) disk['disk'].device), self.native_sysroot)
if p['uuid']: if part['uuid']:
msger.debug("partition %d: set UUID to %s" % \ 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" % \ 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) self.native_sysroot)
if p['boot']: if part['boot']:
flag_name = "legacy_boot" if d['ptable_format'] == 'gpt' else "boot" flag_name = "legacy_boot" if disk['ptable_format'] == 'gpt' else "boot"
msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \ 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" % \ 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) self.native_sysroot)
# Parted defaults to enabling the lba flag for fat16 partitions, # Parted defaults to enabling the lba flag for fat16 partitions,
# which causes compatibility issues with some firmware (and really # which causes compatibility issues with some firmware (and really
# isn't necessary). # isn't necessary).
if parted_fs_type == "fat16": 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'" % \ 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" % \ exec_native_cmd("parted -s %s set %d lba off" % \
(d['disk'].device, p['num']), (disk['disk'].device, part['num']),
self.native_sysroot) self.native_sysroot)
def cleanup(self): def cleanup(self):
if self.disks: if self.disks:
for dev in self.disks: for dev in self.disks:
d = self.disks[dev] disk = self.disks[dev]
try: try:
d['disk'].cleanup() disk['disk'].cleanup()
except: except:
pass pass
@ -354,8 +354,8 @@ class Image(object):
def create(self): def create(self):
for dev in self.disks.keys(): for dev in self.disks.keys():
d = self.disks[dev] disk = self.disks[dev]
d['disk'].create() disk['disk'].create()
self.__format_disks() self.__format_disks()

View File

@ -62,13 +62,13 @@ def runtool(cmdln_or_args, catch=1):
serr = subprocess.STDOUT serr = subprocess.STDOUT
try: try:
p = subprocess.Popen(cmdln_or_args, stdout=sout, process = subprocess.Popen(cmdln_or_args, stdout=sout,
stderr=serr, shell=shell) stderr=serr, shell=shell)
(sout, serr) = p.communicate() (sout, serr) = process.communicate()
# combine stdout and stderr, filter None out # combine stdout and stderr, filter None out
out = ''.join(filter(None, [sout, serr])) out = ''.join(filter(None, [sout, serr]))
except OSError, e: except OSError, err:
if e.errno == 2: if err.errno == 2:
# [Errno 2] No such file or directory # [Errno 2] No such file or directory
msger.error('Cannot run command: %s, lost dependency?' % cmd) msger.error('Cannot run command: %s, lost dependency?' % cmd)
else: else:
@ -77,12 +77,12 @@ def runtool(cmdln_or_args, catch=1):
if catch != 3: if catch != 3:
os.close(dev_null) os.close(dev_null)
return (p.returncode, out) return (process.returncode, out)
def show(cmdln_or_args): def show(cmdln_or_args):
# show all the message using msger.verbose # 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): if isinstance(cmdln_or_args, list):
cmd = ' '.join(cmdln_or_args) cmd = ' '.join(cmdln_or_args)
@ -100,7 +100,7 @@ def show(cmdln_or_args):
msg += '\n +----------------' msg += '\n +----------------'
msger.verbose(msg) msger.verbose(msg)
return rc return rcode
def outs(cmdln_or_args, catch=1): def outs(cmdln_or_args, catch=1):
# get the outputs of tools # get the outputs of tools

View File

@ -62,9 +62,9 @@ def rootfs_dir_to_args(krootfs_dir):
Get a rootfs_dir dict and serialize to string Get a rootfs_dir dict and serialize to string
""" """
rootfs_dir = '' rootfs_dir = ''
for k, v in krootfs_dir.items(): for key, val in krootfs_dir.items():
rootfs_dir += ' ' rootfs_dir += ' '
rootfs_dir += '='.join([k, v]) rootfs_dir += '='.join([key, val])
return rootfs_dir.strip() return rootfs_dir.strip()
def callback_rootfs_dir(option, opt, value, parser): def callback_rootfs_dir(option, opt, value, parser):