forked from pseyfert/gangascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveremote.py
87 lines (83 loc) · 2.88 KB
/
removeremote.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
85
86
def removeLFNs_subjobs(job,sublist):
ds = LHCbDataset()
if type(job.backend)==Dirac:
for sjid in sublist:
sj = job.subjobs(sjid)
if sj.status == 'completed':
for of in sj.outputfiles:
try:
the_lfn = of.lfn
except AttributeError:
pass
else:
ds.extend(of)
for lfn in ds:
lfn.remove()
def removeLFNs(job):
ds = LHCbDataset()
if type(job.backend)==Dirac:
for sj in job.subjobs:
if sj.status == 'completed':
for of in sj.outputfiles:
try:
the_lfn = of.lfn
if the_lfn=="":
raise AttributeError
except AttributeError:
pass
else:
ds.extend(of)
for lfn in ds:
lfn.remove()
def removeJobAndData(job):
removeLFNs(job)
job.remove()
def move_lfn_to_eos(diracfile):
'''
returns None if the only replicate is at cern, the lfn (as string) otherwise
'''
reps = diracfile.getReplicas()
if 'CERN-USER' not in reps[0].keys():
retval = diracfile.replicate('CERN-USER')
try:
isOkay = retval['OK']
except:
isOkay = True
reps = diracfile.getReplicas()
if 'CERN-USER' in reps[0].keys():
for key in reps[0].keys():
if key != 'CERN-USER':
# file is not only at CERN-USER, needs cleaning
return "cleanme"
return "onlycern"
return "notcern"
def move_job_to_eos(job):
ds = LHCbDataset()
if type(job.backend)==Dirac:
for sj in job.subjobs:
if sj.status == 'completed':
for of in sj.outputfiles:
try:
print "fixing ", of.lfn
except AttributeError:
pass
else:
ds.extend(of)
files_which_need_cleaning = []
failures = []
for fileobject in ds:
retval = move_lfn_to_eos(fileobject)
if retval == "cleanme":
files_which_need_cleaning.append(fileobject.lfn)
if retval == "notcern":
failures.append(fileobject.lfn)
if 0!=len(files_which_need_cleaning):
import subprocess
import os
try:
gangascriptdir = os.environ['GANGASCRIPTS']
except KeyError:
gangascriptdir = os.environ['HOME'] + "/gangascripts"
subprocess.call(["lb-run","LHCbDirac","prod","python",gangascriptdir+"/clean_replicas.py"]+files_which_need_cleaning)
if 0!=len(failures):
print "SOME FILES DIDN'T REACH CERN"