Commit 3e13218e authored by Manuel Günther's avatar Manuel Günther

Made gridtk python 3 compatible.

parent c92867a3
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
"""Defines the job manager which can help you managing submitted grid jobs. """Defines the job manager which can help you managing submitted grid jobs.
""" """
from __future__ import print_function
import subprocess import subprocess
import time import time
import copy, os, sys import copy, os, sys
...@@ -43,7 +45,7 @@ class JobManagerLocal(JobManager): ...@@ -43,7 +45,7 @@ class JobManagerLocal(JobManager):
logger.info("Added job '%s' to the database" % job) logger.info("Added job '%s' to the database" % job)
if dry_run: 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) self.session.delete(job)
logger.info("Deleted job '%s' from the database due to dry-run option" % job) logger.info("Deleted job '%s' from the database due to dry-run option" % job)
job_id = None job_id = None
......
from __future__ import print_function
import os import os
import subprocess import subprocess
from .models import Base, Job, ArrayJob from .models import Base, Job, ArrayJob
...@@ -167,18 +169,18 @@ class JobManager: ...@@ -167,18 +169,18 @@ class JobManager:
header = [fields[k].center(lengths[k]) for k in range(len(lengths))] header = [fields[k].center(lengths[k]) for k in range(len(lengths))]
# print header # print header
print ' '.join(header) print(' '.join(header))
print delimiter print(delimiter)
self.lock() self.lock()
for job in self.get_jobs(job_ids): 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: if print_array_jobs and job.array:
print array_delimiter print(array_delimiter)
for array_job in job.array: for array_job in job.array:
print array_job.format(array_format) print(array_job.format(array_format))
print array_delimiter print(array_delimiter)
self.unlock() self.unlock()
...@@ -190,17 +192,17 @@ class JobManager: ...@@ -190,17 +192,17 @@ class JobManager:
out_file, err_file = job.std_out_file(), job.std_err_file() 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: 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) logger.info("Contents of output file: '%s'" % out_file)
print open(out_file).read().rstrip() print(open(out_file).read().rstrip())
print "-"*20 print("-"*20)
if error and err_file is not None and os.path.exists(err_file) and os.stat(err_file).st_size > 0: 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) logger.info("Contents of error file: '%s'" % err_file)
print open(err_file).read().rstrip() print(open(err_file).read().rstrip())
print "-"*40 print("-"*40)
def _write_array_jobs(array_jobs): def _write_array_jobs(array_jobs):
for array_job in array_jobs: for array_job in array_jobs:
if unfinished or array_job.status in ('success', 'failure'): 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) _write_contents(array_job)
self.lock() self.lock()
...@@ -209,7 +211,7 @@ class JobManager: ...@@ -209,7 +211,7 @@ class JobManager:
if array_ids: if array_ids:
if len(job_ids) != 1: logger.error("If array ids are specified exactly one job id must be given.") 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))) 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) _write_array_jobs(array_jobs)
else: else:
...@@ -218,14 +220,14 @@ class JobManager: ...@@ -218,14 +220,14 @@ class JobManager:
for job in jobs: for job in jobs:
if job.array: if job.array:
if (unfinished or job.status in ('success', 'failure', 'executing')): if (unfinished or job.status in ('success', 'failure', 'executing')):
print job print(job)
_write_array_jobs(job.array) _write_array_jobs(job.array)
else: else:
if unfinished or job.status in ('success', 'failure'): if unfinished or job.status in ('success', 'failure'):
print job print(job)
_write_contents(job) _write_contents(job)
if job.log_dir is not None: if job.log_dir is not None:
print "-"*60 print("-"*60)
self.unlock() self.unlock()
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
"""Executes a given command within the context of a shell script that has its """Executes a given command within the context of a shell script that has its
enviroment set like Idiap's 'SETSHELL grid' does.""" enviroment set like Idiap's 'SETSHELL grid' does."""
from __future__ import print_function
import os import os
import sys import sys
...@@ -22,10 +24,9 @@ def main(): ...@@ -22,10 +24,9 @@ def main():
if prog == 'grid': if prog == 'grid':
# act as before # act as before
if len(sys.argv) < 2: if len(sys.argv) < 2:
print __doc__ print(__doc__)
print "usage: %s <command> [arg [arg ...]]" % \ print("usage: %s <command> [arg [arg ...]]" % os.path.basename(sys.argv[0]))
os.path.basename(sys.argv[0]) return 1
sys.exit(1)
replace('grid', sys.argv[1:]) replace('grid', sys.argv[1:])
else: else:
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
"""Defines the job manager which can help you managing submitted grid jobs. """Defines the job manager which can help you managing submitted grid jobs.
""" """
from __future__ import print_function
from .manager import JobManager from .manager import JobManager
from .setshell import environ from .setshell import environ
from .models import add_job from .models import add_job
...@@ -76,9 +78,9 @@ class JobManagerSGE(JobManager): ...@@ -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) 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) logger.info("Added job '%s' to the database." % job)
if dry_run: if dry_run:
print "Would have added the Job" print("Would have added the Job")
print job print(job)
print "to the database to be executed in the grid with options:", str(kwargs) print("to the database to be executed in the grid with options:", str(kwargs))
self.session.delete(job) self.session.delete(job)
logger.info("Deleted job '%s' from the database due to dry-run option" % job) logger.info("Deleted job '%s' from the database due to dry-run option" % job)
job_id = None job_id = None
......
from __future__ import print_function
import unittest import unittest
import nose import nose
...@@ -44,7 +47,7 @@ class GridTKTest(unittest.TestCase): ...@@ -44,7 +47,7 @@ class GridTKTest(unittest.TestCase):
# check that the database was created successfully # check that the database was created successfully
assert os.path.exists(self.database) assert os.path.exists(self.database)
print print()
# test that the list command works (should also work with the "default" grid manager # 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', '1'])
jman.main(['./bin/jman', '--database', self.database, 'list', '--job-ids', '2', '--print-array-jobs', '--print-dependencies']) jman.main(['./bin/jman', '--database', self.database, 'list', '--job-ids', '2', '--print-array-jobs', '--print-dependencies'])
...@@ -164,11 +167,11 @@ class GridTKTest(unittest.TestCase): ...@@ -164,11 +167,11 @@ class GridTKTest(unittest.TestCase):
assert jobs[1].array[i].result == 0 assert jobs[1].array[i].result == 0
job_manager.unlock() job_manager.unlock()
print print()
# test that the list command still works # test that the list command still works
jman.main(['./bin/jman', '--database', self.database, 'list', '--print-array-jobs']) jman.main(['./bin/jman', '--database', self.database, 'list', '--print-array-jobs'])
print print()
# test that the list command still works # test that the list command still works
jman.main(['./bin/jman', '--database', self.database, 'report']) jman.main(['./bin/jman', '--database', self.database, 'report'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment