-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_sims.py
84 lines (70 loc) · 2.52 KB
/
clean_sims.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import os
from types import SimpleNamespace
from scripts.helpers import load_config
if __name__ == "__main__":
config = load_config(os.path.join("scripts", "visualizations", "config.json"))
sim_dir = config.simDirectoryToClean
cleaned_sim_dir = config.locationForCleanSims
failed_sim_dir = config.locationForFailedSims
if not os.path.exists(cleaned_sim_dir):
os.mkdir(cleaned_sim_dir)
if not os.path.exists(failed_sim_dir):
os.mkdir(failed_sim_dir)
def move_failed_file(sim_dir, failed_dir, file_name):
try:
os.rename(
os.path.join(sim_dir, file_name), os.path.join(failed_dir, file_name)
)
except:
os.rename(
os.path.join(sim_dir, file_name),
os.path.join(failed_dir, file_name + "_1"),
)
# purge routine
for sim in os.listdir(sim_dir):
if "_failed" in sim:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
else:
# check to see that it has all of the requisite data
files = os.listdir(os.path.join(sim_dir, sim))
if "CFD_mesh.msh" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
if "log.txt" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
if "D_file.txt" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
if "res_file.txt" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
if "sim_status.txt" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
if "sol_file.txt" not in files:
try:
move_failed_file(sim_dir, failed_sim_dir, sim)
except:
pass
# rename clean sim files in order and move to new directory
counter = len(os.listdir(cleaned_sim_dir))
for sim in os.listdir(sim_dir):
os.rename(
os.path.join(sim_dir, sim), os.path.join(cleaned_sim_dir, str(counter))
)
counter += 1