From 55e8f91f07aa83b98791b9fb7080885d508b9c92 Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI Date: Tue, 17 Jul 2018 13:20:00 +0200 Subject: [PATCH] Accept a plus sign for specifying the job ranges --- doc/manual.rst | 12 +++++++----- gridtk/script/jman.py | 17 ++++++++++------- gridtk/tests/__init__.py | 6 +++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index c099dce..1bc8523 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -170,11 +170,13 @@ which will list only the jobs of the given job id(s): $ jman -vv list -a -j [job_id_1] [job_id_2] -Note that the ``-j`` option is in general relatively smart. You can use it to -select a range of job ids, e.g., ``-j 1-4 6-8``. In this case, please assert -that there are no spaces between job ids and the ``-`` separator. If any job -id is specified, which is not available in the database, it will simply be -ignored, including job ids that in the ranges. +Note that the ``-j`` option is in general relatively smart. You can use it to +select a range of job ids, e.g., ``-j 1-4 6-8 10+2`` is the same as +``-j 1 2 3 4 6 7 8 10 11 12``. In this case, please assert that there are no +spaces between job ids and the ``-`` and ``+`` separators. You cannot use both +``-`` and ``+`` in one part, i.e., something like ``-j 1-4+2`` will not work. +If any job id is specified, which is not available in the database, it will +simply be ignored, including job ids that are in the ranges. Since version 1.3.0, GridTK also saves timing information about jobs, i.e., time stamps when jobs were submitted, started and finished. You can use the diff --git a/gridtk/script/jman.py b/gridtk/script/jman.py index a3ff027..de0ae0a 100644 --- a/gridtk/script/jman.py +++ b/gridtk/script/jman.py @@ -80,15 +80,18 @@ def get_ids(jobs): return None indexes = [] for job in jobs: - # check if a range is specified - separator = job.find('-') - if separator == -1: + if '-' not in job and '+' not in job: index = int(job) indexes.append(index) - else: - first = int(job[0:separator]) - last = int(job[separator+1:]) - indexes.extend(range(first, last+1)) + # check if a range is specified + elif '-' in job and '+' not in job: + first, last = job.split('-', 1) + indexes.extend(range(int(first), int(last) + 1)) + # check if a plus sign is specified + elif '+' in job and '-' not in job: + first, add = job.split('+', 1) + first, add = int(first), int(add) + indexes.extend(range(first, first + add + 1)) return indexes diff --git a/gridtk/tests/__init__.py b/gridtk/tests/__init__.py index 3d00837..f89e100 100644 --- a/gridtk/tests/__init__.py +++ b/gridtk/tests/__init__.py @@ -117,7 +117,7 @@ class GridTKTest(unittest.TestCase): self.scheduler_job = subprocess.Popen([self.jman, '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '5', '--parallel', '2']) # sleep some time to assure that the scheduler was able to start the first job - time.sleep(4) + time.sleep(5) # ... and kill the scheduler self.scheduler_job.kill() self.scheduler_job = None @@ -153,7 +153,7 @@ class GridTKTest(unittest.TestCase): self.scheduler_job = subprocess.Popen([self.jman, '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '5', '--parallel', '2']) # sleep some time to assure that the scheduler was able to finish the first and start the second job - time.sleep(9) + time.sleep(10) # ... and kill the scheduler self.scheduler_job.kill() self.scheduler_job = None @@ -246,7 +246,7 @@ class GridTKTest(unittest.TestCase): jman.main([self.jman, '--database', self.database, 'report']) # clean-up - jman.main([self.jman, '--local', '--database', self.database, 'delete', '--job-ids', '1-5']) + jman.main([self.jman, '--local', '--database', self.database, 'delete', '--job-ids', '1+4']) # check that the database and the log files are gone self.assertEqual(len(os.listdir(self.temp_dir)), 0) -- 2.21.0