11from __future__ import annotations
22
33import base64
4+ import dataclasses
45import io
56import logging
67import os
7980)
8081
8182
83+ @dataclasses
84+ class Distro :
85+ name : str
86+ version_id : str
87+ arch : str
88+
89+
8290def write_env (name : str , value : Any ) -> None :
8391 with ENV_FILE .open ("a" , newline = "\n " ) as fid :
8492 # Remove any existing quote chars.
@@ -97,6 +105,20 @@ def run_command(cmd: str) -> None:
97105 LOGGER .info ("Running command %s... done." , cmd )
98106
99107
108+ def get_distro () -> Distro :
109+ name = ""
110+ version_id = ""
111+ arch = platform .machine ()
112+ with open ("/etc/os-release" ) as fid :
113+ for line in fid .readlines ():
114+ line = line .replace ('"' , "" ) # noqa: PLW2901
115+ if line .startswith ("NAME=" ):
116+ _ , _ , name = line .strip ().partition ("=" )
117+ if line .startswith ("VERSION_ID=" ):
118+ _ , _ , version_id = line .strip ().partition ("=" )
119+ return Distro (name = name , version_id = version_id , arch = arch )
120+
121+
100122def setup_libmongocrypt ():
101123 target = ""
102124 if PLATFORM == "windows" :
@@ -109,23 +131,14 @@ def setup_libmongocrypt():
109131 target = "macos"
110132
111133 else :
112- name = ""
113- version_id = ""
114- arch = platform .machine ()
115- with open ("/etc/os-release" ) as fid :
116- for line in fid .readlines ():
117- line = line .replace ('"' , "" ) # noqa: PLW2901
118- if line .startswith ("NAME=" ):
119- _ , _ , name = line .strip ().partition ("=" )
120- if line .startswith ("VERSION_ID=" ):
121- _ , _ , version_id = line .strip ().partition ("=" )
122- if name .startswith ("Debian" ):
123- target = f"debian{ version_id } "
124- elif name .startswith ("Red Hat" ):
125- if version_id .startswith ("7" ):
134+ distro = get_distro ()
135+ if distro .name .startswith ("Debian" ):
136+ target = f"debian{ distro .version_id } "
137+ elif distro .name .startswith ("Red Hat" ):
138+ if distro .version_id .startswith ("7" ):
126139 target = "rhel-70-64-bit"
127- elif version_id .startswith ("8" ):
128- if arch == "aarch64" :
140+ elif distro . version_id .startswith ("8" ):
141+ if distro . arch == "aarch64" :
129142 target = "rhel-82-arm64"
130143 else :
131144 target = "rhel-80-64-bit"
0 commit comments