diff options
author | K900 <me@0upti.me> | 2023-09-22 16:10:21 +0300 |
---|---|---|
committer | K900 <me@0upti.me> | 2023-09-22 16:10:58 +0300 |
commit | eadfc7b13133c0f23dd4717f25f65ea981b40344 (patch) | |
tree | cd21872f086167c3a022a875f211ba12b448f30e /pkgs/os-specific/linux/kernel/update-mainline.py | |
parent | c08efe1438362d2cdcb64849bd7e28dd688b55f6 (diff) |
linux/update-script: format with black + isort
Diffstat (limited to 'pkgs/os-specific/linux/kernel/update-mainline.py')
-rwxr-xr-x | pkgs/os-specific/linux/kernel/update-mainline.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/pkgs/os-specific/linux/kernel/update-mainline.py b/pkgs/os-specific/linux/kernel/update-mainline.py index 8fac82e6633ee..df8257fa0ef0a 100755 --- a/pkgs/os-specific/linux/kernel/update-mainline.py +++ b/pkgs/os-specific/linux/kernel/update-mainline.py @@ -1,26 +1,27 @@ #!/usr/bin/env nix-shell #!nix-shell -i python3 -p "python3.withPackages (ps: [ ps.beautifulsoup4 ps.lxml ])" -from enum import Enum -from bs4 import BeautifulSoup, NavigableString, Tag -from dataclasses import dataclass import json +import os import pathlib -import re import subprocess -import urllib.request import sys -import os +import urllib.request +from dataclasses import dataclass +from enum import Enum +from bs4 import BeautifulSoup, NavigableString, Tag HERE = pathlib.Path(__file__).parent ROOT = HERE.parent.parent.parent.parent VERSIONS_FILE = HERE / "kernels-org.json" + class KernelNature(Enum): MAINLINE = 1 STABLE = 2 LONGTERM = 3 + @dataclass class KernelRelease: nature: KernelNature @@ -30,20 +31,21 @@ class KernelRelease: link: str eol: bool = False + def parse_release(release: Tag) -> KernelRelease | None: - columns: list[Tag] = list(release.find_all('td')) + columns: list[Tag] = list(release.find_all("td")) try: - nature = KernelNature[columns[0].get_text().rstrip(':').upper()] + nature = KernelNature[columns[0].get_text().rstrip(":").upper()] except KeyError: return None - version = columns[1].get_text().rstrip(' [EOL]') + version = columns[1].get_text().rstrip(" [EOL]") date = columns[2].get_text() - link = columns[3].find('a') + link = columns[3].find("a") if link is not None and isinstance(link, Tag): - link = link.attrs.get('href') - assert link is not None, f'link for kernel {version} is non-existent' - eol = bool(release.find(class_='eolkernel')) + link = link.attrs.get("href") + assert link is not None, f"link for kernel {version} is non-existent" + eol = bool(release.find(class_="eolkernel")) return KernelRelease( nature=nature, @@ -54,14 +56,16 @@ def parse_release(release: Tag) -> KernelRelease | None: eol=eol, ) + def get_branch(version: str): # This is a testing kernel. - if 'rc' in version: - return 'testing' + if "rc" in version: + return "testing" else: major, minor, *_ = version.split(".") return f"{major}.{minor}" + def get_hash(kernel: KernelRelease): if kernel.branch == "testing": args = ["--unpack"] @@ -83,19 +87,19 @@ def commit(message): def main(): kernel_org = urllib.request.urlopen("https://kernel.org/") soup = BeautifulSoup(kernel_org.read().decode(), "lxml") - release_table = soup.find(id='releases') + release_table = soup.find(id="releases") if not release_table or isinstance(release_table, NavigableString): print(release_table) - print('Failed to find the release table on https://kernel.org') + print("Failed to find the release table on https://kernel.org") sys.exit(1) - releases = release_table.find_all('tr') + releases = release_table.find_all("tr") parsed_releases = filter(None, [parse_release(release) for release in releases]) all_kernels = json.load(VERSIONS_FILE.open()) for kernel in parsed_releases: branch = get_branch(kernel.version) - nixpkgs_branch = branch.replace('.', '_') + nixpkgs_branch = branch.replace(".", "_") old_version = all_kernels.get(branch, {}).get("version") if old_version == kernel.version: |