| 129 | return min(usable_cpus, config_nr_cpus) |
| 130 | |
| 131 | def _get_kernel_ver_tuple(self, decomp_prog: str) -> tuple[int, ...]: |
| 132 | if self.kernel == utils.UNINIT_PATH: |
| 133 | msg = 'No kernel set?' |
| 134 | raise RuntimeError(msg) |
| 135 | |
| 136 | utils.check_cmd(decomp_prog) |
| 137 | if decomp_prog == 'gzip': |
| 138 | decomp_cmd = [decomp_prog, '-c', '-d', self.kernel] |
| 139 | else: |
| 140 | msg = f"Unsupported decompression program ('{decomp_prog}')?" |
| 141 | raise RuntimeError(msg) |
| 142 | decomp = subprocess.run(decomp_cmd, capture_output=True, check=True) |
| 143 | |
| 144 | utils.check_cmd('strings') |
| 145 | strings = subprocess.run('strings', capture_output=True, check=True, input=decomp.stdout) |
| 146 | strings_stdout = strings.stdout.decode(encoding='utf-8', errors='ignore') |
| 147 | |
| 148 | if not ( |
| 149 | match := re.search( |
| 150 | r'^Linux version (\d+\.\d+\.\d+)', strings_stdout, flags=re.MULTILINE |
| 151 | ) |
| 152 | ): |
| 153 | msg = f"Could not find Linux version in {self.kernel}?" |
| 154 | raise RuntimeError(msg) |
| 155 | |
| 156 | return tuple(int(x) for x in match.groups()[0].split('.')) |
| 157 | |
| 158 | def _get_qemu_ver_string(self) -> str: |
| 159 | if self._qemu_path == utils.UNINIT_PATH: |