<s> import sys <EOL> from memsql_loader . util . command import Command <EOL> from memsql_loader . util . pretty_printer import PrettyPrinter , TableFormat <EOL> from memsql_loader . util import log <EOL> from memsql_loader . api . tasks import Tasks as TasksApi <EOL> from memsql_loader . api import shared , exceptions <EOL> from memsql_loader . loader_db . jobs import Jobs <EOL> class Tasks ( Command ) : <EOL> @ staticmethod <EOL> def configure ( parser , subparsers ) : <EOL> subparser = subparsers . add_parser ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> subparser . set_defaults ( command = Tasks ) <EOL> subparser . add_argument ( '<STR_LIT>' , type = str , nargs = '<STR_LIT:?>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> choices = shared . TaskState . elements . keys ( ) , <EOL> type = lambda s : s . upper ( ) , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> choices = shared . SortDirection . elements . keys ( ) , <EOL> type = lambda s : s . upper ( ) , <EOL> default = shared . SortDirection . ASC , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> choices = TasksApi . SORTABLE_COLUMNS , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> subparser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = False , <EOL> help = '<STR_LIT>' ) <EOL> def run ( self ) : <EOL> self . logger = log . get_logger ( '<STR_LIT>' ) <EOL> self . tasks_api = TasksApi ( ) <EOL> if not self . options . job_id and not self . options . last_job : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if self . options . last_job : <EOL> jobs = Jobs ( ) <EOL> job_list = jobs . all ( ) <EOL> if not job_list : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> self . options . job_id = job_list [ - <NUM_LIT:1> ] . id <EOL> try : <EOL> result = self . tasks_api . query ( { k : v for k , v in { <EOL> '<STR_LIT>' : self . options . job_id , <EOL> '<STR_LIT:state>' : self . options . state , <EOL> '<STR_LIT>' : self . options . order , <EOL> '<STR_LIT>' : self . options . order_by , <EOL> '<STR_LIT>' : self . options . page_size , <EOL> '<STR_LIT>' : self . options . page , <EOL> } . iteritems ( ) if v } ) <EOL> except exceptions . ApiException as e : <EOL> print e . message <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if result : <EOL> tablefmt = TableFormat . JSON if self . options . json else TableFormat . TABLE <EOL> print PrettyPrinter ( result , columns = TasksApi . SORTABLE_COLUMNS , format = tablefmt ) . format ( ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) </s>
