diff --git a/kernel-update.py b/kernel-update.py index 6a6175d..9e0ceb6 100755 --- a/kernel-update.py +++ b/kernel-update.py @@ -37,11 +37,11 @@ def rollback_impl(boot_dir: Path, files: Dict[str, Path]) -> None: shutil.copy2(src, dst) -def update_config(old_path: Path, new_path: Path, make_cmd: List[str]) -> None: - if old_path == new_path: +def update_config(old_dir: Path, new_dir: Path, make_cmd: List[str]) -> None: + if old_dir == new_dir: return - old_config = old_path/'.config' - new_config = new_path/'.config' + old_config = old_dir/'.config' + new_config = new_dir/'.config' while new_config.is_file(): response = input('New config present. Overwrite? [y/N]').strip().lower() if response == 'y': @@ -53,12 +53,12 @@ def update_config(old_path: Path, new_path: Path, make_cmd: List[str]) -> None: print(f'Copying config from {old_config} to {new_config}') shutil.copy2(old_config, new_config) - print(f'Setting symlink to {new_path}') - subprocess.run(['eselect', 'kernel', 'set', new_path.name]) + print(f'Setting symlink to {new_dir}') + subprocess.run(['eselect', 'kernel', 'set', new_dir.name]) print(f'Migrating config options') - migrate = make_cmd + ['-C', new_path.as_posix(), 'oldconfig'] + migrate = make_cmd + ['-C', new_dir.as_posix(), 'oldconfig'] subprocess.run(migrate) - menuconfig = make_cmd + ['-C', new_path.as_posix(), 'menuconfig'] + menuconfig = make_cmd + ['-C', new_dir.as_posix(), 'menuconfig'] while True: subprocess.run(menuconfig) response = input('Stop editing? [Y/n]').strip().lower() @@ -70,8 +70,8 @@ def update_config(old_path: Path, new_path: Path, make_cmd: List[str]) -> None: print("unrecognized option {}", response) -def compile_kernel(new_path: Path, make_cmd: List[str]) -> None: - cc = make_cmd + ['-C', new_path.as_posix()] +def compile_kernel(new_dir: Path, make_cmd: List[str]) -> None: + cc = make_cmd + ['-C', new_dir.as_posix()] subprocess.run(cc) @@ -125,9 +125,9 @@ def rollback_kernel(boot_dir: Path, boot_files: Dict[str, Path], _args: Any) -> rollback_impl(boot_dir, boot_files) def update_kernel(boot_dir: Path, boot_files: Dict[str, Path], args: Any) -> None: - old_path = linux_folder(SRC_DIR, args.old_version) - new_path = linux_folder(SRC_DIR, args.new_version) - new_version = new_path.name # rename to new_folder + old_dir = linux_folder(SRC_DIR, args.old_version) + new_dir = linux_folder(SRC_DIR, args.new_version) + new_version = new_dir.name make_cmd = ['make', f'-j{len(os.sched_getaffinity(0))}'] clang_env = ['CC=clang', 'LD=ld.lld', 'LLVM=1', 'LLVM_IAS=1'] @@ -136,17 +136,17 @@ def update_kernel(boot_dir: Path, boot_files: Dict[str, Path], args: Any) -> Non none_selected = not (args.backup or args.config or args.compile or args.install or args.rollback) if none_selected: backup_kernel(BOOT_DIR, BOOT_FILES) - update_config(old_path, new_path, make_cmd) - compile_kernel(new_path, make_cmd) - install_kernel(new_path, BOOT_DIR, BOOT_FILES, make_cmd) + update_config(old_dir, new_dir, make_cmd) + compile_kernel(new_dir, make_cmd) + install_kernel(new_dir, BOOT_DIR, BOOT_FILES, make_cmd) if args.backup: backup_kernel(BOOT_DIR, BOOT_FILES) if args.config: - update_config(old_path, new_path, make_cmd) + update_config(old_dir, new_dir, make_cmd) if args.compile: - compile_kernel(new_path, make_cmd) + compile_kernel(new_dir, make_cmd) if args.install: - install_kernel(new_path, BOOT_DIR, BOOT_FILES, make_cmd) + install_kernel(new_dir, BOOT_DIR, BOOT_FILES, make_cmd) def main() -> None: parser = argparse.ArgumentParser(description='Convenience for manual kernel updates')