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: ...@@ -154,21 +154,21 @@ class JobManager:
self.unlock() 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.""" """Lists the jobs currently added to the database."""
# configuration for jobs # configuration for jobs
if print_dependencies: if print_dependencies:
fields = ("job-id", "queue", "status", "job-name", "dependencies", "submitted command line") fields = ("job-id", "queue", "status", "job-name", "dependencies", "submitted command line")
lengths = (20, 9, 14, 20, 30, 43) 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] dependency_length = lengths[4]
else: else:
fields = ("job-id", "queue", "status", "job-name", "submitted command line") fields = ("job-id", "queue", "status", "job-name", "submitted command line")
lengths = (20, 9, 14, 20, 43) 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 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]) delimiter = format.format(*['='*k for k in lengths])
array_delimiter = array_format.format(*["-"*k for k in lengths[:3]]) array_delimiter = array_format.format(*["-"*k for k in lengths[:3]])
header = [fields[k].center(lengths[k]) for k in range(len(lengths))] header = [fields[k].center(lengths[k]) for k in range(len(lengths))]
...@@ -180,12 +180,13 @@ class JobManager: ...@@ -180,12 +180,13 @@ class JobManager:
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)) if job.status in status:
if print_array_jobs and job.array: print(job.format(format, dependency_length, None if long else 43))
print(array_delimiter) if print_array_jobs and job.array:
for array_job in job.array: print(array_delimiter)
print(array_job.format(array_format)) for array_job in job.array:
print(array_delimiter) print(array_job.format(array_format))
print(array_delimiter)
self.unlock() self.unlock()
......
...@@ -121,7 +121,7 @@ def run_scheduler(args): ...@@ -121,7 +121,7 @@ def run_scheduler(args):
def list(args): def list(args):
"""Lists the jobs in the given database.""" """Lists the jobs in the given database."""
jm = setup(args) 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): def communicate(args):
...@@ -253,6 +253,7 @@ def main(command_line_options = None): ...@@ -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('-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('-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('-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) list_parser.set_defaults(func=list)
# subcommand 'communicate' # 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