Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61922535
enterRun.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
Thu, May 9, 20:20
Size
2 KB
Mime Type
text/x-python
Expires
Sat, May 11, 20:20 (2 d)
Engine
blob
Format
Raw Data
Handle
17578094
Attached To
R3127 blackdynamite
enterRun.py
View Options
#!/usr/bin/env python3
################################################################
import
BlackDynamite
as
BD
import
subprocess
import
os
import
sys
import
socket
################################################################
parser
=
BD
.
BDParser
()
parser
.
register_params
(
group
=
"getRunInfo"
,
params
=
{
"run_id"
:
int
,
"order"
:
str
},
help
=
{
"run_id"
:
"Select a run_id for switching to it"
})
params
=
parser
.
parseBDParameters
()
mybase
=
BD
.
Base
(
**
params
)
if
'run_id'
in
params
:
params
[
'run_constraints'
]
=
[
'id = {0}'
.
format
(
params
[
'run_id'
])]
try
:
del
params
[
'job_constraints'
]
except
:
pass
runSelector
=
BD
.
RunSelector
(
mybase
)
run_list
=
runSelector
.
selectRuns
(
params
,
quiet
=
True
)
mybase
.
close
()
if
(
len
(
run_list
)
==
0
):
print
(
"no run found"
)
sys
.
exit
(
1
)
run
,
job
=
run_list
[
0
]
run_id
=
run
[
'id'
]
separator
=
'-'
*
30
print
(
separator
)
print
(
"JOB INFO"
)
print
(
separator
)
print
(
job
)
print
(
separator
)
print
(
"RUN INFO"
)
print
(
separator
)
print
(
run
)
print
(
separator
)
print
(
"LOGGING TO '{0}'"
.
format
(
run
[
'machine_name'
]))
print
(
separator
)
if
run
[
'state'
]
==
'CREATED'
:
print
(
"Cannot enter run: not yet started"
)
sys
.
exit
(
-
1
)
bashrc_filename
=
os
.
path
.
join
(
'/tmp'
,
'bashrc.user{0}.study{1}.run{2}'
.
format
(
params
[
'user'
],
params
[
'study'
],
run_id
))
bashrc
=
open
(
bashrc_filename
,
'w'
)
bashrc
.
write
(
'export PS1="
\\
u@
\\
h:<{0}|RUN-{1}> $ "
\n
'
.
format
(
params
[
'study'
],
run_id
))
bashrc
.
write
(
'cd {0}
\n
'
.
format
(
run
[
'run_path'
]))
bashrc
.
write
(
'echo '
+
separator
)
bashrc
.
close
()
command_login
=
'bash --rcfile {0} -i'
.
format
(
bashrc_filename
)
if
not
run
[
'machine_name'
]
==
socket
.
gethostname
():
command1
=
'scp -q {0} {1}:{0}'
.
format
(
bashrc_filename
,
run
[
'machine_name'
])
subprocess
.
call
(
command1
,
shell
=
True
)
command_login
=
'ssh -X -A -t {0} "{1}"'
.
format
(
run
[
'machine_name'
],
command_login
)
# print command_login
subprocess
.
call
(
command_login
,
shell
=
True
)
Event Timeline
Log In to Comment