fix warnings generated by pylint
This commit is contained in:
parent
082bb267df
commit
f04cb3836f
6 changed files with 34 additions and 32 deletions
|
|
@ -4,7 +4,6 @@ import contextlib
|
|||
import json
|
||||
import math
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
|
@ -32,11 +31,12 @@ def mount_api(dest):
|
|||
mount("/proc", f"{dest}/proc", "-o", "rbind"), \
|
||||
mount("/sys", f"{dest}/sys", "-o", "rbind"), \
|
||||
mount("none", f"{dest}/run", "-t", "tmpfs"):
|
||||
yield
|
||||
yield
|
||||
|
||||
@contextlib.contextmanager
|
||||
def loop_device(image, size, offset=0):
|
||||
r = subprocess.run(["losetup", "--partscan", "--show", "--find", "--sizelimit", str(size), "--offset", str(offset), image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
r = subprocess.run(["losetup", "--partscan", "--show", "--find", "--sizelimit", str(size), "--offset", str(offset),
|
||||
image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
|
||||
loop = r.stdout.strip()
|
||||
try:
|
||||
yield loop
|
||||
|
|
@ -45,7 +45,7 @@ def loop_device(image, size, offset=0):
|
|||
|
||||
def main(tree, output_dir, options):
|
||||
filename = options["filename"]
|
||||
partition_table_id = options["partition_table_id"]
|
||||
# partition_table_id = options["partition_table_id"]
|
||||
root_fs_uuid = options["root_fs_uuid"]
|
||||
|
||||
# Create a working directory on a tmpfs, maybe we should implicitly
|
||||
|
|
@ -69,18 +69,20 @@ def main(tree, output_dir, options):
|
|||
|
||||
# Populate the first partition of the image with an ext4 fs and fill it with the contents of the
|
||||
# tree we are operating on.
|
||||
subprocess.run(["mkfs.ext4", "-d", tree, "-U", root_fs_uuid, "-E", f"offset={partition_offset}", image, f"{int(partition_size / 1024)}k"], input="y", encoding='utf-8', check=True)
|
||||
subprocess.run(["mkfs.ext4", "-d", tree, "-U", root_fs_uuid, "-E", f"offset={partition_offset}", image,
|
||||
f"{int(partition_size / 1024)}k"], input="y", encoding='utf-8', check=True)
|
||||
|
||||
# Mount the created image as a loopback device
|
||||
with loop_device(image, size) as loop, \
|
||||
mount(f"{loop}p1", mountpoint):
|
||||
mount(f"{loop}p1", mountpoint):
|
||||
# Install grub2 into the boot sector of the image, and copy the grub2 imagise into /boot/grub2
|
||||
with mount_api(mountpoint):
|
||||
subprocess.run(["chroot", mountpoint, "grub2-install", "--no-floppy", "--target", "i386-pc", loop], check=True)
|
||||
subprocess.run(["chroot", mountpoint, "grub2-install", "--no-floppy", "--target", "i386-pc", loop],
|
||||
check=True)
|
||||
|
||||
subprocess.run(["qemu-img", "convert", "-O" "qcow2", "-c", image, f"{output_dir}/{filename}"], check=True)
|
||||
subprocess.run(["qemu-img", "convert", "-O", "qcow2", "-c", image, f"{output_dir}/{filename}"], check=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["output_dir"], args["options"])
|
||||
sys.exit(r)
|
||||
ret = main(args["tree"], args["output_dir"], args["options"])
|
||||
sys.exit(ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue