Commit a29e74a9 authored by Manuel Günther's avatar Manuel Günther

Fixed python 2.6 incompatibility; added possibility to list only jobs with given statuses.

parent 4272ec66
......@@ -154,21 +154,21 @@ class JobManager:
self.unlock()
def list(self, job_ids, print_array_jobs = False, print_dependencies = False, long = False):
def list(self, job_ids, print_array_jobs = False, print_dependencies = False, long = False, status=Status):
"""Lists the jobs currently added to the database."""
# configuration for jobs
if print_dependencies:
fields = ("job-id", "queue", "status", "job-name", "dependencies", "submitted command line")
lengths = (20, 9, 14, 20, 30, 43)
format = "{:^%d} {:^%d} {:^%d} {:^%d} {:^%d} {:<%d}" % lengths
format = "{0:^%d} {1:^%d} {2:^%d} {3:^%d} {4:^%d} {5:<%d}" % lengths
dependency_length = lengths[4]
else:
fields = ("job-id", "queue", "status", "job-name", "submitted command line")
lengths = (20, 9, 14, 20, 43)
format = "{:^%d} {:^%d} {:^%d} {:^%d} {:<%d}" % lengths
format = "{0:^%d} {1:^%d} {2:^%d} {3:^%d} {4:<%d}" % lengths
dependency_length = 0
array_format = "{:>%d} {:^%d} {:^%d}" % lengths[:3]
array_format = "{0:>%d} {1:^%d} {2:^%d}" % lengths[:3]
delimiter = format.format(*['='*k for k in lengths])
array_delimiter = array_format.format(*["-"*k for k in lengths[:3]])
header = [fields[k].center(lengths[k]) for k in range(len(lengths))]
......@@ -180,6 +180,7 @@ class JobManager:
self.lock()
for job in self.get_jobs(job_ids):
if job.status in status:
print(job.format(format, dependency_length, None if long else 43))
if print_array_jobs and job.array:
print(array_delimiter)
......
......@@ -121,7 +121,7 @@ def run_scheduler(args):
def list(args):
"""Lists the jobs in the given database."""
jm = setup(args)
jm.list(job_ids=args.job_ids, print_array_jobs=args.print_array_jobs, print_dependencies=args.print_dependencies, long=args.verbose > 1)
jm.list(job_ids=args.job_ids, print_array_jobs=args.print_array_jobs, print_dependencies=args.print_dependencies, status=args.status, long=args.verbose > 1)
def communicate(args):
......@@ -253,6 +253,7 @@ def main(command_line_options = None):
list_parser.add_argument('-j', '--job-ids', metavar='ID', nargs='*', type=int, help='List only the jobs with the given ids (by default, all jobs are listed)')
list_parser.add_argument('-a', '--print-array-jobs', action='store_true', help='Report only the jobs with the given array ids. If specified, a single job-id must be given as well.')
list_parser.add_argument('-x', '--print-dependencies', action='store_true', help='Print the dependencies of the jobs as well.')
list_parser.add_argument('-s', '--status', nargs='+', choices = Status, default = Status, help='Delete only jobs that have the given statuses; by default all jobs are deleted.')
list_parser.set_defaults(func=list)
# subcommand 'communicate'
......
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