(data_files=None, page=1, limit=20, metadata_offset=40)
return profile
Ask the user to choose a profile.
    
    Parameters:
        page (int): Page to start on.
        limit (int): How many results to show on each page.
        metadata_offset (int): Minimum number of spaces before showing the metadata related to sorting.

    Returns:
        Selected profile as text.
Ask the user to choose a profile.
    
    Parameters:
        page (int): Page to start on.
        limit (int): How many results to show on each page.
        metadata_offset (int): Minimum number of spaces before showing the metadata related to sorting.
Ask the user to choose a profile . Parameters : page ( int ) : Page to start on . limit ( int ) : How many results to show on each page . metadata_offset ( int ) : Minimum number of spaces before showing the metadata related to sorting .
def select_profile_from_list(data_files=None, page=1, limit=20, metadata_offset=40):
    """Ask the user to choose a profile.
    
    Parameters:
        page (int): Page to start on.
        limit (int): How many results to show on each page.
        metadata_offset (int): Minimum number of spaces before showing the metadata related to sorting.

    Returns:
        Selected profile as text.
    """

    #Read list of files in data folder
    if data_files is None:
        data_files = get_data_files()
        
    profile_index_max = len(data_files)
    total_pages = round_up(profile_index_max / limit)

    #Build and sort list of all known program names
    program_names = {format_name(DEFAULT_NAME): DEFAULT_NAME}
    for program_name in AppList().names:
        program_names[format_name(program_name)] = program_name

    sort_options = ['Track Length', 'Session Count', 'Creation Time', 'Last Modified', 'File Version', 'File Size']
    sort_options = sorted(SORT_OPTIONS.keys())
    sort_value = sort_options[3]
    reverse = False
    loop = 0
    while True:
        loop += 1
        offset = (page - 1) * limit
        Message(LANGUAGE.strings['GenerationInput']['SelectProfile'])
        Message(LANGUAGE.strings['GenerationInput']['PageSort'].format_custom(
                SORT_TYPE=sort_value.lower(), ORDER='ascending' if reverse else 'descending'))
        _sort_options = list_to_str(['{} ({})'.format(value, i+1) for i, value in enumerate(sort_options)])
        Message(LANGUAGE.strings['GenerationInput']['PageSortSelect'].format_custom(
                SORT=LANGUAGE.strings['Words']['Sort'], SORT_OPTIONS=_sort_options))
        Message()
                                  
        sorted_list = _sort_data_list(data_files, sort_value, not reverse)
        option_name, _, option_type, option_func = SORT_OPTIONS[sort_value]
        for i, profile_name in enumerate(sorted_list[offset:offset+limit]):
            output = '{}: '.format(offset+i+1)

            #Get the full name of the profile
            try:
                output += program_names[profile_name]
            except KeyError:
                output += profile_name

            #Add information relating to current sorting selection
            try:
                value = option_type(data_files[profile_name][option_name])
            except KeyError:
                pass
            else:
                if option_func is not None:
                    if callable(option_func):
                        value = option_func(value)
                    else:
                        value = option_func[0](value, *option_func[1], **option_func[2])
                output_len = len(output)
                output += ' ' * max(1 if output_len < metadata_offset else 3, metadata_offset - output_len) + '{}: {}'.format(sort_value, value)
            Message(output)
        Message(LANGUAGE.strings['GenerationInput']['PageNumber'].format_custom(CURRENT_PAGE=page, 
                                                                       TOTAL_PAGES=total_pages, 
                                                                       PAGE=LANGUAGE.strings['Words']['Page']))
        Message()

        #Ask the user for input, or automatically choose input for testing
        user_input = input(LANGUAGE.strings['Input']['UserChoice'] + ' ')

        try:
            profile_id = int(user_input)

        #Input is not an ID
        except ValueError:

            #Onput is requesting sorting
            if user_input.lower().startswith('{} '.format(LANGUAGE.strings['Words']['Sort'])):
                option = None
                try:
                    sort_id = int(user_input[len(LANGUAGE.strings['Words']['Sort']):]) - 1
                    if not 0 <= sort_id < len(sort_options):
                        raise ValueError
                
                #Attempt to read if the option was manually typed out
                except ValueError:
                    lc_option = user_input[len(LANGUAGE.strings['Words']['Sort'])+1:].lower()
                    for uc_option in sort_options:
                        if lc_option in (uc_option.lower(), uc_option.lower().replace(' ', '')):
                            option = uc_option
                            break
                    else:
                        try:
                            Message(LANGUAGE.strings['GenerationInput']['PageSortInvalidID'].format_custom(
                                    CURRENT_SORT=sort_value, NEW_SORT=sort_id+1, SORT_MIN=1, SORT_MAX=len(sort_options)))
                        except UnboundLocalError:
                            Message(LANGUAGE.strings['GenerationInput']['PageSortInvalidType'].format_custom(
                                    CURRENT_SORT=sort_value, NEW_SORT=lc_option, SORT_OPTIONS=_sort_options))

                #If sort by itself was typed, just reverse
                except IndexError:
                    reverse = not reverse

                #Get the ID
                else:
                    option = sort_options[sort_id]

                #Either reverse or change the sorting option
                if option is not None:
                    if option == sort_value:
                        reverse = not reverse
                        Message(LANGUAGE.strings['GenerationInput']['PageSortReverse'].format_custom(SORT_TYPE=sort_value))
                    else:
                        sort_value = option
                        Message(LANGUAGE.strings['GenerationInput']['PageSortNew'].format_custom(SORT_TYPE=sort_value))

            #Switch pages
            elif user_input.lower().startswith('{} '.format(LANGUAGE.strings['Words']['Page'])):
                _page = user_input[len(LANGUAGE.strings['Words']['Page'])+1:]
                try:
                    page = int(_page)
                    if page < 1:
                        page = 1
                        raise ValueError
                    elif page > total_pages:
                        page = total_pages
                        raise ValueError
                
                except ValueError:
                    Message(LANGUAGE.strings['GenerationInput']['PageNumberInvalid'].format_custom(
                            CURRENT_PAGE=page, NEW_PAGE=_page, PAGE_MIN=1, PAGE_MAX=total_pages))

            #Input is directly typing profile name
            else:
                if get_metadata(user_input) is None:
                    Message(LANGUAGE.strings['GenerationInput']['ProfileEmpty'].format_custom(PROFILE=user_input))
                else:
                    profile = user_input
                    break
        
        #Get the profile matching the ID
        else:
            profile_index = profile_id
            if 1 <= profile_index <= profile_index_max:
                try:
                    profile = program_names[sorted_list[profile_index-1]]
                except KeyError:
                    profile = sorted_list[profile_index-1]
                break
            else:
                Message(LANGUAGE.strings['GenerationInput']['ProfileIndexError'].format_custom(
                        NEW_INDEX=profile_index, INDEX_MIN=1, INDEX_MAX=profile_index_max))
        Message()

    return profile
