Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
gridtk
Commits
3e13218e
Commit
3e13218e
authored
Aug 13, 2013
by
Manuel Günther
Browse files
Made gridtk python 3 compatible.
parent
c92867a3
Changes
5
Hide whitespace changes
Inline
Side-by-side
gridtk/local.py
View file @
3e13218e
...
...
@@ -6,6 +6,8 @@
"""Defines the job manager which can help you managing submitted grid jobs.
"""
from
__future__
import
print_function
import
subprocess
import
time
import
copy
,
os
,
sys
...
...
@@ -43,7 +45,7 @@ class JobManagerLocal(JobManager):
logger
.
info
(
"Added job '%s' to the database"
%
job
)
if
dry_run
:
print
"Would have added the Job"
,
job
,
"to the database to be executed locally."
print
(
"Would have added the Job"
,
job
,
"to the database to be executed locally."
)
self
.
session
.
delete
(
job
)
logger
.
info
(
"Deleted job '%s' from the database due to dry-run option"
%
job
)
job_id
=
None
...
...
gridtk/manager.py
View file @
3e13218e
from
__future__
import
print_function
import
os
import
subprocess
from
.models
import
Base
,
Job
,
ArrayJob
...
...
@@ -167,18 +169,18 @@ class JobManager:
header
=
[
fields
[
k
].
center
(
lengths
[
k
])
for
k
in
range
(
len
(
lengths
))]
# print header
print
' '
.
join
(
header
)
print
delimiter
print
(
' '
.
join
(
header
)
)
print
(
delimiter
)
self
.
lock
()
for
job
in
self
.
get_jobs
(
job_ids
):
print
job
.
format
(
format
,
dependency_length
,
None
if
long
else
43
)
print
(
job
.
format
(
format
,
dependency_length
,
None
if
long
else
43
)
)
if
print_array_jobs
and
job
.
array
:
print
array_delimiter
print
(
array_delimiter
)
for
array_job
in
job
.
array
:
print
array_job
.
format
(
array_format
)
print
array_delimiter
print
(
array_job
.
format
(
array_format
)
)
print
(
array_delimiter
)
self
.
unlock
()
...
...
@@ -190,17 +192,17 @@ class JobManager:
out_file
,
err_file
=
job
.
std_out_file
(),
job
.
std_err_file
()
if
output
and
out_file
is
not
None
and
os
.
path
.
exists
(
out_file
)
and
os
.
stat
(
out_file
).
st_size
>
0
:
logger
.
info
(
"Contents of output file: '%s'"
%
out_file
)
print
open
(
out_file
).
read
().
rstrip
()
print
"-"
*
20
print
(
open
(
out_file
).
read
().
rstrip
()
)
print
(
"-"
*
20
)
if
error
and
err_file
is
not
None
and
os
.
path
.
exists
(
err_file
)
and
os
.
stat
(
err_file
).
st_size
>
0
:
logger
.
info
(
"Contents of error file: '%s'"
%
err_file
)
print
open
(
err_file
).
read
().
rstrip
()
print
"-"
*
40
print
(
open
(
err_file
).
read
().
rstrip
()
)
print
(
"-"
*
40
)
def
_write_array_jobs
(
array_jobs
):
for
array_job
in
array_jobs
:
if
unfinished
or
array_job
.
status
in
(
'success'
,
'failure'
):
print
"Array Job"
,
str
(
array_job
.
id
),
":"
print
(
"Array Job"
,
str
(
array_job
.
id
),
":"
)
_write_contents
(
array_job
)
self
.
lock
()
...
...
@@ -209,7 +211,7 @@ class JobManager:
if
array_ids
:
if
len
(
job_ids
)
!=
1
:
logger
.
error
(
"If array ids are specified exactly one job id must be given."
)
array_jobs
=
list
(
self
.
session
.
query
(
ArrayJob
).
join
(
Job
).
filter
(
Job
.
id
.
in_
(
job_ids
)).
filter
(
Job
.
unique
==
ArrayJob
.
job_id
).
filter
(
ArrayJob
.
id
.
in_
(
array_ids
)))
if
array_jobs
:
print
array_jobs
[
0
].
job
if
array_jobs
:
print
(
array_jobs
[
0
].
job
)
_write_array_jobs
(
array_jobs
)
else
:
...
...
@@ -218,14 +220,14 @@ class JobManager:
for
job
in
jobs
:
if
job
.
array
:
if
(
unfinished
or
job
.
status
in
(
'success'
,
'failure'
,
'executing'
)):
print
job
print
(
job
)
_write_array_jobs
(
job
.
array
)
else
:
if
unfinished
or
job
.
status
in
(
'success'
,
'failure'
):
print
job
print
(
job
)
_write_contents
(
job
)
if
job
.
log_dir
is
not
None
:
print
"-"
*
60
print
(
"-"
*
60
)
self
.
unlock
()
...
...
gridtk/script/grid.py
View file @
3e13218e
...
...
@@ -6,6 +6,8 @@
"""Executes a given command within the context of a shell script that has its
enviroment set like Idiap's 'SETSHELL grid' does."""
from
__future__
import
print_function
import
os
import
sys
...
...
@@ -22,10 +24,9 @@ def main():
if
prog
==
'grid'
:
# act as before
if
len
(
sys
.
argv
)
<
2
:
print
__doc__
print
"usage: %s <command> [arg [arg ...]]"
%
\
os
.
path
.
basename
(
sys
.
argv
[
0
])
sys
.
exit
(
1
)
print
(
__doc__
)
print
(
"usage: %s <command> [arg [arg ...]]"
%
os
.
path
.
basename
(
sys
.
argv
[
0
]))
return
1
replace
(
'grid'
,
sys
.
argv
[
1
:])
else
:
...
...
gridtk/sge.py
View file @
3e13218e
...
...
@@ -6,6 +6,8 @@
"""Defines the job manager which can help you managing submitted grid jobs.
"""
from
__future__
import
print_function
from
.manager
import
JobManager
from
.setshell
import
environ
from
.models
import
add_job
...
...
@@ -76,9 +78,9 @@ class JobManagerSGE(JobManager):
job
=
add_job
(
self
.
session
,
command_line
,
name
,
dependencies
,
array
,
log_dir
=
log_dir
,
stop_on_failure
=
stop_on_failure
,
context
=
self
.
context
,
**
kwargs
)
logger
.
info
(
"Added job '%s' to the database."
%
job
)
if
dry_run
:
print
"Would have added the Job"
print
job
print
"to the database to be executed in the grid with options:"
,
str
(
kwargs
)
print
(
"Would have added the Job"
)
print
(
job
)
print
(
"to the database to be executed in the grid with options:"
,
str
(
kwargs
)
)
self
.
session
.
delete
(
job
)
logger
.
info
(
"Deleted job '%s' from the database due to dry-run option"
%
job
)
job_id
=
None
...
...
gridtk/tests/__init__.py
View file @
3e13218e
from
__future__
import
print_function
import
unittest
import
nose
...
...
@@ -44,7 +47,7 @@ class GridTKTest(unittest.TestCase):
# check that the database was created successfully
assert
os
.
path
.
exists
(
self
.
database
)
print
print
()
# test that the list command works (should also work with the "default" grid manager
jman
.
main
([
'./bin/jman'
,
'--database'
,
self
.
database
,
'list'
,
'--job-ids'
,
'1'
])
jman
.
main
([
'./bin/jman'
,
'--database'
,
self
.
database
,
'list'
,
'--job-ids'
,
'2'
,
'--print-array-jobs'
,
'--print-dependencies'
])
...
...
@@ -164,11 +167,11 @@ class GridTKTest(unittest.TestCase):
assert
jobs
[
1
].
array
[
i
].
result
==
0
job_manager
.
unlock
()
print
print
()
# test that the list command still works
jman
.
main
([
'./bin/jman'
,
'--database'
,
self
.
database
,
'list'
,
'--print-array-jobs'
])
print
print
()
# test that the list command still works
jman
.
main
([
'./bin/jman'
,
'--database'
,
self
.
database
,
'report'
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment