-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
26 lines (22 loc) · 750 Bytes
/
utils.py
File metadata and controls
26 lines (22 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import errno
import os
import zipfile
def mkdirp(dir):
if not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
def extract_saved(tmp_folder, filepath):
has_saved_checkpoint = False
with zipfile.ZipFile(filepath, 'r') as zip_file:
namelist = zip_file.namelist()
for name in namelist:
if name == 'checkpoint':
has_saved_checkpoint = True
filecontent = zip_file.read(name)
filepath = os.path.join(tmp_folder, name)
with open(filepath, 'wb') as f:
f.write(filecontent)
return has_saved_checkpoint