[elbe-devel] [PATCH v4 22/41] Nuke ASCIIDocLog from hdimg
dion at linutronix.de
dion at linutronix.de
Mon Jul 8 17:18:18 CEST 2019
From: Olivier Dion <dion at linutronix.de>
Remove ASCIIDocLog from hdimg thus changing all callers that use it
Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/efilesystem.py | 12 +-
elbepack/hdimg.py | 349 ++++++++++++++++++++----------------------------
2 files changed, 148 insertions(+), 213 deletions(-)
diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index 1f6428e0..3d2e3d6d 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -307,13 +307,11 @@ class TargetFs(ChRootFilesystem):
def part_target(self, targetdir, grub_version, grub_fw_type=None):
# create target images and copy the rfs into them
- self.images = do_hdimg(
- self.log,
- self.xml,
- targetdir,
- self,
- grub_version,
- grub_fw_type)
+ self.images = do_hdimg(self.xml,
+ targetdir,
+ self,
+ grub_version,
+ grub_fw_type)
for i in self.images:
self.image_packers[i] = default_packer
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 771c9a35..92414421 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -15,11 +15,11 @@ import parted
import _ped
from elbepack.fstab import fstabentry, mountpoint_dict
-from elbepack.asciidoclog import CommandError
from elbepack.filesystem import size_to_int
+from elbepack.shellhelper import do, CommandError, chroot
-def mkfs_mtd(outf, mtd, fslabel, target):
+def mkfs_mtd(mtd, fslabel, target):
# generated files
img_files = []
@@ -43,13 +43,15 @@ def mkfs_mtd(outf, mtd, fslabel, target):
continue
try:
- outf.do("mkfs.ubifs -r %s -o %s.ubifs -m %s -e %s -c %s %s" % (
+ cmd = "mkfs.ubifs -r %s -o %s.ubifs -m %s -e %s -c %s %s" % (
os.path.join(target, "filesystems", fslabel[label].id),
os.path.join(target, label),
ubivg.text("miniosize"),
ubivg.text("logicaleraseblocksize"),
ubivg.text("maxlogicaleraseblockcount"),
- fslabel[label].mkfsopt))
+ fslabel[label].mkfsopt
+ )
+ do(cmd)
# only append the ubifs file if creation didn't fail
img_files.append("%s.ubifs" % label)
except CommandError:
@@ -59,7 +61,7 @@ def mkfs_mtd(outf, mtd, fslabel, target):
return img_files
-def build_image_mtd(outf, mtd, target):
+def build_image_mtd(mtd, target):
# pylint: disable=too-many-branches
@@ -87,9 +89,8 @@ def build_image_mtd(outf, mtd, target):
# copy from project directory
else:
tmp = target + "/" + vol.text("binary")
- outf.do(
- "cp %s %s/%s.ubibin" %
- (tmp, target, vol.text("label")))
+ do("cp %s %s/%s.ubibin" %
+ (tmp, target, vol.text("label")))
img_files.append(vol.text("label") + ".ubibin")
fp.write(
"image=%s.ubibin\n" %
@@ -125,7 +126,7 @@ def build_image_mtd(outf, mtd, target):
subp = ""
try:
- outf.do("ubinize %s -o %s -p %s -m %s %s/%s_%s.cfg" % (
+ do("ubinize %s -o %s -p %s -m %s %s/%s_%s.cfg" % (
subp,
os.path.join(target, mtd.text("name")),
ubivg.text("physicaleraseblocksize"),
@@ -144,8 +145,7 @@ def build_image_mtd(outf, mtd, target):
class grubinstaller_base(object):
- def __init__(self, outf, fw_type=None):
- self.outf = outf
+ def __init__(self, fw_type=None):
self.root = None
self.boot = None
self.boot_efi = None
@@ -173,99 +173,72 @@ class grubinstaller202(grubinstaller_base):
imagemnt = os.path.join(target, "imagemnt")
try:
- self.outf.do('cp -a /dev/loop0 /dev/poop0')
-
- self.outf.do('losetup /dev/poop0 "%s"' % self.root.filename)
- self.outf.do('kpartx -as /dev/poop0')
- self.outf.do(
- 'mount /dev/mapper/poop0p%d %s' %
- (self.root.partnum, imagemnt))
+ do('cp -a /dev/loop0 /dev/poop0')
+ do('losetup /dev/poop0 "%s"' % self.root.filename)
+ do('kpartx -as /dev/poop0')
+ do('mount /dev/mapper/poop0p%d %s' %
+ (self.root.partnum, imagemnt))
if self.boot:
- self.outf.do(
- 'mount /dev/mapper/poop0p%d %s' %
- (self.boot.partnum, os.path.join(
- imagemnt, "boot")))
+ do('mount /dev/mapper/poop0p%d %s' %
+ (self.boot.partnum, os.path.join(imagemnt, "boot")))
if self.boot_efi:
- self.outf.do(
- 'mount /dev/mapper/poop0p%d %s' %
- (self.boot_efi.partnum, os.path.join(
- imagemnt, "boot/efi")))
-
- self.outf.do(
- "mount --bind /dev %s" %
- os.path.join(
- imagemnt,
- "dev"))
- self.outf.do(
- "mount --bind /proc %s" %
- os.path.join(
- imagemnt,
- "proc"))
- self.outf.do(
- "mount --bind /sys %s" %
- os.path.join(
- imagemnt,
- "sys"))
-
- self.outf.do('mkdir -p "%s"' % os.path.join(imagemnt, "boot/grub"))
+ do('mount /dev/mapper/poop0p%d %s' %
+ (self.boot_efi.partnum, os.path.join(imagemnt, "boot/efi")))
+
+ do("mount --bind /dev %s" %
+ os.path.join(imagemnt, "dev"))
+
+ do("mount --bind /proc %s" %
+ os.path.join(imagemnt, "proc"))
+
+ do("mount --bind /sys %s" %
+ os.path.join(imagemnt, "sys"))
+
+ do('mkdir -p "%s"' %
+ os.path.join(imagemnt, "boot/grub"))
devmap = open(os.path.join(imagemnt, "boot/grub/device.map"), "w")
devmap.write("(hd0) /dev/poop0\n")
devmap.close()
- self.outf.do("chroot %s update-initramfs -u -k all" % imagemnt)
- self.outf.do("chroot %s update-grub2" % imagemnt)
+ chroot(imagemnt, "update-initramfs -u -k all")
+ chroot(imagemnt, "update-grub2")
if self.fw_type == "efi" or self.fw_type == "hybrid":
- self.outf.do(
- "chroot %s grub-install --target=x86_64-efi --removable "
- "--no-floppy /dev/poop0" %
- (imagemnt))
+ chroot(imagemnt, "grub-install --target=x86_64-efi --removable "
+ "--no-floppy /dev/poop0")
+
if self.fw_type == "hybrid" or self.fw_type is None:
# when we are in hybrid mode, install grub also into MBR
- self.outf.do(
- "chroot %s grub-install --no-floppy /dev/poop0" %
- (imagemnt))
+ chroot(imagemnt, "grub-install --no-floppy /dev/poop0")
finally:
os.unlink(os.path.join(imagemnt, "boot/grub/device.map"))
- self.outf.do(
- "umount %s" %
- os.path.join(
- imagemnt,
- "dev"),
- allow_fail=True)
- self.outf.do(
- "umount %s" %
- os.path.join(
- imagemnt,
- "proc"),
- allow_fail=True)
- self.outf.do(
- "umount %s" %
- os.path.join(
- imagemnt,
- "sys"),
- allow_fail=True)
+
+ do("umount %s" % os.path.join(imagemnt, "dev"),
+ allow_fail=True)
+
+ do("umount %s" % os.path.join(imagemnt, "proc"),
+ allow_fail=True)
+
+ do("umount %s" % os.path.join(imagemnt, "sys"),
+ allow_fail=True)
if self.boot_efi:
- self.outf.do(
- 'umount /dev/mapper/poop0p%d' %
- self.boot_efi.partnum, allow_fail=True)
+ do('umount /dev/mapper/poop0p%d' %
+ self.boot_efi.partnum, allow_fail=True)
if self.boot:
- self.outf.do(
- 'umount /dev/mapper/poop0p%d' %
- self.boot.partnum, allow_fail=True)
+ do('umount /dev/mapper/poop0p%d' %
+ self.boot.partnum, allow_fail=True)
- self.outf.do(
- 'umount /dev/mapper/poop0p%d' %
- self.root.partnum, allow_fail=True)
+ do('umount /dev/mapper/poop0p%d' % self.root.partnum,
+ allow_fail=True)
- self.outf.do('kpartx -d /dev/poop0', allow_fail=True)
- self.outf.do("losetup -d /dev/poop0", allow_fail=True)
+ do('kpartx -d /dev/poop0', allow_fail=True)
+ do("losetup -d /dev/poop0", allow_fail=True)
class grubinstaller199(grubinstaller_base):
@@ -276,17 +249,17 @@ class grubinstaller199(grubinstaller_base):
imagemnt = os.path.join(target, "imagemnt")
try:
- self.outf.do('cp -a /dev/loop0 /dev/poop0')
- self.outf.do('cp -a /dev/loop1 /dev/poop1')
- self.outf.do('cp -a /dev/loop2 /dev/poop2')
+ do('cp -a /dev/loop0 /dev/poop0')
+ do('cp -a /dev/loop1 /dev/poop1')
+ do('cp -a /dev/loop2 /dev/poop2')
- self.outf.do('losetup /dev/poop0 "%s"' % self.root.filename)
- self.root.losetup(self.outf, "poop1")
- self.outf.do('mount /dev/poop1 %s' % imagemnt)
+ do('losetup /dev/poop0 "%s"' % self.root.filename)
+ self.root.losetup("poop1")
+ do('mount /dev/poop1 %s' % imagemnt)
if self.boot:
- self.boot.losetup(self.outf, "poop2")
- self.outf.do('mount /dev/poop2 %s' %
+ self.boot.losetup("poop2")
+ do('mount /dev/poop2 %s' %
(os.path.join(imagemnt, "boot")))
devmap = open(os.path.join(imagemnt, "boot/grub/device.map"), "w")
@@ -297,59 +270,33 @@ class grubinstaller199(grubinstaller_base):
devmap.close()
- self.outf.do(
- "mount --bind /dev %s" %
- os.path.join(
- imagemnt,
- "dev"))
- self.outf.do(
- "mount --bind /proc %s" %
- os.path.join(
- imagemnt,
- "proc"))
- self.outf.do(
- "mount --bind /sys %s" %
- os.path.join(
- imagemnt,
- "sys"))
-
- self.outf.do("chroot %s update-initramfs -u -k all" % imagemnt)
- self.outf.do("chroot %s update-grub2" % imagemnt)
-
- self.outf.do(
- "chroot %s grub-install --no-floppy /dev/loop0" %
- imagemnt)
+ do("mount --bind /dev %s" % os.path.join(imagemnt, "dev"))
+ do("mount --bind /proc %s" % os.path.join(imagemnt, "proc"))
+ do("mount --bind /sys %s" % os.path.join(imagemnt, "sys"))
+ chroot(imagemnt, "update-initramfs -u -k all")
+ chroot(imagemnt, "update-grub2")
+ chroot(imagemnt, "grub-install --no-floppy /dev/loop0")
finally:
os.unlink(os.path.join(imagemnt, "boot/grub/device.map"))
- self.outf.do(
- "umount -l %s" %
- os.path.join(
- imagemnt,
- "dev"),
- allow_fail=True)
- self.outf.do(
- "umount -l %s" %
- os.path.join(
- imagemnt,
- "proc"),
- allow_fail=True)
- self.outf.do(
- "umount -l %s" %
- os.path.join(
- imagemnt,
- "sys"),
- allow_fail=True)
-
- self.outf.do("losetup -d /dev/poop0", allow_fail=True)
+ do("umount -l %s" % os.path.join(imagemnt, "dev"),
+ allow_fail=True)
+
+ do("umount -l %s" % os.path.join(imagemnt, "proc"),
+ allow_fail=True)
+
+ do("umount -l %s" % os.path.join(imagemnt, "sys"),
+ allow_fail=True)
+
+ do("losetup -d /dev/poop0", allow_fail=True)
if self.boot:
- self.outf.do('umount /dev/poop2', allow_fail=True)
- self.outf.do('losetup -d /dev/poop2', allow_fail=True)
+ do('umount /dev/poop2', allow_fail=True)
+ do('losetup -d /dev/poop2', allow_fail=True)
- self.outf.do('umount /dev/poop1', allow_fail=True)
- self.outf.do('losetup -d /dev/poop1', allow_fail=True)
+ do('umount /dev/poop1', allow_fail=True)
+ do('losetup -d /dev/poop1', allow_fail=True)
class simple_fstype(object):
@@ -399,7 +346,7 @@ def create_partition(
return ppart
-def create_label(outf, disk, part, ppart, fslabel, target, grub):
+def create_label(disk, part, ppart, fslabel, target, grub):
# pylint: disable=too-many-arguments
@@ -413,33 +360,30 @@ def create_label(outf, disk, part, ppart, fslabel, target, grub):
elif entry.mountpoint == "/boot/efi":
grub.set_boot_efi_entry(entry)
- entry.losetup(outf, "loop0")
- outf.do(
- 'mkfs.%s %s %s /dev/loop0' %
- (entry.fstype,
- entry.mkfsopt,
- entry.get_label_opt()))
-
- outf.do('mount /dev/loop0 %s' % os.path.join(target, "imagemnt"))
- outf.do(
- 'cp -a "%s/." "%s/"' %
- (os.path.join(
- target, "filesystems", entry.id), os.path.join(
- target, "imagemnt")), allow_fail=True)
- outf.do('umount /dev/loop0')
- outf.do('losetup -d /dev/loop0')
+ entry.losetup("loop0")
+
+ do('mkfs.%s %s %s /dev/loop0' %
+ (entry.fstype,
+ entry.mkfsopt,
+ entry.get_label_opt()))
+
+ do('mount /dev/loop0 %s' % os.path.join(target, "imagemnt"))
+ do('cp -a "%s/." "%s/"' %
+ (os.path.join(target, "filesystems", entry.id),
+ os.path.join(target, "imagemnt")),
+ allow_fail=True)
+ do('umount /dev/loop0')
+ do('losetup -d /dev/loop0')
return ppart
-def create_logical_partitions(
- outf,
- disk,
- extended,
- epart,
- fslabel,
- target,
- grub):
+def create_logical_partitions(disk,
+ extended,
+ epart,
+ fslabel,
+ target,
+ grub):
# pylint: disable=too-many-arguments
@@ -459,12 +403,12 @@ def create_logical_partitions(
size_in_sectors,
current_sector)
if logical.has("label") and logical.text("label") in fslabel:
- create_label(outf, disk, logical, lpart, fslabel, target, grub)
+ create_label(disk, logical, lpart, fslabel, target, grub)
current_sector += lpart.getLength()
-def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
+def do_image_hd(hd, fslabel, target, grub_version, grub_fw_type=None):
# pylint: disable=too-many-arguments
# pylint: disable=too-many-locals
@@ -475,7 +419,7 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
size_in_sectors = s / sector_size
imagename = os.path.join(target, hd.text("name"))
- outf.do('rm -f "%s"' % imagename, allow_fail=True)
+ do('rm -f "%s"' % imagename, allow_fail=True)
f = open(imagename, "wb")
f.truncate(size_in_sectors * sector_size)
f.close()
@@ -487,15 +431,15 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
disk = parted.freshDisk(imag, "msdos")
if grub_version == 199:
- grub = grubinstaller199(outf)
+ grub = grubinstaller199()
elif grub_version == 202 and grub_fw_type == "efi":
- grub = grubinstaller202(outf, "efi")
+ grub = grubinstaller202("efi")
elif grub_version == 202 and grub_fw_type == "hybrid":
- grub = grubinstaller202(outf, "hybrid")
+ grub = grubinstaller202("hybrid")
elif grub_version == 202:
- grub = grubinstaller202(outf)
+ grub = grubinstaller202()
else:
- grub = grubinstaller_base(outf)
+ grub = grubinstaller_base()
current_sector = 2048
for part in hd:
@@ -509,7 +453,7 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
size_in_sectors,
current_sector)
if part.text("label") in fslabel:
- create_label(outf, disk, part, ppart, fslabel, target, grub)
+ create_label(disk, part, ppart, fslabel, target, grub)
elif part.tag == "extended":
ppart = create_partition(
disk,
@@ -518,8 +462,8 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
fslabel,
size_in_sectors,
current_sector)
- create_logical_partitions(
- outf, disk, part, ppart, fslabel, target, grub)
+ create_logical_partitions(disk, part, ppart,
+ fslabel, target, grub)
else:
continue
@@ -533,7 +477,7 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type=None):
return hd.text("name")
-def add_binary_blob(outf, hd, target):
+def add_binary_blob(hd, target):
imagename = os.path.join(target, hd.text("name"))
@@ -559,14 +503,11 @@ def add_binary_blob(outf, hd, target):
# use file from /var/cache/elbe/<uuid> project dir
bf = os.path.join(target, binary.et.text)
- outf.do('dd if="%s" of="%s" seek="%s" bs="%s" conv=notrunc' % (
- bf,
- imagename,
- offset,
- bs))
+ do('dd if="%s" of="%s" seek="%s" bs="%s" conv=notrunc' %
+ (bf, imagename, offset, bs))
-def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type=None):
+def do_hdimg(xml, target, rfs, grub_version, grub_fw_type=None):
# pylint: disable=too-many-arguments
# pylint: disable=too-many-locals
@@ -602,67 +543,63 @@ def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type=None):
# create directories, where we want our
# filesystems later
fspath = os.path.join(target, "filesystems")
- outf.do('mkdir -p %s' % fspath)
+ do('mkdir -p %s' % fspath)
imagemnt = os.path.join(target, "imagemnt")
- outf.do('mkdir -p %s' % imagemnt)
+ do('mkdir -p %s' % imagemnt)
# now move all mountpoints into own directories
# begin from deepest mountpoints
for l in reversed(fslist):
- outf.do('mkdir -p "%s"' % os.path.join(fspath, l.id))
- outf.do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
+ do('mkdir -p "%s"' % os.path.join(fspath, l.id))
+ do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
if rfs.listdir(l.mountpoint):
- outf.do('mv "%s"/* "%s"' % (rfs.fname(l.mountpoint), os.path.join(
- fspath, l.id)), allow_fail=True)
+ do('mv "%s"/* "%s"' %
+ (rfs.fname(l.mountpoint),
+ os.path.join(fspath, l.id)),
+ allow_fail=True)
try:
# Now iterate over all images and create filesystems and partitions
for i in xml.tgt.node("images"):
if i.tag == "msdoshd":
- img = do_image_hd(
- outf,
- i,
- fslabel,
- target,
- grub_version,
- grub_fw_type)
+ img = do_image_hd(i,
+ fslabel,
+ target,
+ grub_version,
+ grub_fw_type)
img_files.append(img)
if i.tag == "gpthd":
- img = do_image_hd(
- outf,
- i,
- fslabel,
- target,
- grub_version,
- grub_fw_type)
+ img = do_image_hd(i,
+ fslabel,
+ target,
+ grub_version,
+ grub_fw_type)
img_files.append(img)
if i.tag == "mtd":
- imgs = mkfs_mtd(outf, i, fslabel, target)
+ imgs = mkfs_mtd(i, fslabel, target)
img_files.extend(imgs)
finally:
# Put back the filesystems into /target
# most shallow fs first...
for i in fslist:
if len(os.listdir(os.path.join(fspath, i.id))) > 0:
- outf.do(
- 'mv "%s"/* "%s"' %
- (os.path.join(
- fspath, i.id), rfs.fname(
- i.mountpoint)), allow_fail=True)
+ do('mv "%s"/* "%s"' %
+ (os.path.join(fspath, i.id), rfs.fname(i.mountpoint)),
+ allow_fail=True)
# Files are now moved back. ubinize needs files in place, so we run it now.
for i in xml.tgt.node("images"):
if i.tag == "mtd":
- imgs = build_image_mtd(outf, i, target)
+ imgs = build_image_mtd(i, target)
img_files.extend(imgs)
# dd binary blobs onto images
for i in xml.tgt.node("images"):
if (i.tag == "msdoshd") or (i.tag == "gpthd"):
- add_binary_blob(outf, i, target)
+ add_binary_blob(i, target)
# use set() to remove duplicates, but
# return a list
--
2.11.0
More information about the elbe-devel
mailing list