<s> import re <EOL> import os <EOL> from . . anf_util import * <EOL> class GenerateCompletionListBase ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , command ) : <EOL> super ( GenerateCompletionListBase , self ) . __init__ ( ) <EOL> self . top_level_split_char = "<STR_LIT::>" <EOL> self . command = command <EOL> self . aliases = command . aliases <EOL> self . settings = command . settings <EOL> def is_home ( self , path ) : <EOL> return re . match ( r"<STR_LIT>" , path ) <EOL> def is_alias ( self , path ) : <EOL> return self . top_level_split_char in path <EOL> def generate_completion_list ( self , path_in ) : <EOL> alias_list = [ ] <EOL> dir_list = [ ] <EOL> file_list = [ ] <EOL> if self . is_alias ( path_in ) or self . is_home ( path_in ) : <EOL> pass <EOL> else : <EOL> directory , filename = os . path . split ( path_in ) <EOL> if len ( directory ) == <NUM_LIT:0> : <EOL> alias_list += self . generate_alias_auto_complete ( filename ) <EOL> alias_list += self . generate_project_auto_complete ( filename ) <EOL> base , path = self . command . split_path ( path_in ) <EOL> full_path = generate_creation_path ( self . settings , base , path ) <EOL> directory , filename = os . path . split ( full_path ) <EOL> if os . path . isdir ( directory ) : <EOL> for d in os . listdir ( directory ) : <EOL> full_path = os . path . join ( directory , d ) <EOL> if os . path . isdir ( full_path ) : <EOL> is_file = False <EOL> elif self . settings . get ( SHOW_FILES_SETTING ) : <EOL> is_file = True <EOL> else : <EOL> continue <EOL> if self . compare_entries ( d , filename ) : <EOL> if is_file : <EOL> file_list . append ( d ) <EOL> else : <EOL> dir_list . append ( d ) <EOL> completion_list = alias_list + dir_list + file_list <EOL> return sorted ( completion_list ) , alias_list , dir_list , file_list <EOL> def generate_project_auto_complete ( self , base ) : <EOL> folder_data = get_project_folder_data ( <EOL> self . settings . get ( USE_FOLDER_NAME_SETTING ) ) <EOL> if len ( folder_data ) > <NUM_LIT:1> : <EOL> folders = [ x [ <NUM_LIT:0> ] for x in folder_data ] <EOL> return self . generate_auto_complete ( base , folders ) <EOL> return [ ] <EOL> def generate_alias_auto_complete ( self , base ) : <EOL> return self . generate_auto_complete ( base , self . aliases ) <EOL> def generate_auto_complete ( self , base , iterable_var ) : <EOL> sugg = [ ] <EOL> for entry in iterable_var : <EOL> compare_entry = entry <EOL> compare_base = base <EOL> if self . settings . get ( IGNORE_CASE_SETTING ) : <EOL> compare_entry = compare_entry . lower ( ) <EOL> compare_base = compare_base . lower ( ) <EOL> if self . compare_entries ( compare_entry , compare_base ) : <EOL> if entry not in sugg : <EOL> sugg . append ( entry ) <EOL> return sugg <EOL> def compare_entries ( self , compare_entry , compare_base ) : <EOL> if self . settings . get ( IGNORE_CASE_SETTING ) : <EOL> compare_entry = compare_entry . lower ( ) <EOL> compare_base = compare_base . lower ( ) <EOL> return compare_entry . startswith ( compare_base ) </s>
