<s> from . . parser import load_task_graph , get_task_kwargs_list <EOL> from . . exceptions import ConfigurationNotFound , YamlError <EOL> class BaseCommand ( object ) : <EOL> help_text = '<STR_LIT>' <EOL> def __init__ ( self , subcommand_creator ) : <EOL> self . config = None <EOL> self . subcommand_creator = subcommand_creator <EOL> self . option_parser = self . subcommand_creator . add_parser ( <EOL> self . get_command_name ( ) , <EOL> help = self . help_text , <EOL> description = self . help_text , <EOL> ) <EOL> self . add_command_line_options ( ) <EOL> def get_command_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __module__ . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> def add_command_line_options ( self ) : <EOL> self . option_parser . add_argument ( <EOL> '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> type = str , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> def execute ( self , config = None ) : <EOL> self . config = config <EOL> self . task_graph = load_task_graph ( config = config ) <EOL> @ property <EOL> def task_kwargs_list ( self ) : <EOL> try : <EOL> return get_task_kwargs_list ( config = self . config ) <EOL> except ( ConfigurationNotFound , YamlError ) : <EOL> return [ ] <EOL> @ property <EOL> def available_task_ids ( self ) : <EOL> task_ids = [ ] <EOL> for task_kwargs in self . task_kwargs_list : <EOL> task_id = task_kwargs . get ( '<STR_LIT>' ) or task_kwargs . get ( '<STR_LIT>' ) <EOL> task_ids . append ( task_id ) <EOL> task_ids . sort ( ) <EOL> return task_ids <EOL> def task_ids_completer ( self , prefix , parsed_args , ** kwargs ) : <EOL> self . config = parsed_args . config <EOL> return [ task_id for task_id in self . available_task_ids <EOL> if task_id . startswith ( prefix ) ] <EOL> def add_task_id_argument ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> option = self . option_parser . add_argument ( * args , ** kwargs ) <EOL> option . completer = self . task_ids_completer <EOL> return option <EOL> def add_task_id_option ( self , help_text ) : <EOL> """<STR_LIT>""" <EOL> help_text += "<STR_LIT>" <EOL> self . add_task_id_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = str , <EOL> choices = self . available_task_ids , <EOL> nargs = '<STR_LIT:?>' , <EOL> help = help_text , <EOL> ) </s>
