Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90393967
cleanRuns.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 1, 06:58
Size
2 KB
Mime Type
text/x-python
Expires
Sun, Nov 3, 06:58 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22067790
Attached To
R3127 blackdynamite
cleanRuns.py
View Options
#!/usr/bin/env python
import
base
import
job
import
run
import
os
,
sys
,
stat
import
subprocess
import
getopt
import
socket
import
bdparser
import
runselector
import
re
import
shutil
def
validate
(
question
):
if
(
params
[
"truerun"
]
==
True
):
print
(
question
+
"? (Y/n)"
)
validated
=
sys
.
stdin
.
read
(
1
)
if
(
validated
==
"
\n
"
or
validated
==
"Y"
or
validated
==
"y"
):
validated
=
True
else
:
validated
=
False
else
:
print
(
question
)
validated
=
False
return
validated
parser
=
bdparser
.
BDParser
()
parser
.
declareBDParameters
(
additional_params
=
{
\
"runid"
:
int
,
\
"state"
:
str
,
\
"run_constraints"
:[
str
],
\
"job_constraints"
:[
str
],
\
"clean_orphans"
:
str
},
\
# default_additional_params={ \
# "run_constraints":"", \
# "job_constraints":"" \
# }
)
params
=
parser
.
parseBDParameters
()
base
=
base
.
Base
(
**
params
)
runSelector
=
runselector
.
RunSelector
(
base
)
if
(
"clean_orphans"
in
params
):
run_list
=
runSelector
.
selectRuns
([],[])
run_ids
=
[
r
.
id
for
r
in
run_list
]
print
(
"clean orphans"
)
resdir
=
params
[
"clean_orphans"
]
+
"/BD-"
+
params
[
"study"
]
+
"-runs"
if
not
os
.
path
.
exists
(
resdir
):
print
(
"Directory '"
+
resdir
+
"' do not exists"
)
sys
.
exit
(
-
1
)
for
filename
in
os
.
listdir
(
resdir
):
fullname
=
os
.
path
.
join
(
resdir
,
filename
)
if
(
os
.
path
.
isdir
(
fullname
)):
match
=
re
.
match
(
"run-([0-9]+)"
,
filename
)
if
(
match
):
# print (filename)
id
=
int
(
match
.
group
(
1
))
if
(
id
not
in
run_ids
):
validated
=
validate
(
"Delete output from run "
+
str
(
id
))
if
(
validated
):
shutil
.
rmtree
(
fullname
)
sys
.
exit
(
0
)
runSelector
=
runselector
.
RunSelector
(
base
)
run_constraints
=
[]
if
(
"run_constraints"
in
params
):
run_constraints
=
params
[
"run_constraints"
]
job_constraints
=
[]
if
(
"job_constraints"
in
params
):
job_constraints
=
params
[
"job_constraints"
]
run_list
=
runSelector
.
selectRuns
(
run_constraints
,
job_constraints
)
print
(
run_list
)
print
(
params
)
if
(
len
(
run_list
)
==
0
):
print
"No runs to be cleared"
for
j
in
run_list
:
validated
=
validate
(
"Delete run "
+
str
(
j
.
id
))
run_path
=
j
[
"run_path"
]
if
os
.
path
.
exists
(
run_path
):
if
(
validated
):
print
(
"deleting directory: "
+
run_path
)
shutil
.
rmtree
(
run_path
)
else
:
print
(
"Simulate deletion of directory: "
+
run_path
)
else
:
print
(
"output directory: "
+
run_path
+
"
\n
not found: are we on the right machine ?"
)
continue
print
(
"deleting run "
+
str
(
j
.
id
)
+
" from base"
)
if
(
validated
):
j
.
delete
()
base
.
commit
()
else
:
print
(
"Simulate deletion of run "
+
str
(
j
.
id
)
+
" from base"
)
Event Timeline
Log In to Comment