Code Duplication    Length = 16-17 lines in 3 locations

mycluster/slurm.py 1 location

@@ 228-244 (lines=17) @@
225
        pass
226
227
228
def status():
229
    status_dict = {}
230
    with os.popen('squeue -u `whoami`') as f:
231
        try:
232
            f.readline()  # read header
233
            for line in f:
234
                new_line = re.sub(' +', ' ', line.strip())
235
                job_id = int(new_line.split(' ')[0])
236
                state = new_line.split(' ')[4]
237
                if state == 'R':
238
                    status_dict[job_id] = 'r'
239
                else:
240
                    status_dict[job_id] = state
241
        except Exception as e:
242
            print e
243
244
    return status_dict
245
246
247
def job_stats(job_id):

mycluster/lsf.py 1 location

@@ 217-233 (lines=17) @@
214
        pass
215
216
217
def status():
218
    status_dict = {}
219
    with os.popen('bjobs -w') as f:
220
        try:
221
            f.readline()  # read header
222
            for line in f:
223
                new_line = re.sub(' +', ' ', line.strip())
224
                job_id = int(new_line.split(' ')[0])
225
                state = new_line.split(' ')[2]
226
                if state == 'RUN':
227
                    status_dict[job_id] = 'r'
228
                else:
229
                    status_dict[job_id] = state
230
        except e:
231
            print e
232
233
    return status_dict
234
235
236
def job_stats(job_id):

mycluster/sge.py 1 location

@@ 345-360 (lines=16) @@
342
        pass
343
344
345
def status():
346
    status_dict = {}
347
    with os.popen('qstat') as f:
348
        try:
349
            f.readline()  # read header
350
            f.readline()  # read separator
351
            for line in f:
352
                new_line = re.sub(' +', ' ', line.strip())
353
                job_id = int(new_line.split(' ')[0])
354
                state = new_line.split(' ')[4]
355
356
                status_dict[job_id] = state
357
        except e:
358
            print e
359
360
    return status_dict
361
362
363
def job_stats(job_id):