-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_pease_missing_data.py
More file actions
149 lines (117 loc) · 5.02 KB
/
sync_pease_missing_data.py
File metadata and controls
149 lines (117 loc) · 5.02 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#sync_pease_missing_data
import pandas as pd
import os
import shutil
import glob
verbose=True
drive_path="/media/tracy/NTFS Test"
pease_folder_list_dict=[
{"csv_file":"2023_Annular_Eclipse_Rd1_ESID.csv",
"top_out_dir":os.path.join(drive_path,"2023_Annular_Eclipse_Data_Rd_1"),
"Annular_Data":True,
"Total_Data":False,
"df_out_name":"2023_Annular_Eclipse_Rd1_out.csv"
},
{"csv_file":"2023_Annular_Eclipse_Rd2_ESID.csv",
"top_out_dir":os.path.join(drive_path,"2023_Annular_Eclipse_Data_Rd_1"),
"Annular_Data":True,
"Total_Data":False,
"df_out_name":"2023_Annular_Eclipse_Rd2_out.csv"
},
{"csv_file":"2024_Total_Eclipse_Rd1_ESID.csv",
"top_out_dir":os.path.join(drive_path,"2024_Total_Eclipse_Data_Rd_1"),
"Annular_Data":False,
"Total_Data":True,
"df_out_name":"2024_Total_Eclipse_Rd1_out.csv"
},
{"csv_file":"2024_Total_Eclipse_Rd2_ESID.csv",
"top_out_dir":os.path.join(drive_path,"2024_Total_Eclipse_Data_Rd_2"),
"Annular_Data":False,
"Total_Data":True,
"df_out_name":"2024_Total_Eclipse_Rd2_out.csv"
}
]
for dict_item in [pease_folder_list_dict[3]]:
Annular_Data=dict_item["Annular_Data"]
Total_Data=dict_item["Total_Data"]
if Annular_Data:
top_in_dir1="/media/tracy/ESCSPA00/2023_Annular_Raw_Data"
top_in_dir2="/media/tracy/ESCSPA01/2023_Annular_Raw_Data"
else:
top_in_dir1="/media/tracy/ESCSPA00/2024_Total_Raw_Data"
top_in_dir2="/media/tracy/ESCSPA01/2024_Total_Raw_Data"
df_in = pd.read_csv(dict_item["csv_file"])
missing_ESIDs=df_in["AudioMoth ES ID Number"]
path_exists=[]
number_of_files=[]
success=[]
success_binary_list=[]
top_out_dir=dict_item['top_out_dir']
if not os.path.isdir(top_out_dir):
os.system("mkdir "+top_out_dir)
for ESID in missing_ESIDs:
print(str(ESID).zfill(3))
folder_name="ESID#"+str(ESID).zfill(3)
in_path1=os.path.join(top_in_dir1,
folder_name
)
in_path2=os.path.join(top_in_dir2,
folder_name
)
out_path=top_out_dir
if verbose: print(in_path1)
if verbose: print(in_path2)
if verbose: print(out_path)
does_exist="No"
success_binary=0
file_num=0
Successfully_copied="No"
if os.path.isdir(in_path1):
does_exist="Yes"
#file_num=len(os.listdir(in_path1))
file_num = len(glob.glob(os.path.join(in_path1, "*.WAV")))
command_line="rsync -auv --exclude '.*' --exclude 'System*' "+in_path1+" "+out_path
if verbose: print("Command line= "+command_line)
os.system(command_line)
else:
if os.path.isdir(in_path2):
does_exist="Yes"
#file_num=len(os.listdir(in_path2))
file_num = len(glob.glob(os.path.join(in_path2, "*.WAV")))
command_line="rsync -auv --exclude '.*' --exclude 'System*' "+in_path2+" "+out_path
os.system(command_line)
path_exists.append(does_exist)
number_of_files.append(file_num)
success_binary_list.append(file_num)
out_dir_name=os.path.join(out_path, folder_name)
if os.path.isdir(out_dir_name):
if len(glob.glob(os.path.join(in_path1, "*.WAV"))) == file_num:
Successfully_copied="Yes"
success_binary=1
# if len(os.listdir(out_dir_name)) == file_num:
# Successfully_copied="Yes"
if os.path.isdir(in_path1) or os.path.isdir(in_path2):
for item in os.listdir(out_dir_name):
item_path = os.path.join(out_dir_name, item)
# Check if the item is hidden (starts with a dot)
if item.startswith('.') or item.startswith('System'):
try:
# If it's a file, remove it
if os.path.isfile(item_path):
os.remove(item_path)
print(f"Removed hidden file: {item_path}")
# If it's a directory, remove it along with all its contents
elif os.path.isdir(item_path):
shutil.rmtree(item_path)
print(f"Removed hidden folder: {item_path}")
except Exception as e:
print(f"Error removing {item_path}: {e}")
success.append(Successfully_copied)
success_binary_list.append(success_binary)
df_out=pd.DataFrame({"ESID #":missing_ESIDs,
"Folder Exists?":path_exists,
"Number of files in DB match number of files in drive?":success,
"Number of .WAV files":number_of_files
})
df_out.to_csv(dict_item["df_out_name"])
#os.system("mkdir "+wave_folder)