def select_profile_from_list ( data_files = None , page = 1 , limit = 20 , metadata_offset = 40 ) : #Read list of files in data folder if data_files is None : data_files = get_data_files ( ) profile_index_max = len ( data_files ) total_pages = round_up ( profile_index_max / limit ) #Build and sort list of all known program names program_names = { format_name ( DEFAULT_NAME ) : DEFAULT_NAME } for program_name in AppList ( ) . names : program_names [ format_name ( program_name ) ] = program_name sort_options = [ 'Track Length' , 'Session Count' , 'Creation Time' , 'Last Modified' , 'File Version' , 'File Size' ] sort_options = sorted ( SORT_OPTIONS . keys ( ) ) sort_value = sort_options [ 3 ] reverse = False loop = 0 while True : loop += 1 offset = ( page - 1 ) * limit Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'SelectProfile' ] ) Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSort' ] . format_custom ( SORT_TYPE = sort_value . lower ( ) , ORDER = 'ascending' if reverse else 'descending' ) ) _sort_options = list_to_str ( [ '{} ({})' . format ( value , i + 1 ) for i , value in enumerate ( sort_options ) ] ) Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSortSelect' ] . format_custom ( SORT = LANGUAGE . strings [ 'Words' ] [ 'Sort' ] , SORT_OPTIONS = _sort_options ) ) Message ( ) sorted_list = _sort_data_list ( data_files , sort_value , not reverse ) option_name , _ , option_type , option_func = SORT_OPTIONS [ sort_value ] for i , profile_name in enumerate ( sorted_list [ offset : offset + limit ] ) : output = '{}: ' . format ( offset + i + 1 ) #Get the full name of the profile try : output += program_names [ profile_name ] except KeyError : output += profile_name #Add information relating to current sorting selection try : value = option_type ( data_files [ profile_name ] [ option_name ] ) except KeyError : pass else : if option_func is not None : if callable ( option_func ) : value = option_func ( value ) else : value = option_func [ 0 ] ( value , * option_func [ 1 ] , * * option_func [ 2 ] ) output_len = len ( output ) output += ' ' * max ( 1 if output_len < metadata_offset else 3 , metadata_offset - output_len ) + '{}: {}' . format ( sort_value , value ) Message ( output ) Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageNumber' ] . format_custom ( CURRENT_PAGE = page , TOTAL_PAGES = total_pages , PAGE = LANGUAGE . strings [ 'Words' ] [ 'Page' ] ) ) Message ( ) #Ask the user for input, or automatically choose input for testing user_input = input ( LANGUAGE . strings [ 'Input' ] [ 'UserChoice' ] + ' ' ) try : profile_id = int ( user_input ) #Input is not an ID except ValueError : #Onput is requesting sorting if user_input . lower ( ) . startswith ( '{} ' . format ( LANGUAGE . strings [ 'Words' ] [ 'Sort' ] ) ) : option = None try : sort_id = int ( user_input [ len ( LANGUAGE . strings [ 'Words' ] [ 'Sort' ] ) : ] ) - 1 if not 0 <= sort_id < len ( sort_options ) : raise ValueError #Attempt to read if the option was manually typed out except ValueError : lc_option = user_input [ len ( LANGUAGE . strings [ 'Words' ] [ 'Sort' ] ) + 1 : ] . lower ( ) for uc_option in sort_options : if lc_option in ( uc_option . lower ( ) , uc_option . lower ( ) . replace ( ' ' , '' ) ) : option = uc_option break else : try : Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSortInvalidID' ] . format_custom ( CURRENT_SORT = sort_value , NEW_SORT = sort_id + 1 , SORT_MIN = 1 , SORT_MAX = len ( sort_options ) ) ) except UnboundLocalError : Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSortInvalidType' ] . format_custom ( CURRENT_SORT = sort_value , NEW_SORT = lc_option , SORT_OPTIONS = _sort_options ) ) #If sort by itself was typed, just reverse except IndexError : reverse = not reverse #Get the ID else : option = sort_options [ sort_id ] #Either reverse or change the sorting option if option is not None : if option == sort_value : reverse = not reverse Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSortReverse' ] . format_custom ( SORT_TYPE = sort_value ) ) else : sort_value = option Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageSortNew' ] . format_custom ( SORT_TYPE = sort_value ) ) #Switch pages elif user_input . lower ( ) . startswith ( '{} ' . format ( LANGUAGE . strings [ 'Words' ] [ 'Page' ] ) ) : _page = user_input [ len ( LANGUAGE . strings [ 'Words' ] [ 'Page' ] ) + 1 : ] try : page = int ( _page ) if page < 1 : page = 1 raise ValueError elif page > total_pages : page = total_pages raise ValueError except ValueError : Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'PageNumberInvalid' ] . format_custom ( CURRENT_PAGE = page , NEW_PAGE = _page , PAGE_MIN = 1 , PAGE_MAX = total_pages ) ) #Input is directly typing profile name else : if get_metadata ( user_input ) is None : Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'ProfileEmpty' ] . format_custom ( PROFILE = user_input ) ) else : profile = user_input break #Get the profile matching the ID else : profile_index = profile_id if 1 <= profile_index <= profile_index_max : try : profile = program_names [ sorted_list [ profile_index - 1 ] ] except KeyError : profile = sorted_list [ profile_index - 1 ] break else : Message ( LANGUAGE . strings [ 'GenerationInput' ] [ 'ProfileIndexError' ] . format_custom ( NEW_INDEX = profile_index , INDEX_MIN = 1 , INDEX_MAX = profile_index_max ) ) Message ( ) return profile