-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathremove_archived.py
executable file
·65 lines (57 loc) · 1.8 KB
/
remove_archived.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
#!/usr/bin/env python
from __future__ import print_function
from surveys_db import SurveysDB
import glob
import os
import sys
# remove archived data! Yikes!
with SurveysDB() as sdb:
sdb.cur.execute('select * from fields where (status="Verified" or status="Archived" or status="Proprietary") and archive_version>=4 and clustername="Herts" and location like "%beegfs%"')
results=sdb.cur.fetchall()
dryrun=True
try:
if sys.argv[1]=="delete":
dryrun=False
except:
pass
if len(sys.argv)>2:
selected=sys.argv[2:]
else:
selected=None
if selected:
for i in range(len(selected)):
if selected[i]=='.':
selected[i]=os.getcwd().split('/')[-1]
deleted=[]
for r in results:
location=r['location']
if not location:
continue
if not os.path.isdir(location):
continue
print(r['id'],r['location'])
g=len(glob.glob(location+'/*.archive'))
g2=len(glob.glob(location+'/*.fz'))
print(r['id'], g, g2)
if selected is not None and r['id'] not in selected:
print('Failed selection, skipping')
continue
if g>3 or selected is not None:
print('Deleting files from',r['id'],'at',location)
print('In DR3 dir:',len(glob.glob('/data/lofar/DR3/fields/'+r['id']+'/*NS*int*.fits')),len(glob.glob('/data/lofar/DR3/fields/'+r['id']+'/*.fz')))
if dryrun:
print('Only not really')
else:
os.system('rm -r '+location+'/*')
os.system('rmdir '+location)
#os.system('rm ~/ddfp-'+r['id']+'.*')
os.system('rm /beegfs/car/mjh/torque/ddfp-'+r['id']+'.*')
rr=r
rr['location']=''
deleted.append(rr)
else:
print('Not removing',r['id'])
if not dryrun:
with SurveysDB() as sdb:
for r in deleted:
sdb.set_field(r)