32
32
'opensuse-leap' : 'sles' ,
33
33
'opensuse' : 'sles' ,
34
34
'redhat' : 'rhel' ,
35
+ 'rocky' : 'rhel' ,
35
36
}
36
37
37
38
DISTRO_VERSION_MAP = {
46
47
'20.*' : 'ubuntu2004' ,
47
48
'18.*' : 'ubuntu1804' ,
48
49
'16.*' : 'ubuntu1604' ,
50
+ '14.*' : 'ubuntu1404' ,
49
51
},
50
52
'debian' : {
51
53
'9' : 'debian92' ,
54
56
},
55
57
'rhel' : {
56
58
'6' : 'rhel60' ,
59
+ '6.*' : 'rhel60' ,
57
60
'7' : 'rhel70' ,
61
+ '7.*' : 'rhel70' ,
58
62
'8' : 'rhel80' ,
63
+ '8.*' : 'rhel80' ,
59
64
},
60
65
'sles' : {
61
66
'10.*' : 'suse10' ,
65
70
'15.*' : 'suse15' ,
66
71
},
67
72
'amzn' : {
68
- '2018' : 'amzn64' ,
69
- '2' : 'amzn64 ' ,
73
+ '2018.* ' : 'amzn64' ,
74
+ '2' : 'amazon2 ' ,
70
75
},
71
76
}
72
77
@@ -84,12 +89,18 @@ def infer_target():
84
89
85
90
86
91
def _infer_target_os_rel ():
87
- content = Path ('/etc/os-release' ).read_text ()
92
+ with Path ('/etc/os-release' ).open ('r' , encoding = 'utf-8' ) as f :
93
+ content = f .read ()
88
94
id_re = re .compile (r'\bID=("?)(.*)\1' )
89
95
mat = id_re .search (content )
90
96
assert mat , 'Unable to detect ID from [/etc/os-release] content:\n {}' .format (
91
97
content )
92
98
os_id = mat .group (2 )
99
+ if os_id == 'arch' :
100
+ # There are no Archlinux-specific MongoDB downloads, so we'll just use
101
+ # the build for RHEL8, which is reasonably compatible with other modern
102
+ # distributions (including Arch).
103
+ return 'rhel80'
93
104
ver_id_re = re .compile (r'VERSION_ID=("?)(.*?)\1' )
94
105
mat = ver_id_re .search (content )
95
106
assert mat , 'Unable to detect VERSION_ID from [/etc/os-release] content:\n {}' .format (
@@ -122,11 +133,11 @@ def caches_root():
122
133
if sys .platform == 'win32' :
123
134
return Path (os .environ ['LocalAppData' ])
124
135
if sys .platform == 'darwin' :
125
- return Path ('~ /Library/Caches'). expanduser ( )
136
+ return Path (os . environ [ 'HOME' ] + ' /Library/Caches' )
126
137
xdg_cache = os .getenv ('XDG_CACHE_HOME' )
127
138
if xdg_cache :
128
139
return Path (xdg_cache )
129
- return Path ('~ /.cache'). expanduser ( )
140
+ return Path (os . environ [ 'HOME' ] + ' /.cache' )
130
141
131
142
132
143
def cache_dir ():
@@ -214,9 +225,27 @@ def _import_json_data(db, json_file):
214
225
)
215
226
216
227
228
+ def _mkdir (dirpath ):
229
+ """
230
+ Ensure a directory at ``dirpath``, and all parent directories thereof.
231
+
232
+ Cannot using Path.mkdir(parents, exist_ok) on some Python versions that
233
+ we need to support.
234
+ """
235
+ if dirpath .is_dir ():
236
+ return
237
+ par = dirpath .parent
238
+ if par != dirpath :
239
+ _mkdir (par )
240
+ try :
241
+ dirpath .mkdir ()
242
+ except FileExistsError :
243
+ pass
244
+
245
+
217
246
def get_dl_db ():
218
247
caches = cache_dir ()
219
- caches . mkdir ( exist_ok = True , parents = True )
248
+ _mkdir ( caches )
220
249
db = sqlite3 .connect (str (caches / 'downloads.db' ), isolation_level = None )
221
250
db .executescript (r'''
222
251
CREATE TABLE IF NOT EXISTS meta (
@@ -271,7 +300,7 @@ def _print_list(db, version, target, arch, edition, component):
271
300
' Edition: {}\n \n '
272
301
' Info: {}\n \n ' .format (comp_key , version , target , arch ,
273
302
edition , comp_data ))
274
- print (f '(Omit filter arguments for a list of available filters)' )
303
+ print ('(Omit filter arguments for a list of available filters)' )
275
304
return
276
305
277
306
arches , targets , editions , versions , components = next (
@@ -344,7 +373,7 @@ def _download_file(db, url):
344
373
return DLRes (False , dest )
345
374
else :
346
375
print ('Downloading [{}] ...' .format (url ))
347
- dest .parent . mkdir ( exist_ok = True , parents = True )
376
+ _mkdir ( dest .parent )
348
377
got_etag = resp .getheader ("ETag" )
349
378
got_modtime = resp .getheader ('Last-Modified' )
350
379
with dest .open ('wb' ) as of :
@@ -551,10 +580,10 @@ def _maybe_extract_member(out, relpath, pattern, strip, is_dir, opener,
551
580
# We are running in test-only mode: Do not do anything
552
581
return 1
553
582
if is_dir :
554
- dest . mkdir ( exist_ok = True , parents = True )
583
+ _mkdir ( dest )
555
584
return 1
556
585
with opener () as infile :
557
- dest .parent . mkdir ( exist_ok = True , parents = True )
586
+ _mkdir ( dest .parent )
558
587
with dest .open ('wb' ) as outfile :
559
588
shutil .copyfileobj (infile , outfile )
560
589
os .chmod (str (dest ), modebits )
0 commit comments