1
1
from __future__ import annotations
2
2
3
3
import base64
4
+ import dataclasses
4
5
import io
5
6
import logging
6
7
import os
79
80
)
80
81
81
82
83
+ @dataclasses
84
+ class Distro :
85
+ name : str
86
+ version_id : str
87
+ arch : str
88
+
89
+
82
90
def write_env (name : str , value : Any ) -> None :
83
91
with ENV_FILE .open ("a" , newline = "\n " ) as fid :
84
92
# Remove any existing quote chars.
@@ -97,6 +105,20 @@ def run_command(cmd: str) -> None:
97
105
LOGGER .info ("Running command %s... done." , cmd )
98
106
99
107
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
+
100
122
def setup_libmongocrypt ():
101
123
target = ""
102
124
if PLATFORM == "windows" :
@@ -109,23 +131,14 @@ def setup_libmongocrypt():
109
131
target = "macos"
110
132
111
133
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" ):
126
139
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" :
129
142
target = "rhel-82-arm64"
130
143
else :
131
144
target = "rhel-80-64-bit"
0 commit comments