11#!/usr/bin/env python3
22# pylint: disable=invalid-name
33
4- from argparse import ArgumentParser
5- from collections .abc import Sequence
64import contextlib
75import os
8- from pathlib import Path
96import platform
107import re
118import shlex
129import shutil
1310import subprocess
1411import sys
12+ from argparse import ArgumentParser
13+ from collections .abc import Sequence
14+ from pathlib import Path
1515from typing import Any , Union
1616
1717import utils
1818
19-
2019SUPPORTED_ARCHES = [
2120 'arm' ,
2221 'arm32_v5' ,
@@ -108,9 +107,7 @@ def _get_default_smp_value(self) -> int:
108107 # * <kernel_dir>/../../../.config (if the image is in arch/*/boot/)
109108 # * <kernel_dir>/config (if the image is in a TuxMake folder)
110109 possible_locations = ['.config' , '../../../.config' , 'config' ]
111- configuration = utils .find_first_file (
112- self .kernel_dir , possible_locations , required = False
113- )
110+ configuration = utils .find_first_file (self .kernel_dir , possible_locations , required = False )
114111
115112 config_nr_cpus = 8 # sensible default based on treewide defaults,
116113 if configuration != utils .UNINIT_PATH :
@@ -129,21 +126,19 @@ def _get_kernel_ver_tuple(self, decomp_prog: str) -> tuple[int, ...]:
129126 raise RuntimeError ('No kernel set?' )
130127
131128 utils .check_cmd (decomp_prog )
132- if decomp_prog in ( 'gzip' ,) :
129+ if decomp_prog == 'gzip' :
133130 decomp_cmd = [decomp_prog , '-c' , '-d' , self .kernel ]
134131 else :
135132 raise RuntimeError (f"Unsupported decompression program ('{ decomp_prog } ')?" )
136133 decomp = subprocess .run (decomp_cmd , capture_output = True , check = True )
137134
138135 utils .check_cmd ('strings' )
139- strings = subprocess .run (
140- 'strings' , capture_output = True , check = True , input = decomp .stdout
141- )
136+ strings = subprocess .run ('strings' , capture_output = True , check = True , input = decomp .stdout )
142137 strings_stdout = strings .stdout .decode (encoding = 'utf-8' , errors = 'ignore' )
143138
144139 if not (
145140 match := re .search (
146- r'^Linux version (\d+\.\d+\.\d+)' , strings_stdout , flags = re .M
141+ r'^Linux version (\d+\.\d+\.\d+)' , strings_stdout , flags = re .MULTILINE
147142 )
148143 ):
149144 raise RuntimeError (f"Could not find Linux version in { self .kernel } ?" )
@@ -505,7 +500,9 @@ def __init__(self) -> None:
505500 bios = Path (utils .BOOT_UTILS , 'images' , self ._initrd_arch , 'QEMU_EFI.fd' )
506501 if not bios .exists ():
507502 bios .parent .mkdir (exist_ok = True , parents = True )
508- firmware_url = f"https://github.com/loongson/Firmware/raw/main/LoongArchVirtMachine/{ bios .name } "
503+ firmware_url = (
504+ f"https://github.com/loongson/Firmware/raw/main/LoongArchVirtMachine/{ bios .name } "
505+ )
509506 utils .green (f"Downloading LoongArch firmware from { firmware_url } ..." )
510507 curl_cmd = ['curl' , '-LSs' , '-o' , bios , firmware_url ]
511508 subprocess .run (curl_cmd , check = True )
@@ -694,9 +691,7 @@ def run(self) -> None:
694691 Path ('OVMF/OVMF_VARS.fd' ), # Debian and Ubuntu
695692 ]
696693 ovmf_vars = utils .find_first_file (usr_share , ovmf_vars_locations )
697- self ._efi_vars = Path (
698- utils .BOOT_UTILS , 'images' , self ._initrd_arch , ovmf_vars .name
699- )
694+ self ._efi_vars = Path (utils .BOOT_UTILS , 'images' , self ._initrd_arch , ovmf_vars .name )
700695 # This file is in /usr/share, so it must be copied in order to be
701696 # modified.
702697 shutil .copyfile (ovmf_vars , self ._efi_vars )
@@ -720,12 +715,8 @@ def guess_arch(kernel_arg: Path) -> str:
720715 #
721716 # Note: 'required=False' just to provide our own exception.
722717 vmlinux_locations = ['vmlinux' , '../../../vmlinux' ]
723- if not (
724- vmlinux := utils .find_first_file (kernel_dir , vmlinux_locations , required = False )
725- ):
726- raise RuntimeError (
727- 'Architecture was not provided and vmlinux could not be found!'
728- )
718+ if not (vmlinux := utils .find_first_file (kernel_dir , vmlinux_locations , required = False )):
719+ raise RuntimeError ('Architecture was not provided and vmlinux could not be found!' )
729720
730721 if not (file := shutil .which ('file' )):
731722 raise RuntimeError ("Architecture was not provided and 'file' is not installed!" )
@@ -783,9 +774,7 @@ def parse_arguments():
783774 help = "The architecture to boot. If omitted, value will be guessed based on 'vmlinux' if available. Possible values are: %(choices)s" ,
784775 metavar = 'ARCH' ,
785776 )
786- parser .add_argument (
787- '--efi' , action = 'store_true' , help = 'Boot kernel via UEFI (x86_64 only)'
788- )
777+ parser .add_argument ('--efi' , action = 'store_true' , help = 'Boot kernel via UEFI (x86_64 only)' )
789778 parser .add_argument (
790779 '-g' ,
791780 '--gdb' ,
@@ -855,9 +844,7 @@ def parse_arguments():
855844 args = parse_arguments ()
856845
857846 if not (kernel_location := Path (args .kernel_location ).resolve ()).exists ():
858- raise FileNotFoundError (
859- f"Supplied kernel location ('{ kernel_location } ') does not exist!"
860- )
847+ raise FileNotFoundError (f"Supplied kernel location ('{ kernel_location } ') does not exist!" )
861848
862849 if not (arch := args .architecture ):
863850 arch = guess_arch (kernel_location )
@@ -900,9 +887,7 @@ def parse_arguments():
900887 if args .efi :
901888 runner .efi = runner .supports_efi
902889 if not runner .efi :
903- utils .yellow (
904- f"EFI boot requested on unsupported architecture ('{ arch } '), ignoring..."
905- )
890+ utils .yellow (f"EFI boot requested on unsupported architecture ('{ arch } '), ignoring..." )
906891
907892 if args .gdb :
908893 runner .gdb = True
@@ -921,13 +906,9 @@ def parse_arguments():
921906
922907 if args .modules :
923908 if not (modules := Path (args .modules ).resolve ()).exists ():
924- raise FileNotFoundError (
925- f"Supplied modules .cpio ('{ modules } ') does not exist?"
926- )
909+ raise FileNotFoundError (f"Supplied modules .cpio ('{ modules } ') does not exist?" )
927910 if not args .memory :
928- utils .yellow (
929- 'Memory not specified, the default may be too small for modules...'
930- )
911+ utils .yellow ('Memory not specified, the default may be too small for modules...' )
931912 runner .modules = modules
932913
933914 if args .no_kvm :
0 commit comments