@@ -372,31 +372,116 @@ def check_all_jobs(self, phase=None, regex=None, sortby=None):
372372 if frame .f_code .co_name in do_not_print_job_dict :
373373 return checkalljobs
374374 else :
375- if not phase :
376- if not regex :
377- for i in self .job_dict .keys ():
378- print ("{} : {}" .format (i ,self .job_dict [i ]))
379- if regex :
380- for i in self .job_dict .keys ():
381- if i in self .table_dict .keys ():
382- if self .table_dict [i ] in matching_tables :
383- print ("{} : {} (Table: {})" .format (i ,
384- self .job_dict [i ],
385- self .table_dict [i ]))
386- elif phase :
387- phase = [phase [i ].upper () for i in range (len (phase ))]
388- if not regex :
389- for i in self .job_dict .keys ():
390- if self .job_dict [i ] in phase :
391- print ("{} : {}" .format (i ,self .job_dict [i ]))
392- if regex :
393- for i in self .job_dict .keys ():
394- if self .job_dict [i ] in phase :
395- if i in self .table_dict .keys ():
396- if self .table_dict [i ] in matching_tables :
397- print ("{} : {} (Table: {})" .format (i ,
398- self .job_dict [i ],
399- self .table_dict [i ]))
375+ if not phase and not regex :
376+ if not sortby :
377+ t = Table ()
378+ t ['JobID' ] = self .job_dict .keys ()
379+ t ['Phase' ] = self .job_dict .values ()
380+ t .pprint ()
381+ else :
382+ if sortby .upper () == 'TABLENAME' :
383+ t = Table ()
384+ t ['Tablename' ] = matching_tables
385+ t ['Starttime' ] = matching_starttimes
386+ t ['JobID' ] = matching_jobids
387+ t ['Phase' ] = matching_phases
388+ t .pprint ()
389+ if sortby .upper () == 'STARTTIME' :
390+ t = Table ()
391+ t ['Starttime' ] = matching_starttimes
392+ t ['Tablename' ] = matching_tables
393+ t ['JobID' ] = matching_jobids
394+ t ['Phase' ] = matching_phases
395+ t .pprint ()
396+
397+ elif not phase and regex :
398+ t = Table ()
399+ if sortby :
400+ if sortby .upper () == 'STARTTIME' :
401+ t ['Starttime' ] = matching_starttimes
402+ t ['Tablename' ] = matching_tables
403+ if sortby .upper () == 'TABLENAME' :
404+ t ['Tablename' ] = matching_tables
405+ t ['Starttime' ] = matching_starttimes
406+ if not sortby :
407+ t ['Tablename' ] = matching_tables
408+ t ['Starttime' ] = matching_starttimes
409+ t ['JobID' ] = matching_jobids
410+ t ['Phase' ] = matching_phases
411+ t .pprint ()
412+
413+
414+ if phase and not regex :
415+ if len (phase ) == 1 and "COMPLETED" in phase :
416+ if not sortby :
417+ matching_jobids = [key
418+ for key in self .job_dict .keys ()
419+ if self .job_dict [key ] in phase ]
420+ matching = zip (* [[(self .table_dict [i ],self .job_dict [i ],self .starttime_dict [i ])
421+ for i in self .table_dict .keys ()
422+ if i == miter ][0 ]
423+ for miter in matching_jobids ])
424+ matching_tables ,matching_phases ,matching_starttimes = (matching [0 ],matching [1 ],matching [2 ])
425+ t = Table ()
426+ t ['JobID' ] = matching_jobids
427+ t ['Phase' ] = matching_phases
428+ t ['Tablename' ] = matching_tables
429+ t ['Starttime' ] = matching_starttimes
430+ t .pprint ()
431+ if sortby :
432+ if sortby .upper () == 'TABLENAME' :
433+ t = Table ()
434+ t ['Tablename' ] = matching_tables
435+ t ['Starttime' ] = matching_starttimes
436+ t ['JobID' ] = matching_jobids
437+ t ['Phase' ] = matching_phases
438+ t .pprint ()
439+ if sortby .upper () == 'STARTTIME' :
440+ t = Table ()
441+ t ['Starttime' ] = matching_starttimes
442+ t ['Tablename' ] = matching_tables
443+ t ['JobID' ] = matching_jobids
444+ t ['Phase' ] = matching_phases
445+ t .pprint ()
446+ else :
447+ if sortby :
448+ print ('Sorting can only be applied to jobs with phase `COMPLETED`.' )
449+ if not sortby :
450+ matching_jobids = [key
451+ for key in self .job_dict .keys ()
452+ if self .job_dict [key ] in phase ]
453+ matching_phases = [self .job_dict [key ]
454+ for key in self .job_dict .keys ()
455+ if self .job_dict [key ] in phase ]
456+ t = Table ()
457+ t ['JobID' ] = matching_jobids
458+ t ['Phase' ] = matching_phases
459+ t .pprint ()
460+
461+ if phase and regex :
462+ if not sortby :
463+ t = Table ()
464+ t ['Tablename' ] = matching_tables
465+ t ['Starttime' ] = matching_starttimes
466+ t ['JobID' ] = matching_jobids
467+ t ['Phase' ] = matching_phases
468+ t .pprint ()
469+ else :
470+ if sortby .upper () == 'TABLENAME' :
471+ t = Table ()
472+ t ['Tablename' ] = matching_tables
473+ t ['Starttime' ] = matching_starttimes
474+ t ['JobID' ] = matching_jobids
475+ t ['Phase' ] = matching_phases
476+ t .pprint ()
477+ if sortby .upper () == 'STARTTIME' :
478+ t = Table ()
479+ t ['Starttime' ] = matching_starttimes
480+ t ['Tablename' ] = matching_tables
481+ t ['JobID' ] = matching_jobids
482+ t ['Phase' ] = matching_phases
483+ t .pprint ()
484+
400485 return checkalljobs
401486
402487 def completed_job_info (self ,jobid = None ,output = False ):
@@ -418,16 +503,22 @@ def completed_job_info(self,jobid=None,output=False):
418503 self .check_all_jobs ()
419504
420505 if jobid is None :
421- completed_jobids = [key
422- for key in self .job_dict .keys ()
423- if self .job_dict [key ] == 'COMPLETED' ]
424- response_list = [self .session .get (CosmoSim .QUERY_URL + "/{}" .format (completed_jobids [i ]),
425- auth = (self .username ,self .password ))
426- for i in range (len (completed_jobids ))]
506+ completed_jobids = [key for key in self .job_dict .keys () if self .job_dict [key ] == 'COMPLETED' ]
507+ response_list = [self ._request ('GET' ,
508+ CosmoSim .QUERY_URL + "/{}" .format (completed_jobids [i ]),
509+ auth = (self .username , self .password ),cache = False )
510+ for i in range (len (completed_jobids ))]
511+ self .response_dict_current = {}
512+ for i ,vals in enumerate (completed_jobids ):
513+ self .response_dict_current [vals ] = self ._generate_response_dict (response_list [i ])
427514 else :
428515 if self .job_dict [jobid ] == 'COMPLETED' :
429- response_list = [self .session .get (CosmoSim .QUERY_URL + "/{}" .format (jobid ),
430- auth = (self .username ,self .password ))]
516+ response_list = [self ._request ('GET' ,
517+ CosmoSim .QUERY_URL + "/{}" .format (jobid ),
518+ auth = (self .username ,
519+ self .password ),cache = False )]
520+ self .response_dict_current = {}
521+ self .response_dict_current [jobid ] = self ._generate_response_dict (response_list [0 ])
431522 else :
432523 logging .warning ("JobID must refer to a query with a phase of 'COMPLETED'." )
433524 return
0 commit comments