4
4
"""
5
5
6
6
import logging
7
- import os
8
7
import pickle
9
8
import shutil
10
9
@@ -32,12 +31,11 @@ def cleanup():
32
31
If there is no key left for a compiled module, we delete the module.
33
32
34
33
"""
35
- compiledir = config .compiledir
36
- for directory in os .listdir (compiledir ):
34
+ for directory in config .compiledir .iterdir ():
37
35
try :
38
- filename = os . path . join ( compiledir , directory , "key.pkl" )
36
+ filename = directory / "key.pkl"
39
37
# print file
40
- with open (filename , "rb" ) as file :
38
+ with filename . open ("rb" ) as file :
41
39
try :
42
40
keydata = pickle .load (file )
43
41
@@ -78,7 +76,7 @@ def cleanup():
78
76
"the directory containing it."
79
77
)
80
78
if len (keydata .keys ) == 0 :
81
- shutil .rmtree (os . path . join ( compiledir , directory ) )
79
+ shutil .rmtree (directory )
82
80
83
81
except (EOFError , AttributeError ):
84
82
_logger .error (
@@ -116,11 +114,9 @@ def print_compiledir_content():
116
114
big_key_files = []
117
115
total_key_sizes = 0
118
116
nb_keys = {}
119
- for dir in os .listdir (compiledir ):
120
- filename = os .path .join (compiledir , dir , "key.pkl" )
121
- if not os .path .exists (filename ):
122
- continue
123
- with open (filename , "rb" ) as file :
117
+ for dir in config .compiledir .iterdir ():
118
+ filename = dir / "key.pkl"
119
+ with filename .open ("rb" ) as file :
124
120
try :
125
121
keydata = pickle .load (file )
126
122
ops = list ({x for x in flatten (keydata .keys ) if isinstance (x , Op )})
@@ -135,15 +131,11 @@ def print_compiledir_content():
135
131
{x for x in flatten (keydata .keys ) if isinstance (x , CType )}
136
132
)
137
133
compile_start = compile_end = float ("nan" )
138
- for fn in os .listdir (os .path .join (compiledir , dir )):
139
- if fn .startswith ("mod.c" ):
140
- compile_start = os .path .getmtime (
141
- os .path .join (compiledir , dir , fn )
142
- )
143
- elif fn .endswith (".so" ):
144
- compile_end = os .path .getmtime (
145
- os .path .join (compiledir , dir , fn )
146
- )
134
+ for fn in dir .iterdir ():
135
+ if fn .name == "mod.c" :
136
+ compile_start = fn .stat ().st_mtime
137
+ elif fn .suffix == ".so" :
138
+ compile_end = fn .stat ().st_mtime
147
139
compile_time = compile_end - compile_start
148
140
if len (ops ) == 1 :
149
141
table .append ((dir , ops [0 ], types , compile_time ))
@@ -154,7 +146,7 @@ def print_compiledir_content():
154
146
(dir , ops_to_str , types_to_str , compile_time )
155
147
)
156
148
157
- size = os . path . getsize ( filename )
149
+ size = filename . stat (). st_size
158
150
total_key_sizes += size
159
151
if size > max_key_file_size :
160
152
big_key_files .append ((dir , size , ops ))
@@ -242,8 +234,8 @@ def basecompiledir_ls():
242
234
"""
243
235
subdirs = []
244
236
others = []
245
- for f in os . listdir ( config .base_compiledir ):
246
- if os . path . isdir ( os . path . join ( config . base_compiledir , f ) ):
237
+ for f in config .base_compiledir . iterdir ( ):
238
+ if f . is_dir ( ):
247
239
subdirs .append (f )
248
240
else :
249
241
others .append (f )
0 commit comments