-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_raw.py
66 lines (53 loc) · 1.6 KB
/
delete_raw.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
# Delete the raw data files for a day
#
# Author James Dempsey
# Date 6 Sep 2016
import csv
import glob
import sys
import magmo
import os
import shutil
import time
# functions
def get_day_data(day):
"""
Read the magmo-days-full.csv file and find the row for the requested day.
:param day: The day to be found
:return: The day's row, or None if the day is not defined
"""
with open('magmo-days-full.csv', 'rb') as magmodays:
reader = csv.reader(magmodays)
for row in reader:
if row[0] == day:
return row
return None
def main():
# Read day parameter
if len(sys.argv) != 2:
print("Incorrect number of parameters.")
print("Usage: python delete_raw.py day")
exit(1)
day = sys.argv[1]
start = time.time()
# Read metadata for the day (file pattern fragments etc)
dayRow = get_day_data(day)
if dayRow is None:
print "Day %s is not defined." % (day)
exit(1)
print "#### Started deleting raw data for MAGMO day %s at %s ####" % \
(day, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start)))
print dayRow
# Delete files
startDatePatterns = 2
for i in range(startDatePatterns, len(dayRow)):
os.system("rm -r rawdata/" + dayRow[i] + "* ")
# Report
end = time.time()
print '#### Deleting completed at %s ####' \
% (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end)))
print 'Processed in %.02f s' % (end - start)
return 0
# Run the script if it is called from the command line
if __name__ == "__main__":
exit(main())