-
Notifications
You must be signed in to change notification settings - Fork 7k
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (34 loc) · 1.14 KB
/
utils.py
File metadata and controls
48 lines (34 loc) · 1.14 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import os
import pprint
import signal
from os import path
class ExitSignalHandler:
def __init__(self):
self.exit_now = False
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self, signum, frame):
self.exit_now = True
def write_failure_file(failure_file_path, failure_reason):
failure_file = open(failure_file_path, "w")
failure_file.write(failure_reason)
failure_file.close()
def save_model_artifacts(model_artifacts_path, net):
if path.exists(model_artifacts_path):
model_file = open(model_artifacts_path + "model.dummy", "w")
model_file.write("Dummy model.")
model_file.close()
def print_json_object(json_object):
pprint.pprint(json_object)
def load_json_object(json_file_path):
with open(json_file_path) as json_file:
return json.load(json_file)
def print_files_in_path(path):
files = []
# r=root, d=directories, f = files
for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))
for f in files:
print(f)