Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90920711
bashCoat.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
Wed, Nov 6, 00:26
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Nov 8, 00:26 (2 d)
Engine
blob
Format
Raw Data
Handle
22156951
Attached To
R3127 blackdynamite
bashCoat.py
View Options
#!/usr/bin/env python
#from BlackDynamite import *
import
os
,
stat
import
subprocess
admissible_params
=
{
"stdout"
:
bool
,
"stop_on_error"
:
bool
}
default_params
=
{
"stop_on_error"
:
False
}
help
=
{
"stdout"
:
"Specify if you want the standard output instead of a file"
,
"stop_on_error"
:
"Specify if should raise an error in case of an error in the bash script"
}
def
launch
(
run
,
params
):
_exec
=
run
.
getExecFile
()
head
=
\
"""#!/bin/bash
export BLACKDYNAMITE_HOST=__BLACKDYNAMITE__dbhost__
export BLACKDYNAMITE_STUDY=__BLACKDYNAMITE__study__
export BLACKDYNAMITE_SCHEMA=__BLACKDYNAMITE__study__
export BLACKDYNAMITE_RUN_ID=__BLACKDYNAMITE__run_id__
export BLACKDYNAMITE_USER={0}
"""
.
format
(
params
[
"user"
])
_exec
[
"file"
]
=
run
.
replaceBlackDynamiteVariables
(
head
)
+
_exec
[
"file"
]
f
=
open
(
_exec
[
"filename"
],
'w'
)
f
.
write
(
_exec
[
"file"
])
f
.
close
()
os
.
chmod
(
_exec
[
"filename"
],
stat
.
S_IRWXU
)
print
(
"execute ./"
+
_exec
[
"filename"
])
if
(
params
[
"truerun"
]
==
True
):
run
[
"state"
]
=
"launched"
run
.
update
()
run
.
commit
()
filename
=
run
[
"run_name"
]
+
".o"
+
str
(
run
.
id
)
filename_err
=
run
[
"run_name"
]
+
".e"
+
str
(
run
.
id
)
if
(
params
[
"stdout"
]
==
True
):
ret
=
subprocess
.
call
(
"./"
+
_exec
[
"filename"
])
else
:
with
open
(
filename
,
"w"
)
as
outfile
:
with
open
(
filename_err
,
"w"
)
as
errfile
:
ret
=
subprocess
.
call
(
"./"
+
_exec
[
"filename"
],
stdout
=
outfile
,
stderr
=
errfile
)
if
ret
==
0
:
run
[
"state"
]
=
"FINISHED"
else
:
run
[
"state"
]
=
"BASH error"
run
.
update
()
run
.
commit
()
if
(
params
[
"stop_on_error"
]
==
True
and
not
ret
==
0
):
raise
Exception
(
"The underlying bash script returned with the error code {0}."
.
format
(
ret
))
Event Timeline
Log In to Comment