diff --git a/pmb/install/_install.py b/pmb/install/_install.py index 53e33d98..f8e8f600 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -64,7 +64,9 @@ def get_nonfree_packages(args, device): ["device-nokia-n900-nonfree-firmware"] """ # Read subpackages - apkbuild = pmb.parse.apkbuild(args, pmb.helpers.devices.find_path(args, device, 'APKBUILD')) + apkbuild = pmb.parse.apkbuild(args, + pmb.helpers.devices.find_path(args, device, + 'APKBUILD')) subpackages = apkbuild["subpackages"] # Check for firmware and userland @@ -138,8 +140,8 @@ def copy_files_from_chroot(args, suffix): rsync_flags = "-a" if args.verbose: rsync_flags += "vP" - pmb.chroot.root(args, ["rsync", rsync_flags, "--delete"] + folders + ["/mnt/install/"], - working_dir=mountpoint) + pmb.chroot.root(args, ["rsync", rsync_flags, "--delete"] + folders + + ["/mnt/install/"], working_dir=mountpoint) pmb.chroot.root(args, ["rm", "-rf", "/mnt/install/home"]) else: pmb.chroot.root(args, ["cp", "-a"] + folders + ["/mnt/install/"], @@ -204,8 +206,8 @@ def set_user(args): def setup_login(args, suffix): """ - Loop until the password for user has been set successfully, and disable root - login. + Loop until the password for user has been set successfully, and disable + root login. :param suffix: of the chroot, where passwd will be execute (either the f"rootfs_{args.device}", or f"installer_{args.device}") @@ -239,8 +241,9 @@ def copy_ssh_keys(args): keys += infile.readlines() if not len(keys): - logging.info("NOTE: Public SSH keys not found. Since no SSH keys " + - "were copied, you will need to use SSH password authentication!") + logging.info("NOTE: Public SSH keys not found. Since no SSH keys " + "were copied, you will need to use SSH password " + "authentication!") return authorized_keys = args.work + "/chroot_native/tmp/authorized_keys" @@ -249,10 +252,11 @@ def copy_ssh_keys(args): outfile.write("%s" % key) outfile.close() - target = args.work + "/chroot_native/mnt/install/home/" + args.user + "/.ssh" + target = f"{args.work}/chroot_native/mnt/install/home/{args.user}/.ssh" pmb.helpers.run.root(args, ["mkdir", target]) pmb.helpers.run.root(args, ["chmod", "700", target]) - pmb.helpers.run.root(args, ["cp", authorized_keys, target + "/authorized_keys"]) + pmb.helpers.run.root(args, ["cp", authorized_keys, target + + "/authorized_keys"]) pmb.helpers.run.root(args, ["rm", authorized_keys]) pmb.helpers.run.root(args, ["chown", "-R", "10000:10000", target]) @@ -294,8 +298,8 @@ def setup_keymap(args): config = config.splitlines()[-1] old_text = "Option *\\\"XkbLayout\\\" *\\\".*\\\"" new_text = "Option \\\"XkbLayout\\\" \\\"" + layout + "\\\"" - pmb.chroot.root(args, ["sed", "-i", "s/" + old_text + "/" + new_text + "/", config], - suffix) + pmb.chroot.root(args, ["sed", "-i", "s/" + old_text + "/" + + new_text + "/", config], suffix) else: logging.info("NOTE: No valid keymap specified for device") @@ -440,12 +444,12 @@ def sanity_check_sdcard(args): device = args.sdcard device_name = os.path.basename(device) if not os.path.exists(device): - raise RuntimeError("{} doesn't exist, is the sdcard plugged?".format(device)) + raise RuntimeError(f"{device} doesn't exist, is the sdcard plugged?") if os.path.isdir('/sys/class/block/{}'.format(device_name)): with open('/sys/class/block/{}/ro'.format(device_name), 'r') as handle: ro = handle.read() if ro == '1\n': - raise RuntimeError("{} is read-only, is the sdcard locked?".format(device)) + raise RuntimeError(f"{device} is read-only, is the sdcard locked?") def sanity_check_sdcard_size(args): @@ -465,10 +469,12 @@ def sanity_check_sdcard_size(args): # Warn if the size is larger than 100GiB if size > (100 * 2 * 1024 * 1024): - if not pmb.helpers.cli.confirm(args, f"WARNING: The target disk ({devpath}) is" - " larger than a usual SD card (>100GiB)." - " Are you sure you want to overwrite" - f" this {human} disk?", no_assumptions=True): + if not pmb.helpers.cli.confirm(args, + f"WARNING: The target disk ({devpath}) " + "is larger than a usual SD card " + "(>100GiB). Are you sure you want to " + f"overwrite this {human} disk?", + no_assumptions=True): raise RuntimeError("Aborted.") @@ -722,7 +728,8 @@ def create_device_rootfs(args, step, steps): get_nonfree_packages(args, args.device) + pmb.install.ui.get_recommends(args)) if not args.install_base: - install_packages = [p for p in install_packages if p != "postmarketos-base"] + install_packages = [p for p in install_packages + if p != "postmarketos-base"] if args.ui.lower() != "none": install_packages += ["postmarketos-ui-" + args.ui] if args.ui_extras: diff --git a/pmb/install/blockdevice.py b/pmb/install/blockdevice.py index d6cc7e60..0611bab3 100644 --- a/pmb/install/blockdevice.py +++ b/pmb/install/blockdevice.py @@ -11,9 +11,9 @@ import pmb.config def previous_install(args, path): """ - Search the sdcard for possible existence of a previous installation of pmOS. - We temporarily mount the possible pmOS_boot partition as /dev/sdcardp1 inside - the native chroot to check the label from there. + Search the sdcard for possible existence of a previous installation of + pmOS. We temporarily mount the possible pmOS_boot partition as + /dev/sdcardp1 inside the native chroot to check the label from there. :param path: path to sdcard device (e.g. /dev/mmcblk0) """ label = "" @@ -22,10 +22,12 @@ def previous_install(args, path): continue blockdevice_inside = "/dev/sdcardp1" pmb.helpers.mount.bind_file(args, blockdevice_outside, - args.work + "/chroot_native" + blockdevice_inside) + args.work + '/chroot_native' + + blockdevice_inside) label = pmb.chroot.root(args, ["blkid", "-s", "LABEL", "-o", "value", blockdevice_inside], output_return=True) - pmb.helpers.run.root(args, ["umount", args.work + "/chroot_native" + blockdevice_inside]) + pmb.helpers.run.root(args, ["umount", args.work + "/chroot_native" + + blockdevice_inside]) return "pmOS_boot" in label @@ -88,7 +90,8 @@ def create_and_mount_image(args, size_boot, size_root, size_reserve, disk_data = os.statvfs(args.work) free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2)) if size_mb > free: - raise RuntimeError("Not enough free space to create rootfs image! (free: " + str(free) + "M, required: " + str(size_mb) + "M)") + raise RuntimeError("Not enough free space to create rootfs image! " + f"(free: {free}M, required: {size_mb}M)") # Create empty image files pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"]) @@ -100,7 +103,8 @@ def create_and_mount_image(args, size_boot, size_root, size_reserve, images = {img_path_boot: size_mb_boot, img_path_root: size_mb_root} for img_path, size_mb in images.items(): - logging.info("(native) create " + os.path.basename(img_path) + " (" + size_mb + ")") + logging.info(f"(native) create {os.path.basename(img_path)} " + f"({size_mb})") pmb.chroot.root(args, ["truncate", "-s", size_mb, img_path]) # Mount to /dev/install diff --git a/pmb/install/losetup.py b/pmb/install/losetup.py index 9edca173..728477c0 100644 --- a/pmb/install/losetup.py +++ b/pmb/install/losetup.py @@ -14,10 +14,11 @@ import pmb.chroot def init(args): if not os.path.isdir("/sys/module/loop"): pmb.helpers.run.root(args, ["modprobe", "loop"]) - loopdevices = [loopdev for loopdev in glob.glob("/dev/loop*") if not os.path.isdir(loopdev)] - for loopdev in loopdevices: - pmb.helpers.mount.bind_file(args, loopdev, - args.work + "/chroot_native/" + loopdev) + for loopdevice in glob.glob("/dev/loop*"): + if os.path.isdir(loopdevice): + continue + pmb.helpers.mount.bind_file(args, loopdevice, + args.work + "/chroot_native/" + loopdevice) def mount(args, img_path): diff --git a/pmb/install/partition.py b/pmb/install/partition.py index 2498e6cf..5a5219b4 100644 --- a/pmb/install/partition.py +++ b/pmb/install/partition.py @@ -27,8 +27,8 @@ def partitions_mount(args, root_id, sdcard): partition_prefix = symbol if partition_prefix is not None: break - logging.debug("NOTE: (" + str(i + 1) + "/" + str(tries) + ") failed to find" - " the install partition. Retrying...") + logging.debug(f"NOTE: ({i + 1}/{tries}) failed to find the install " + "partition. Retrying...") time.sleep(0.1) if partition_prefix is None: diff --git a/test/static_code_analysis.sh b/test/static_code_analysis.sh index 81cbedde..f0198ca9 100755 --- a/test/static_code_analysis.sh +++ b/test/static_code_analysis.sh @@ -88,7 +88,11 @@ py_files=" pmb/helpers/status.py pmb/helpers/ui.py pmb/install/__init__.py + pmb/install/_install.py + pmb/install/blockdevice.py pmb/install/format.py + pmb/install/losetup.py + pmb/install/partition.py pmb/install/recovery.py pmb/install/ui.py pmb/parse/__init__.py